diff options
author | Tor Egge <Tor.Egge@oath.com> | 2017-10-10 13:52:38 +0000 |
---|---|---|
committer | Tor Egge <Tor.Egge@oath.com> | 2017-10-10 13:52:38 +0000 |
commit | 101d599ab0478ba9e8d2bc6558f708909e12d4a9 (patch) | |
tree | b0d2d90eedeb02cfec0cae9ac4c061942b4e6107 /persistence/src | |
parent | 64dc18c66319310fe2ba45fe60268e0b59046bc1 (diff) |
Add minimal test using multiple bucket spaces when peristence provider
claims to support it.
Diffstat (limited to 'persistence/src')
4 files changed, 95 insertions, 5 deletions
diff --git a/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp b/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp index 88dd475e6f6..662955be1b7 100644 --- a/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp +++ b/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp @@ -17,6 +17,7 @@ #include <limits> using document::BucketId; +using document::BucketSpace; using storage::spi::test::makeBucket; using storage::spi::test::makeBucketSpace; @@ -2300,6 +2301,72 @@ void ConformanceTest::testRemoveEntry() } } +void assertBucketInfo(PersistenceProvider &spi, const Bucket &bucket, uint32_t expDocCount) +{ + const BucketInfo info = spi.getBucketInfo(bucket).getBucketInfo(); + CPPUNIT_ASSERT_EQUAL(expDocCount, info.getDocumentCount()); + CPPUNIT_ASSERT(info.getEntryCount() >= info.getDocumentCount()); + CPPUNIT_ASSERT(info.getChecksum() != 0); + CPPUNIT_ASSERT(info.getDocumentSize() > 0); + CPPUNIT_ASSERT(info.getUsedSize() >= info.getDocumentSize()); +} + +void assertBucketList(PersistenceProvider &spi, + BucketSpace &bucketSpace, + PartitionId partId, + const std::vector<BucketId> &expBuckets) +{ + BucketIdListResult result = spi.listBuckets(bucketSpace, partId); + const BucketIdListResult::List &bucketList = result.getList(); + CPPUNIT_ASSERT_EQUAL(expBuckets.size(), bucketList.size()); + for (const auto &expBucket : expBuckets) { + CPPUNIT_ASSERT(std::find(bucketList.begin(), bucketList.end(), expBucket) != bucketList.end()); + } +} + +void ConformanceTest::testBucketSpaces() +{ + if (!_factory->supportsBucketSpaces()) { + return; + } + document::TestDocMan testDocMan; + _factory->clear(); + PersistenceProvider::UP spi(getSpi(*_factory, testDocMan)); + Context context(defaultLoadType, Priority(0), Trace::TraceLevel(0)); + BucketSpace bucketSpace0(makeBucketSpace("testdoctype1")); + BucketSpace bucketSpace1(makeBucketSpace("testdoctype2")); + BucketSpace bucketSpace2(makeBucketSpace("no")); + PartitionId partId(0); + + BucketId bucketId1(8, 0x01); + BucketId bucketId2(8, 0x02); + Bucket bucket01({ bucketSpace0, bucketId1 }, partId); + Bucket bucket11({ bucketSpace1, bucketId1 }, partId); + Bucket bucket12({ bucketSpace1, bucketId2 }, partId); + Document::SP doc1 = testDocMan.createDocument("content", "id:test:testdoctype1:n=1:1", "testdoctype1"); + Document::SP doc2 = testDocMan.createDocument("content", "id:test:testdoctype1:n=1:2", "testdoctype1"); + Document::SP doc3 = testDocMan.createDocument("content", "id:test:testdoctype2:n=1:3", "testdoctype2"); + Document::SP doc4 = testDocMan.createDocument("content", "id:test:testdoctype2:n=2:4", "testdoctype2"); + spi->createBucket(bucket01, context); + spi->createBucket(bucket11, context); + spi->createBucket(bucket12, context); + spi->put(bucket01, Timestamp(3), doc1, context); + spi->put(bucket01, Timestamp(4), doc2, context); + spi->put(bucket11, Timestamp(5), doc3, context); + spi->put(bucket12, Timestamp(6), doc4, context); + spi->flush(bucket01, context); + spi->flush(bucket11, context); + spi->flush(bucket12, context); + // Check bucket lists + assertBucketList(*spi, bucketSpace0, partId, { bucketId1 }); + assertBucketList(*spi, bucketSpace1, partId, { bucketId1, bucketId2 }); + assertBucketList(*spi, bucketSpace2, partId, { }); + // Check bucket info + assertBucketInfo(*spi, bucket01, 2); + assertBucketInfo(*spi, bucket11, 1); + assertBucketInfo(*spi, bucket12, 1); +} + void ConformanceTest::detectAndTestOptionalBehavior() { // Report if implementation supports setting bucket size info. diff --git a/persistence/src/vespa/persistence/conformancetest/conformancetest.h b/persistence/src/vespa/persistence/conformancetest/conformancetest.h index 46aee7a33b8..66b1dec113a 100644 --- a/persistence/src/vespa/persistence/conformancetest/conformancetest.h +++ b/persistence/src/vespa/persistence/conformancetest/conformancetest.h @@ -58,6 +58,7 @@ CPPUNIT_TEST(testBucketActivation); \ CPPUNIT_TEST(testBucketActivationSplitAndJoin); \ CPPUNIT_TEST(testRemoveEntry); \ + CPPUNIT_TEST(testBucketSpaces); \ CPPUNIT_TEST(detectAndTestOptionalBehavior); namespace document @@ -100,6 +101,8 @@ struct ConformanceTest : public CppUnit::TestFixture { { return false; } + // If bucket spaces are supported then testdoctype2 is in bucket space 1 + virtual bool supportsBucketSpaces() const { return false; } }; PersistenceFactory::UP _factory; @@ -261,6 +264,9 @@ public: void testRemoveEntry(); + /** Test multiple bucket spaces */ + void testBucketSpaces(); + /** * Reports what optional behavior is supported by implementation and not. * Tests functionality if supported. diff --git a/persistence/src/vespa/persistence/spi/test.cpp b/persistence/src/vespa/persistence/spi/test.cpp index 08ee060a52f..d91f7fdfc1c 100644 --- a/persistence/src/vespa/persistence/spi/test.cpp +++ b/persistence/src/vespa/persistence/spi/test.cpp @@ -2,19 +2,35 @@ #include "test.h" +using document::BucketId; +using document::BucketSpace; + namespace storage::spi::test { -document::BucketSpace makeBucketSpace() +BucketSpace makeBucketSpace() +{ + return BucketSpace::placeHolder(); +} + +BucketSpace makeBucketSpace(const vespalib::string &docTypeName) { - return document::BucketSpace::placeHolder(); + // Used by persistence conformance test to map fron document type name + // to bucket space. See document::TestDocRepo for known document types. + if (docTypeName == "no") { + return BucketSpace(2); + } else if (docTypeName == "testdoctype2") { + return BucketSpace(1); + } else { + return makeBucketSpace(); + } } -Bucket makeBucket(document::BucketId bucketId, PartitionId partitionId) +Bucket makeBucket(BucketId bucketId, PartitionId partitionId) { - return Bucket(document::Bucket(document::BucketSpace::placeHolder(), bucketId), partitionId); + return Bucket(document::Bucket(BucketSpace::placeHolder(), bucketId), partitionId); } -Bucket makeBucket(document::BucketId bucketId) +Bucket makeBucket(BucketId bucketId) { return makeBucket(bucketId, PartitionId(0)); } diff --git a/persistence/src/vespa/persistence/spi/test.h b/persistence/src/vespa/persistence/spi/test.h index babc136cc81..cbd546d6315 100644 --- a/persistence/src/vespa/persistence/spi/test.h +++ b/persistence/src/vespa/persistence/spi/test.h @@ -9,6 +9,7 @@ namespace storage::spi::test { // Helper functions used by unit tests document::BucketSpace makeBucketSpace(); +document::BucketSpace makeBucketSpace(const vespalib::string &docTypeName); Bucket makeBucket(document::BucketId bucketId, PartitionId partitionId); Bucket makeBucket(document::BucketId bucketId); |