Exemplo n.º 1
0
    void SetUp()
    {
        MojDbCoreTest::SetUp();

        // add kind
        MojObject obj;
        MojAssertNoErr( obj.fromJson(MojTestKind1Str1) );
        MojAssertNoErr( db.putKind(obj) );
    }
Exemplo n.º 2
0
    void deleteMark(MojUInt32 expect = 50ul, int mark = -1, MojDbReqRef req = MojDbReq())
    {
        MojDbQuery query;
        MojAssertNoErr( query.from(_T("Test:1")) );
        MojAssertNoErr( query.where(_T("bar"), MojDbQuery::OpEq, mark) );

        MojUInt32 count = 0xbaddcafe;
        MojAssertNoErr( db.del(query, count, MojDb::FlagNone, req) );
        EXPECT_EQ( expect, count );
    }
Exemplo n.º 3
0
TEST(NumberTest, parse_with_rounding)
{
    MojNumber::Parser parser;

    MojAssertNoErr( MojNumber::Lexer::parse(parser, "0.123456789") );
    EXPECT_TRUE( parser.haveFraction() );

    MojDecimal d;
    MojAssertNoErr( parser.toDecimal(d) );
    EXPECT_EQ( MojDecimal(0, 123457), d );
}
Exemplo n.º 4
0
/**
 * @test Similar to parse_unbalanced_small but with big number.
 *       I.e. 123000000000000000000e-20 = 1.23
 */
TEST(NumberTest, parse_unbalanced_big)
{
    MojNumber::Parser parser;

    MojAssertNoErr( MojNumber::Lexer::parse(parser, "123000000000000000000e-20") );
    EXPECT_TRUE( parser.haveFraction() );

    MojDecimal d;
    MojAssertNoErr( parser.toDecimal(d) );
    EXPECT_EQ( MojDecimal(1,230000), d );
}
Exemplo n.º 5
0
/**
 * Basic test for parser
 */
TEST(NumberTest, parser)
{
    MojNumber::Parser parser;

    MojAssertNoErr( MojNumber::Lexer::parse(parser, "-3.14e0") );
    EXPECT_TRUE( parser.haveFraction() );

    MojDecimal d;
    MojAssertNoErr( parser.toDecimal(d) );
    EXPECT_EQ( MojDecimal(-3, 140000), d );
}
Exemplo n.º 6
0
    void buildSample()
    {
        for (int i = 0; i < 100; ++i) {
            MojObject obj;
            MojAssertNoErr( obj.putString(MojDb::KindKey, _T("Test:1")) );
            MojAssertNoErr( obj.put(_T("foo"), (i + 25) % 100) );
            MojAssertNoErr( obj.put(_T("bar"), i % 3) );
            MojExpectNoErr( db.put(obj) ) << "Failed to put record #" << i;
        }

        // db: x0 = (25, 0), (26, 1), (27, 2), (28, 0) .. x74 = (99,2), x75 = (0,0) .. x99 = (24,0)
    }
Exemplo n.º 7
0
    void checkMarkWithUpdate(MojUInt32 expect = 50ul, int mark = -1, MojDbReqRef req = MojDbReq())
    {
        MojDbQuery query;
        MojAssertNoErr( query.from(_T("Test:1")) );
        MojAssertNoErr( query.where(_T("bar"), MojDbQuery::OpEq, mark) );

        MojObject update;

        MojUInt32 count = (MojUInt32)(-1);
        MojAssertNoErr( db.merge(query, MojObject(), count, MojDb::FlagNone, req) );
        EXPECT_EQ( expect, count );
    }
Exemplo n.º 8
0
    void checkCount()
    {
        MojDbQuery query;
        MojAssertNoErr( query.from(_T("LoadTest:1")) );

        MojDbCursor cursor;
        MojAssertNoErr( db.find(query, cursor) );

        MojUInt32 count = 0;
        MojAssertNoErr( cursor.count(count) );

        EXPECT_EQ( 10LL, count );
    }
Exemplo n.º 9
0
    void mark3(MojDbReqRef req = MojDbReq())
    {
        MojDbQuery query;
        MojAssertNoErr( query.from(_T("Test:1")) );
        MojAssertNoErr( query.where(_T("bar"), MojDbQuery::OpLessThan, 2) );

        MojObject update;
        MojAssertNoErr( update.put(_T("bar"), -3) );

        MojUInt32 count = 0xbaddcafe;
        MojAssertNoErr( db.merge(query, update, count, MojDb::FlagNone, req) );
        EXPECT_EQ( 33ul, count );
    }
Exemplo n.º 10
0
    void mark1(MojDbReqRef req = MojDbReq())
    {
        // mark half with bar=-1
        MojDbQuery query;
        MojAssertNoErr( query.from(_T("Test:1")) );
        MojAssertNoErr( query.where(_T("foo"), MojDbQuery::OpLessThan, 50) );

        MojObject update;
        MojAssertNoErr( update.put(_T("bar"), -1) );
        MojUInt32 count = 0xbaddcafe; // differentiat 0 from non-filled count
        MojAssertNoErr( db.merge(query, update, count) );
        EXPECT_EQ( 50ul, count );

        // db: x0 = (25, -1) .. x24 = (49,-1), x25 = (50,1)i .. x74 = (99,2), x75 = (0,-1) .. x99 = (24, -1)
    }
Exemplo n.º 11
0
    void mark2(MojDbReqRef req = MojDbReq())
    {
        // re-mark half with bar=-1 to bar=-2
        MojDbQuery query;
        MojAssertNoErr( query.from(_T("Test:1")) );
        MojAssertNoErr( query.where(_T("bar"), MojDbQuery::OpEq, -1) );

        MojObject update;
        MojAssertNoErr( update.put(_T("bar"), -2) );

        MojUInt32 count = 0xbaddcafe;
        MojAssertNoErr( db.merge(query, update, count, MojDb::FlagNone, req) );
        EXPECT_EQ( 50ul, count );

        // db: x0 = (25, -1) .. x24 = (49,-1), x25 = (50,1)i .. x74 = (99,2), x75 = (0,-1) .. x99 = (24, -1)
    }
Exemplo n.º 12
0
    void SetUp()
    {
        const ::testing::TestInfo* const test_info =
          ::testing::UnitTest::GetInstance()->current_test_info();

        path = std::string(tempFolder) + '/'
             + test_info->test_case_name() + '-' + test_info->name();

        // open
        MojAssertNoErr( db.open(path.c_str()) );

        // add type
        MojObject obj;
        MojAssertNoErr( obj.fromJson(MojKindStr) );
        MojAssertNoErr( db.putKind(obj) );
    }
Exemplo n.º 13
0
TEST_F(QuotaTest, enforce)
{
    MojObject obj;

    // put quota
    MojAssertNoErr( obj.fromJson(_T("{\"owner\":\"com.foo.bar\",\"size\":1000}")) );
    MojAssertNoErr( db.putQuotas(&obj, &obj + 1) );

    // make kind2 inherit from kind1
    MojAssertNoErr( obj.fromJson(MojTestKind2Str3) );
    MojExpectNoErr( db.putKind(obj) );

    //// end of prerequisites form prev tests

    // set quota size to current usage
    MojInt64 quotaUsage1 = 0;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1) );
    MojAssertNoErr( obj.putString(_T("owner"), _T("com.foo.bar")) );
    MojAssertNoErr( obj.putInt(_T("size"), quotaUsage1) );
    MojExpectNoErr( db.putQuotas(&obj, &obj + 1) );

    MojAssertNoErr( obj.fromJson(MojTestKind1Objects[3]) );
    EXPECT_EQ( MojErrDbQuotaExceeded, db.put(obj) );

    // Try to delete the kind
    MojString kindStr;
    MojAssertNoErr( kindStr.assign(_T("Test:1")) );
    bool found = false;
    EXPECT_EQ( MojErrDbKindHasSubKinds, db.delKind(kindStr, found) )
        << "The delete should be failure, because it contain sub kind \"Test2:1\"";
    EXPECT_FALSE( found );
}
Exemplo n.º 14
0
/**
 * @test Decimal overflow situation due to big exponent
 */
TEST(NumberTest, parse_decimal_overflow_by_exponent)
{
    MojNumber::Parser parser;

    MojAssertNoErr( MojNumber::Lexer::parse(parser, "1.23e20") );

    MojDecimal d;
    EXPECT_EQ( MojErrValueOutOfRange, parser.toDecimal(d) );
}
Exemplo n.º 15
0
/**
 * @test number very close to boundary of maximum MojDecimal but still
 *       parsable.
 *       I.e. ((2^63 - 1) / 10^6) / 10^12 = 9.223372036854775
 *       But double have issue to represent that number exactly, so we found
 *       some other that is close enough.
 */
TEST(NumberTest, parse_decimal_exponent_bound)
{
    MojNumber::Parser parser;
    MojDecimal d;

    MojAssertNoErr( MojNumber::Lexer::parse(parser, "9.22337203685477376e12") );
    MojExpectNoErr( parser.toDecimal(d) );
    EXPECT_EQ( MojDecimal(9.223372036854774376e12), d );
}
Exemplo n.º 16
0
/**
 * @test Decimal overflow situation due to big mantissa
 */
TEST(NumberTest, parse_decimal_overflow_by_mantissa)
{
    MojNumber::Parser parser;

    MojAssertNoErr( MojNumber::Lexer::parse(parser, "123000000000000000000") );

    // note that in this case we should get error during rendering
    MojDecimal d;
    EXPECT_EQ( MojErrValueOutOfRange, parser.toDecimal(d) );
}
Exemplo n.º 17
0
TEST(NumberTest, small_small_number)
{
    MojNumber::Parser parser;

    MojAssertNoErr( MojNumber::Lexer::parse(parser, "3.1844206213736e-308") );
    EXPECT_TRUE( parser.haveFraction() );

    MojDecimal d;
    EXPECT_EQ( MojErrNone, parser.toDecimal(d) );
    EXPECT_EQ( MojDecimal(0,0), d );    // should be zero
}
Exemplo n.º 18
0
/**
 * @test Boundary case for decimal overflow situation when exponent is still in
 *       allowed range, but product of both mantissa and exponent goes out of
 *       MojDecimal.
 */
TEST(NumberTest, parse_decimal_overflow_by_exponent_bound)
{
    MojNumber::Parser parser;
    MojDecimal d(0,0);

    // log_10 {2^63 - 1} = 18.96
    // 18 - MojDecimal::Precision = 12
    // M * 10^12 > ((2^63 - 1) / 10^6 )  ==>  M > 9.22

    MojAssertNoErr( MojNumber::Lexer::parse(parser, "11e12") );
    EXPECT_EQ( MojErrValueOutOfRange, parser.toDecimal(d) );
    EXPECT_EQ( MojDecimal(0,0), d ); // should keep old value
}
Exemplo n.º 19
0
TEST_F(ReqSuite, original)
{
    buildSample();
    mark1();

    // test visibility with update
    {
        MojDbReq req;

        // start transaction
        req.begin(&db, false);
        mark2(req);

        // visible within transaction
        checkMarkWithUpdate(50ul, -2, req);
    }

    // invisible after aborted transaction
    checkMarkWithUpdate(0ul, -2);

    // test visibility with delete
    mark1();
    {
        MojDbReq req;
        // start transaction
        req.begin(&db, false);

        deleteMark(50ul, -1, req);

        // visible within transaction
        {
            MojDbQuery query;
            MojAssertNoErr( query.from(_T("Test:1")) );
            MojAssertNoErr( query.where(_T("bar"), MojDbQuery::OpLessThan, 2) );

            MojObject update;

            MojUInt32 count = 0xbaddcafe;
            MojAssertNoErr( db.merge(query, update, count, MojDb::FlagNone, req) );
            EXPECT_EQ( 33ul, count);
        }
    }

    // invisible after aborted transaction
    {
        MojDbQuery query;
        MojAssertNoErr( query.from(_T("Test:1")) );
        MojAssertNoErr( query.where(_T("bar"), MojDbQuery::OpLessThan, 2) );

        MojObject update;
        // Note: should not set value to something that will introduce double-update

        MojUInt32 count = 0xbaddcafe;
        MojAssertNoErr( db.merge(query, update, count) );

        EXPECT_EQ( 83ul, count);
    }
}
Exemplo n.º 20
0
TEST_F(DatabaseSuite, dump_and_load)
{

    // load
    MojAssertNoErr( MojFileFromString(MojLoadTestFileName, MojTestStr) );

    MojUInt32 count = 0;
    MojAssertNoErr( db.load(MojLoadTestFileName, count) );
    EXPECT_EQ( 11LL, count );

    checkCount();

    // dump
    count = 0;
    MojAssertNoErr( db.dump(MojDumpTestFileName, count) );
    EXPECT_EQ( 11LL, count );

    EXPECT_TRUE( db.kindEngine() );

    // verify that we can get this kind
    MojDbKind *pk = 0;
    MojExpectNoErr( db.kindEngine()->getKind(kindId.data(), pk) );
    EXPECT_TRUE( pk );

    // del
    bool found = false;
    MojAssertNoErr( db.delKind(kindId, found) );
    EXPECT_TRUE( found );

    // verify that we can NOT get this kind
    pk = 0;
    EXPECT_EQ( MojErrDbKindNotRegistered, db.kindEngine()->getKind(kindId.data(), pk) );
    EXPECT_FALSE( pk );

    // purge deleted kinds
    MojAssertNoErr( db.purge(count, 0) );
    EXPECT_EQ( 1LL, count ) << "Purged kinds marked for delete";

    // load again. why 12?
    MojAssertNoErr( db.load(MojDumpTestFileName, count) );
    EXPECT_EQ( 12LL, count );

    checkCount();

    // analyze
    MojObject analysis;
    MojAssertNoErr( db.stats(analysis) );
}
Exemplo n.º 21
0
 void getKindUsage(MojDb& db, const MojChar* kindId, MojInt64& usageOut)
 {
     MojRefCountedPtr<MojDbStorageTxn> txn;
     MojAssertNoErr( db.storageEngine()->beginTxn(txn) );
     MojAssertNoErr( db.quotaEngine()->kindUsage(kindId, usageOut, txn.get()) );
 }
Exemplo n.º 22
0
 void put(MojDb& db, const MojChar* objJson)
 {
     MojObject obj;
     MojAssertNoErr( obj.fromJson(objJson) );
     MojAssertNoErr( db.put(obj) );
 }
Exemplo n.º 23
0
 void SetUp()
 {
     MojDbCoreTest::SetUp();
     MojAssertNoErr( kindId.assign(_T("LoadTest:1")) );
 }
Exemplo n.º 24
0
 void getQuotaUsage(MojDb& db, const MojChar* owner, MojInt64& usageOut)
 {
     MojInt64 size;
     MojAssertNoErr( db.quotaEngine()->quotaUsage(owner, size, usageOut) );
 }
Exemplo n.º 25
0
TEST_F(QuotaTest, error)
{
	MojErr err;
    MojObject obj;

    // put quota (from testUsage)
	err = obj.fromJson(_T("{\"owner\":\"com.foo.bar\",\"size\":1000}"));
    MojAssertNoErr(err);

	err = db.putQuotas(&obj, &obj + 1);
    MojAssertNoErr(err);

    // quota for com.foo.baz (from multipleQuotas)
	err = obj.fromJson(_T("{\"owner\":\"com.foo.baz\",\"size\":1000}"));
	MojAssertNoErr(err);

	err = db.putQuotas(&obj, &obj + 1);
    MojAssertNoErr(err);

    // make kind2 inherit from kind1 (from multipleQuotas)
	err = obj.fromJson(MojTestKind2Str3);
    MojAssertNoErr(err);

	err = db.putKind(obj);
    MojExpectNoErr(err);

    // kind3 (from multipleQuotas)
	err = obj.fromJson(MojTestKind3Str1);
    MojAssertNoErr(err);

	err = db.putKind(obj);
    MojExpectNoErr(err);

    // wildcard (from multipleQuotas)
	err = obj.fromJson(_T("{\"owner\":\"com.foo.*\",\"size\":1000}"));
    MojAssertNoErr(err);

	err = db.putQuotas(&obj, &obj + 1);
    MojExpectNoErr(err);

	err = db.close();
	MojAssertNoErr(err);

	MojRefCountedPtr<MojDbEnv> testEnv(new MojDbTestStorageEnv(env));

	err = db.open(path.c_str(), testEnv);
	MojAssertNoErr(err);

	MojDbTestStorageEngine* testEngine = dynamic_cast<MojDbTestStorageEngine*> (db.storageEngine());
	ASSERT_TRUE(testEngine);

    // test that failed put does not affect quota
    MojInt64 quotaUsage1 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.*"), quotaUsage1) );
    EXPECT_LE( 0, quotaUsage1 );

	err = testEngine->setNextError(_T("txn.commit"), MojErrDbDeadlock);
    MojAssertNoErr(err);

	err = obj.fromJson(MojTestKind3Objects[1]);
    MojAssertNoErr(err);
    EXPECT_EQ( MojErrDbDeadlock, db.put(obj) );

    MojInt64 quotaUsage2 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.*"), quotaUsage2) );
    EXPECT_LE( 0, quotaUsage2 );
    EXPECT_EQ( quotaUsage1, quotaUsage2 );

    // test that failed putQuota has no effect
	err = testEngine->setNextError(_T("txn.commit"), MojErrDbDeadlock);
    MojAssertNoErr(err);

	err = obj.fromJson(_T("{\"owner\":\"com.foo.boo\",\"size\":1000}"));
    MojAssertNoErr(err);
    EXPECT_EQ( MojErrDbDeadlock, db.putQuotas(&obj, &obj + 1) );

    MojInt64 quotaUsage3 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.*"), quotaUsage3) );
    EXPECT_LE( 0, quotaUsage3 );
    EXPECT_EQ( quotaUsage1, quotaUsage3 );

    // test that failed putKind has no effect
	err = testEngine->setNextError(_T("txn.commit"), MojErrDbDeadlock);
    MojAssertNoErr(err);
	err = obj.fromJson(MojTestKind3Str2);
    MojAssertNoErr(err);
    EXPECT_EQ( MojErrDbDeadlock, db.putKind(obj) );

    MojInt64 quotaUsage4 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.*"), quotaUsage4) );
    EXPECT_LE( 0, quotaUsage4 );
    EXPECT_EQ( quotaUsage1, quotaUsage4 );
}
Exemplo n.º 26
0
TEST_F(QuotaTest, usage)
{
    // put quota
    MojObject obj;
    MojAssertNoErr( obj.fromJson(_T("{\"owner\":\"com.foo.bar\",\"size\":1000}")) );
    MojAssertNoErr( db.putQuotas(&obj, &obj + 1) );

    // empty
    MojInt64 kindUsage = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage) );
    EXPECT_EQ( 0, kindUsage )
        << "Kind without objects should have zero usage";
    MojInt64 quotaUsage = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage) );
    EXPECT_EQ( 0, quotaUsage )
        << "Quota without matching objects should have zero usage";

    // new obj
    EXPECT_NO_FATAL_FAILURE( put(db, MojTestKind1Objects[0]) );
    MojInt64 kindUsage1 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage1) );
    EXPECT_LT( 0, kindUsage1 )
        << "Adding new object into kind should increase kind usage";
    MojInt64 quotaUsage1 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1) );
    EXPECT_LT( 0, quotaUsage1 )
        << "Adding new object matching quota should increase quota usage";

    // add prop to existing obj
    MojAssertNoErr( obj.fromJson(MojTestKind1Objects[0]) );
    MojAssertNoErr( obj.put(_T("bar"), 2) );
    MojAssertNoErr( db.put(obj, MojDb::FlagForce) );
    MojInt64 kindUsage2 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage2) );
    EXPECT_LE( 0, kindUsage2 );
    EXPECT_LT( kindUsage1, kindUsage2 )
        << "Adding property to existing object should increase kind usage";
    MojInt64 quotaUsage2 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage2) );
    EXPECT_LE( 0, quotaUsage2 );
    EXPECT_LT( quotaUsage1, quotaUsage2 )
        << "Adding property to existing object that matches quota should increase usage";

    // add 2nd obj
    EXPECT_NO_FATAL_FAILURE( put(db, MojTestKind1Objects[1]) );
    MojInt64 kindUsage3 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage3) );
    EXPECT_LE( 0, kindUsage3 );
    EXPECT_LT( kindUsage2, kindUsage3 )
        << "Adding another object should increase kind usage";
    MojInt64 quotaUsage3 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage3) );
    EXPECT_LE( 0, quotaUsage3 );
    EXPECT_LT( quotaUsage2, quotaUsage3 )
        << "Adding another object matching to quota should increase usage";

    // del first obj
    bool found = false;
    MojExpectNoErr( db.del(1, found, MojDb::FlagPurge) );
    EXPECT_TRUE( found ) << "Object should be deleted";
    MojInt64 kindUsage4 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage4) );
    EXPECT_LE( 0, kindUsage4 );
    EXPECT_EQ( kindUsage3 - kindUsage2, kindUsage4 )
        << "Deletion of object should bring kind usage to expected value";
    MojInt64 quotaUsage4 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage4) );
    EXPECT_LE( 0, quotaUsage4 );
    EXPECT_EQ( quotaUsage3 - quotaUsage2, quotaUsage4 )
        << "Deletion of object should bring quota usage to expected value";

    // add index
    MojAssertNoErr( obj.fromJson(MojTestKind1Str2) );
    MojExpectNoErr( db.putKind(obj) );
    MojInt64 kindUsage5 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage5) );
    EXPECT_LE( 0, kindUsage5 );
    EXPECT_LT( kindUsage4, kindUsage5 )
        << "Adding new index should increase kind usage";
    MojInt64 quotaUsage5 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage5) );
    EXPECT_LE( 0, quotaUsage5 );
    EXPECT_LT( quotaUsage4, quotaUsage5 )
        << "Adding new index should increase quota usage";

    // update locale
    MojExpectNoErr( db.updateLocale(_T("FR_fr")) );
    MojExpectNoErr( db.updateLocale(_T("EN_us")) );
    MojInt64 kindUsage6 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage6) );
    EXPECT_LE( 0, kindUsage6 );
    EXPECT_EQ( kindUsage5, kindUsage6 )
        << "Switching locale forth and back shouldn't affect kind usage";
    MojInt64 quotaUsage6 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage6) );
    EXPECT_LE( 0, kindUsage6 );
    EXPECT_EQ( quotaUsage5, quotaUsage6 )
        << "Switching locale forth and back shouldn't affect quota usage";

    // drop index
    MojAssertNoErr( obj.fromJson(MojTestKind1Str1) );
    MojExpectNoErr( db.putKind(obj) );
    MojInt64 kindUsage7 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage7) );
    EXPECT_LE( 0, kindUsage7 );
    EXPECT_EQ( kindUsage4, kindUsage7 )
        << "Dropping of index should bring kind usage to expected value";
    MojInt64 quotaUsage7 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage7) );
    EXPECT_LE( 0, quotaUsage7 );
    EXPECT_EQ( quotaUsage4, quotaUsage7 )
        << "Dropping of index should bring quota usage to expected value";

    // drop kind
    MojString kindStr;
    MojAssertNoErr( kindStr.assign(_T("Test:1")) );
    MojExpectNoErr( db.delKind(kindStr, found) );
    EXPECT_TRUE( found ) << "Kind should be deleted";
    MojInt64 kindUsage8 = -1;
    EXPECT_NO_FATAL_FAILURE( getKindUsage(db, _T("Test:1"), kindUsage8) );
    EXPECT_EQ( 0, kindUsage8 )
        << "Dropping of kind should bring its usage to zero";
    MojInt64 quotaUsage8 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage8) );
    EXPECT_EQ( 0, quotaUsage8 )
        << "Dropping of kind that matches quota should bring quota usage to zero";
    MojExpectNoErr( db.quotaStats(obj) );

    MojString statStr;
    MojExpectNoErr( obj.toJson(statStr) );
    std::cerr << "quotaStats: " << statStr.data() << std::endl;
}
Exemplo n.º 27
0
TEST_F(QuotaTest, multipleQuotas)
{
    MojObject obj;

    // put quota (from testUsage)
    MojAssertNoErr( obj.fromJson(_T("{\"owner\":\"com.foo.bar\",\"size\":1000}")) );
    MojAssertNoErr( db.putQuotas(&obj, &obj + 1) );

    // quota for com.foo.baz
    MojAssertNoErr( obj.fromJson(_T("{\"owner\":\"com.foo.baz\",\"size\":1000}")) );
    MojAssertNoErr( db.putQuotas(&obj, &obj + 1) );

    // register kinds
    MojAssertNoErr( obj.fromJson(MojTestKind1Str1) );
    MojExpectNoErr( db.putKind(obj) );
    MojAssertNoErr( obj.fromJson(MojTestKind2Str1) );
    MojExpectNoErr( db.putKind(obj) );

    // put object of kind1 and kind2
    EXPECT_NO_FATAL_FAILURE( put(db, MojTestKind1Objects[0]) );
    EXPECT_NO_FATAL_FAILURE( put(db, MojTestKind2Objects[0]) );
    MojInt64 quotaUsage1 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1) );
    EXPECT_LE( 0, quotaUsage1 );
    MojInt64 quotaUsage2 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.baz"), quotaUsage2) );
    EXPECT_LE( 0, quotaUsage2 );
    EXPECT_LT( 0, quotaUsage1 );
    EXPECT_EQ( 0, quotaUsage2 );

    // change owner of kind2 to com.foo.baz
    MojAssertNoErr( obj.fromJson(MojTestKind2Str2) );
    MojExpectNoErr( db.putKind(obj) );
    MojInt64 quotaUsage3 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage3) );
    EXPECT_LE( 0, quotaUsage3 );
    MojInt64 quotaUsage4 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.baz"), quotaUsage4) );
    EXPECT_LE( 0, quotaUsage4 );
    EXPECT_LT( 0, quotaUsage3 );
    EXPECT_EQ( quotaUsage3, quotaUsage4);

    // make kind2 inherit from kind1
    MojAssertNoErr( obj.fromJson(MojTestKind2Str3) );
    MojExpectNoErr( db.putKind(obj) );
    MojInt64 quotaUsage5 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage5) );
    MojInt64 quotaUsage6 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.baz"), quotaUsage6) );
    EXPECT_GT( quotaUsage5, quotaUsage1 );
    EXPECT_EQ( 0, quotaUsage6 );

    // kind3 and object
    MojAssertNoErr( obj.fromJson(MojTestKind3Str1) );
    MojExpectNoErr( db.putKind(obj) );
    EXPECT_NO_FATAL_FAILURE( put(db, MojTestKind3Objects[0]) );
    MojInt64 quotaUsage7 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage7) );
    EXPECT_EQ( quotaUsage7, quotaUsage5 );

    // wildcard
    MojAssertNoErr( obj.fromJson(_T("{\"owner\":\"com.foo.*\",\"size\":1000}")) );
    MojExpectNoErr( db.putQuotas(&obj, &obj + 1) );
    MojInt64 quotaUsage8 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage8) );
    MojInt64 quotaUsage9 = -1;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.*"), quotaUsage9) );
    EXPECT_EQ( quotaUsage5, quotaUsage8 );
    EXPECT_LT( 0, quotaUsage9 );
}