diff options
Diffstat (limited to 'storageapi/src/tests/mbusprot/storageprotocoltest.cpp')
-rw-r--r-- | storageapi/src/tests/mbusprot/storageprotocoltest.cpp | 87 |
1 files changed, 56 insertions, 31 deletions
diff --git a/storageapi/src/tests/mbusprot/storageprotocoltest.cpp b/storageapi/src/tests/mbusprot/storageprotocoltest.cpp index 4d5a33b1dec..f03c59f0887 100644 --- a/storageapi/src/tests/mbusprot/storageprotocoltest.cpp +++ b/storageapi/src/tests/mbusprot/storageprotocoltest.cpp @@ -22,6 +22,7 @@ #include <sstream> using std::shared_ptr; +using document::BucketSpace; using document::ByteBuffer; using document::Document; using document::DocumentId; @@ -33,11 +34,20 @@ using vespalib::string; namespace storage { namespace api { +namespace { + +document::Bucket makeDocumentBucket(document::BucketId bucketId) +{ + return document::Bucket(BucketSpace::placeHolder(), bucketId); +} + +} + struct StorageProtocolTest : public CppUnit::TestFixture { document::TestDocMan _docMan; document::Document::SP _testDoc; document::DocumentId _testDocId; - document::BucketId _bucket{16, 0x51}; + document::Bucket _bucket; vespalib::Version _version5_0{5, 0, 12}; vespalib::Version _version5_1{5, 1, 0}; vespalib::Version _version5_2{5, 93, 30}; @@ -52,6 +62,7 @@ struct StorageProtocolTest : public CppUnit::TestFixture { : _docMan(), _testDoc(_docMan.createDocument()), _testDocId(_testDoc->getId()), + _bucket(makeDocumentBucket(document::BucketId(16, 0x51))), _protocol(_docMan.getTypeRepoSP(), _loadTypes) { _loadTypes.addLoadType(34, "foo", documentapi::Priority::PRI_NORMAL_2); @@ -427,8 +438,10 @@ StorageProtocolTest::testNotifyBucketChange51() { ScopedName test("testNotifyBucketChange51"); BucketInfo info(2, 3, 4); + document::BucketId modifiedBucketId(20, 1000); + document::Bucket modifiedBucket(makeDocumentBucket(modifiedBucketId)); NotifyBucketChangeCommand::SP cmd(new NotifyBucketChangeCommand( - document::BucketId(20, 1000), info)); + modifiedBucket, info)); NotifyBucketChangeCommand::SP cmd2(copyCommand(cmd, _version5_1)); CPPUNIT_ASSERT_EQUAL(document::BucketId(20, 1000), cmd2->getBucketId()); @@ -446,15 +459,16 @@ void StorageProtocolTest::testCreateBucket51() { ScopedName test("testCreateBucket51"); - document::BucketId id(623); + document::BucketId bucketId(623); + document::Bucket bucket(makeDocumentBucket(bucketId)); - CreateBucketCommand::SP cmd(new CreateBucketCommand(id)); + CreateBucketCommand::SP cmd(new CreateBucketCommand(bucket)); CreateBucketCommand::SP cmd2(copyCommand(cmd, _version5_1)); - CPPUNIT_ASSERT_EQUAL(id, cmd2->getBucketId()); + CPPUNIT_ASSERT_EQUAL(bucketId, cmd2->getBucketId()); CreateBucketReply::SP reply(new CreateBucketReply(*cmd)); CreateBucketReply::SP reply2(copyReply(reply)); - CPPUNIT_ASSERT_EQUAL(id, reply2->getBucketId()); + CPPUNIT_ASSERT_EQUAL(bucketId, reply2->getBucketId()); recordOutput(*cmd2); recordOutput(*reply2); @@ -465,20 +479,21 @@ void StorageProtocolTest::testDeleteBucket51() { ScopedName test("testDeleteBucket51"); - document::BucketId id(623); + document::BucketId bucketId(623); + document::Bucket bucket(makeDocumentBucket(bucketId)); - DeleteBucketCommand::SP cmd(new DeleteBucketCommand(id)); + DeleteBucketCommand::SP cmd(new DeleteBucketCommand(bucket)); BucketInfo info(0x100, 200, 300); cmd->setBucketInfo(info); DeleteBucketCommand::SP cmd2(copyCommand(cmd, _version5_1)); - CPPUNIT_ASSERT_EQUAL(id, cmd2->getBucketId()); + CPPUNIT_ASSERT_EQUAL(bucketId, cmd2->getBucketId()); CPPUNIT_ASSERT_EQUAL(info, cmd2->getBucketInfo()); DeleteBucketReply::SP reply(new DeleteBucketReply(*cmd)); // Not set automatically by constructor reply->setBucketInfo(cmd2->getBucketInfo()); DeleteBucketReply::SP reply2(copyReply(reply)); - CPPUNIT_ASSERT_EQUAL(id, reply2->getBucketId()); + CPPUNIT_ASSERT_EQUAL(bucketId, reply2->getBucketId()); CPPUNIT_ASSERT_EQUAL(info, reply2->getBucketInfo()); recordOutput(*cmd2); @@ -490,7 +505,8 @@ void StorageProtocolTest::testMergeBucket51() { ScopedName test("testMergeBucket51"); - document::BucketId id(623); + document::BucketId bucketId(623); + document::Bucket bucket(makeDocumentBucket(bucketId)); typedef api::MergeBucketCommand::Node Node; std::vector<Node> nodes; @@ -504,9 +520,9 @@ StorageProtocolTest::testMergeBucket51() chain.push_back(14); MergeBucketCommand::SP cmd( - new MergeBucketCommand(id, nodes, Timestamp(1234), 567, chain)); + new MergeBucketCommand(bucket, nodes, Timestamp(1234), 567, chain)); MergeBucketCommand::SP cmd2(copyCommand(cmd, _version5_1)); - CPPUNIT_ASSERT_EQUAL(id, cmd2->getBucketId()); + CPPUNIT_ASSERT_EQUAL(bucketId, cmd2->getBucketId()); CPPUNIT_ASSERT_EQUAL(nodes, cmd2->getNodes()); CPPUNIT_ASSERT_EQUAL(Timestamp(1234), cmd2->getMaxTimestamp()); CPPUNIT_ASSERT_EQUAL(uint32_t(567), cmd2->getClusterStateVersion()); @@ -514,7 +530,7 @@ StorageProtocolTest::testMergeBucket51() MergeBucketReply::SP reply(new MergeBucketReply(*cmd)); MergeBucketReply::SP reply2(copyReply(reply)); - CPPUNIT_ASSERT_EQUAL(id, reply2->getBucketId()); + CPPUNIT_ASSERT_EQUAL(bucketId, reply2->getBucketId()); CPPUNIT_ASSERT_EQUAL(nodes, reply2->getNodes()); CPPUNIT_ASSERT_EQUAL(Timestamp(1234), reply2->getMaxTimestamp()); CPPUNIT_ASSERT_EQUAL(uint32_t(567), reply2->getClusterStateVersion()); @@ -530,7 +546,8 @@ StorageProtocolTest::testSplitBucket51() { ScopedName test("testSplitBucket51"); - document::BucketId bucket(16, 0); + document::BucketId bucketId(16, 0); + document::Bucket bucket(makeDocumentBucket(bucketId)); SplitBucketCommand::SP cmd(new SplitBucketCommand(bucket)); CPPUNIT_ASSERT_EQUAL(0u, (uint32_t) cmd->getMinSplitBits()); CPPUNIT_ASSERT_EQUAL(58u, (uint32_t) cmd->getMaxSplitBits()); @@ -555,7 +572,7 @@ StorageProtocolTest::testSplitBucket51() document::BucketId(17, 1), BucketInfo(101, 1001, 10001, true, true))); SplitBucketReply::SP reply2(copyReply(reply)); - CPPUNIT_ASSERT_EQUAL(bucket, reply2->getBucketId()); + CPPUNIT_ASSERT_EQUAL(bucketId, reply2->getBucketId()); CPPUNIT_ASSERT_EQUAL(size_t(2), reply2->getSplitInfo().size()); CPPUNIT_ASSERT_EQUAL(document::BucketId(17, 0), reply2->getSplitInfo()[0].first); @@ -575,7 +592,8 @@ void StorageProtocolTest::testJoinBuckets51() { ScopedName test("testJoinBuckets51"); - document::BucketId bucket(16, 0); + document::BucketId bucketId(16, 0); + document::Bucket bucket(makeDocumentBucket(bucketId)); std::vector<document::BucketId> sources; sources.push_back(document::BucketId(17, 0)); sources.push_back(document::BucketId(17, 1)); @@ -591,7 +609,7 @@ StorageProtocolTest::testJoinBuckets51() CPPUNIT_ASSERT_EQUAL(sources, reply2->getSourceBuckets()); CPPUNIT_ASSERT_EQUAL(3, (int)cmd2->getMinJoinBits()); CPPUNIT_ASSERT_EQUAL(BucketInfo(3,4,5), reply2->getBucketInfo()); - CPPUNIT_ASSERT_EQUAL(bucket, reply2->getBucketId()); + CPPUNIT_ASSERT_EQUAL(bucketId, reply2->getBucketId()); recordOutput(*cmd2); recordOutput(*reply2); @@ -619,12 +637,14 @@ void StorageProtocolTest::testRemoveLocation51() { ScopedName test("testRemoveLocation51"); + document::BucketId bucketId(16, 1234); + document::Bucket bucket(makeDocumentBucket(bucketId)); RemoveLocationCommand::SP cmd( - new RemoveLocationCommand("id.group == \"mygroup\"", document::BucketId(16, 1234))); + new RemoveLocationCommand("id.group == \"mygroup\"", bucket)); RemoveLocationCommand::SP cmd2(copyCommand(cmd, _version5_1)); CPPUNIT_ASSERT_EQUAL(vespalib::string("id.group == \"mygroup\""), cmd2->getDocumentSelection()); - CPPUNIT_ASSERT_EQUAL(document::BucketId(16, 1234), cmd2->getBucketId()); + CPPUNIT_ASSERT_EQUAL(bucketId, cmd2->getBucketId()); RemoveLocationReply::SP reply(new RemoveLocationReply(*cmd2)); RemoveLocationReply::SP reply2(copyReply(reply)); @@ -689,7 +709,8 @@ void StorageProtocolTest::testGetBucketDiff51() { ScopedName test("testGetBucketDiff51"); - document::BucketId id(623); + document::BucketId bucketId(623); + document::Bucket bucket(makeDocumentBucket(bucketId)); std::vector<api::MergeBucketCommand::Node> nodes; nodes.push_back(4); @@ -709,7 +730,7 @@ StorageProtocolTest::testGetBucketDiff51() " header size: 100, body size: 65536, flags 0x1)"), entries.back().toString(true)); - GetBucketDiffCommand::SP cmd(new GetBucketDiffCommand(id, nodes, 1056)); + GetBucketDiffCommand::SP cmd(new GetBucketDiffCommand(bucket, nodes, 1056)); cmd->getDiff() = entries; GetBucketDiffCommand::SP cmd2(copyCommand(cmd, _version5_1)); @@ -730,7 +751,8 @@ void StorageProtocolTest::testApplyBucketDiff51() { ScopedName test("testApplyBucketDiff51"); - document::BucketId id(16, 623); + document::BucketId bucketId(16, 623); + document::Bucket bucket(makeDocumentBucket(bucketId)); std::vector<api::MergeBucketCommand::Node> nodes; nodes.push_back(4); @@ -738,7 +760,7 @@ StorageProtocolTest::testApplyBucketDiff51() std::vector<ApplyBucketDiffCommand::Entry> entries; entries.push_back(ApplyBucketDiffCommand::Entry()); - ApplyBucketDiffCommand::SP cmd(new ApplyBucketDiffCommand(id, nodes, 1234)); + ApplyBucketDiffCommand::SP cmd(new ApplyBucketDiffCommand(bucket, nodes, 1234)); cmd->getDiff() = entries; ApplyBucketDiffCommand::SP cmd2(copyCommand(cmd, _version5_1)); @@ -759,13 +781,14 @@ StorageProtocolTest::testMultiOperation51() { ScopedName test("testMultiOperation51"); - document::BucketId bucket(20, 0xf1f1f1f1f1ull); + document::BucketId bucketId(20, 0xf1f1f1f1f1ull); + document::Bucket bucket(makeDocumentBucket(bucketId)); DocumentTypeRepo::SP repo(new DocumentTypeRepo); MultiOperationCommand::SP cmd(new MultiOperationCommand(repo, bucket, 10000)); cmd->getOperations().addPut(*_testDoc); MultiOperationCommand::SP cmd2(copyCommand(cmd, _version5_1)); - CPPUNIT_ASSERT_EQUAL(bucket, cmd2->getBucketId()); + CPPUNIT_ASSERT_EQUAL(bucketId, cmd2->getBucketId()); CPPUNIT_ASSERT_EQUAL(*_testDoc, *cmd2->getOperations().begin()->getDocument()); @@ -782,14 +805,15 @@ StorageProtocolTest::testBatchPutRemove51() { ScopedName test("testBatchPutRemove51"); - document::BucketId bucket(20, 0xf1f1f1f1f1ull); + document::BucketId bucketId(20, 0xf1f1f1f1f1ull); + document::Bucket bucket(makeDocumentBucket(bucketId)); BatchPutRemoveCommand::SP cmd(new BatchPutRemoveCommand(bucket)); cmd->addPut(_testDoc, 100); cmd->addHeaderUpdate(_testDoc, 101, 1234); cmd->addRemove(_testDoc->getId(), 102); cmd->forceMsgId(556677); BatchPutRemoveCommand::SP cmd2(copyCommand(cmd, _version5_1)); - CPPUNIT_ASSERT_EQUAL(bucket, cmd2->getBucketId()); + CPPUNIT_ASSERT_EQUAL(bucketId, cmd2->getBucketId()); CPPUNIT_ASSERT_EQUAL(3, (int)cmd2->getOperationCount()); CPPUNIT_ASSERT_EQUAL(*_testDoc, *(dynamic_cast<const BatchPutRemoveCommand::PutOperation&>(cmd2->getOperation(0)).document)); CPPUNIT_ASSERT_EQUAL((uint64_t)100, cmd2->getOperation(0).timestamp); @@ -872,7 +896,8 @@ void StorageProtocolTest::testSetBucketState51() { ScopedName test("testSetBucketState51"); - document::BucketId bucket(16, 0); + document::BucketId bucketId(16, 0); + document::Bucket bucket(makeDocumentBucket(bucketId)); SetBucketStateCommand::SP cmd( new SetBucketStateCommand(bucket, SetBucketStateCommand::ACTIVE)); SetBucketStateCommand::SP cmd2(copyCommand(cmd, _version5_1)); @@ -881,8 +906,8 @@ StorageProtocolTest::testSetBucketState51() SetBucketStateReply::SP reply2(copyReply(reply)); CPPUNIT_ASSERT_EQUAL(SetBucketStateCommand::ACTIVE, cmd2->getState()); - CPPUNIT_ASSERT_EQUAL(bucket, cmd2->getBucketId()); - CPPUNIT_ASSERT_EQUAL(bucket, reply2->getBucketId()); + CPPUNIT_ASSERT_EQUAL(bucketId, cmd2->getBucketId()); + CPPUNIT_ASSERT_EQUAL(bucketId, reply2->getBucketId()); recordOutput(*cmd2); recordOutput(*reply2); |