From 403c3cfc37cdecb8e342d686a3512fdd74989ffb Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Wed, 13 Sep 2017 15:13:05 +0000 Subject: Check that split and join can trigger bucket create notification. --- .../documentmetastore/documentmetastore_test.cpp | 43 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'searchcore/src/tests') diff --git a/searchcore/src/tests/proton/documentmetastore/documentmetastore_test.cpp b/searchcore/src/tests/proton/documentmetastore/documentmetastore_test.cpp index a389e702c69..9bcc63ad8d6 100644 --- a/searchcore/src/tests/proton/documentmetastore/documentmetastore_test.cpp +++ b/searchcore/src/tests/proton/documentmetastore/documentmetastore_test.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -12,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +22,7 @@ LOG_SETUP("documentmetastore_test"); using namespace document; using proton::bucketdb::BucketState; +using proton::bucketdb::IBucketCreateListener; using search::AttributeFileSaveTarget; using search::AttributeGuard; using search::AttributeVector; @@ -1132,6 +1135,30 @@ struct GlobalIdEntry { typedef std::vector GlobalIdVector; +struct MyBucketCreateListener : public IBucketCreateListener +{ + std::vector _buckets; + + MyBucketCreateListener(); + ~MyBucketCreateListener(); + virtual void notifyCreateBucket(const document::BucketId &bucket) override; +}; + +MyBucketCreateListener::MyBucketCreateListener() +{ +} + +MyBucketCreateListener::~MyBucketCreateListener() +{ +} + + +void +MyBucketCreateListener::notifyCreateBucket(const document::BucketId &bucket) +{ + _buckets.emplace_back(bucket); +} + struct SplitAndJoinEmptyFixture { DocumentMetaStore dms; @@ -1146,6 +1173,7 @@ struct SplitAndJoinEmptyFixture BucketId bid34; // contained in bid10 and bid20 BucketId bid36; // contained in bid10 and bid22 bucketdb::BucketDBHandler _bucketDBHandler; + MyBucketCreateListener _bucketCreateListener; SplitAndJoinEmptyFixture(); ~SplitAndJoinEmptyFixture(); @@ -1153,6 +1181,10 @@ struct SplitAndJoinEmptyFixture BucketInfo getInfo(const BucketId &bid) const { return dms.getBucketDB().takeGuard()->get(bid); } + + void assertNotifyCreateBuckets(std::vector expBuckets) { + EXPECT_EQUAL(expBuckets, _bucketCreateListener._buckets); + } }; SplitAndJoinEmptyFixture::SplitAndJoinEmptyFixture() @@ -1160,11 +1192,16 @@ SplitAndJoinEmptyFixture::SplitAndJoinEmptyFixture() bid10(1, 0), bid11(1, 1), bid20(2, 0), bid21(2, 1), bid22(2, 2), bid23(2, 3), bid30(3, 0), bid32(3, 2), bid34(3, 4), bid36(3, 6), - _bucketDBHandler(dms.getBucketDB()) + _bucketDBHandler(dms.getBucketDB()), + _bucketCreateListener() { _bucketDBHandler.addDocumentMetaStore(&dms, 0); + _bucketDBHandler.getBucketCreateNotifier().addListener(&_bucketCreateListener); +} +SplitAndJoinEmptyFixture::~SplitAndJoinEmptyFixture() +{ + _bucketDBHandler.getBucketCreateNotifier().removeListener(&_bucketCreateListener); } -SplitAndJoinEmptyFixture::~SplitAndJoinEmptyFixture() {} struct SplitAndJoinFixture : public SplitAndJoinEmptyFixture @@ -1314,6 +1351,7 @@ TEST("requireThatBucketInfoIsCorrectAfterSplit") EXPECT_EQUAL(bi11.getDocumentCount(), bi21.getDocumentCount() + bi23.getDocumentCount()); + f.assertNotifyCreateBuckets({ f.bid21, f.bid23 }); } TEST("requireThatActiveStateIsPreservedAfterSplit") @@ -1460,6 +1498,7 @@ TEST("requireThatBucketInfoIsCorrectAfterJoin") EXPECT_EQUAL(bi21.getDocumentCount() + bi23.getDocumentCount(), bi11.getDocumentCount()); + f.assertNotifyCreateBuckets({ f.bid11 }); } TEST("requireThatActiveStateIsPreservedAfterJoin") -- cgit v1.2.3