@@ -57,6 +57,21 @@ class MagmaKVStoreTest : public KVStoreTest {
5757 rollbackTest = true ;
5858 }
5959
60+ queued_item doWrite (uint64_t seqno,
61+ bool expected,
62+ const std::string& key = " key" ) {
63+ auto ctx =
64+ kvstore->begin (vbid, std::make_unique<PersistenceCallback>());
65+ auto qi = makeCommittedItem (makeStoredDocKey (key),
66+ " value" + std::to_string (seqno));
67+ qi->setBySeqno (seqno);
68+ flush.proposedVBState .lastSnapStart = seqno;
69+ flush.proposedVBState .lastSnapEnd = seqno;
70+ kvstore->set (*ctx, qi);
71+ EXPECT_EQ (expected, kvstore->commit (std::move (ctx), flush));
72+ return qi;
73+ };
74+
6075private:
6176 bool rollbackTest{false };
6277};
@@ -697,4 +712,34 @@ TEST_F(MagmaKVStoreTest, makeFileHandleSyncFailed) {
697712 setupSyncStatus (magma::Status (magma::Status::Internal, " Internal" ));
698713 fileHandle = kvstore->makeFileHandle (vbid);
699714 EXPECT_FALSE (fileHandle);
715+ }
716+
717+ // @todo: This is a basic test that will be expanded to cover scanning history
718+ // at the moment this test is equivalent to "scan"
719+ TEST_F (MagmaKVStoreTest, scanAllVersions) {
720+ initialize_kv_store (kvstore.get (), vbid);
721+ std::vector<queued_item> expectedItems;
722+ expectedItems.push_back (doWrite (1 , true , " k1" ));
723+ expectedItems.push_back (doWrite (2 , true , " k2" ));
724+ auto validate = [&expectedItems](GetValue gv) {
725+ ASSERT_TRUE (gv.item );
726+ ASSERT_GE (expectedItems.size (), size_t (gv.item ->getBySeqno ()));
727+ EXPECT_EQ (*expectedItems[gv.item ->getBySeqno () - 1 ], *gv.item );
728+ };
729+ auto bySeq = kvstore->initBySeqnoScanContext (
730+ std::make_unique<CustomCallback<GetValue>>(validate),
731+ std::make_unique<CustomCallback<CacheLookup>>(),
732+ vbid,
733+ 1 ,
734+ DocumentFilter::ALL_ITEMS,
735+ ValueFilter::VALUES_COMPRESSED,
736+ SnapshotSource::Head);
737+ ASSERT_TRUE (bySeq);
738+ // @todo: This must be the expected seqno where history begins
739+ EXPECT_EQ (0 , bySeq->historyStartSeqno );
740+ EXPECT_EQ (scan_success, kvstore->scanAllVersions (*bySeq));
741+
742+ auto & cb =
743+ static_cast <CustomCallback<GetValue>&>(bySeq->getValueCallback ());
744+ EXPECT_EQ (2 , cb.getProcessedCount ());
700745}
0 commit comments