Test that gid mapper can iterate over known gids.
#include <vespa/searchcore/proton/bucketdb/bucket_db_owner.h>
#include <vespa/searchcore/proton/documentmetastore/documentmetastore.h>
#include <vespa/vespalib/stllike/string.h>
+#include <vespa/vespalib/test/insertion_operators.h>
#include <vespa/document/base/documentid.h>
#include <vespa/document/bucket/bucketid.h>
#include <vespa/searchcore/proton/reference/gid_to_lid_mapper.h>
@@ -40,6 +41,31 @@ void assertLid(const std::unique_ptr<search::IGidToLidMapper> &mapper, const ves
EXPECT_EQUAL(lid, mapper->mapGidToLid(toGid(docId)));
}
+using GidMap = std::map<GlobalId, uint32_t>;
+
+struct GidCollector : public search::IGidToLidMapperVisitor
+{
+ GidMap &_map;
+ GidCollector(GidMap &map)
+ : IGidToLidMapperVisitor(),
+ _map(map)
+ {
+ }
+ virtual void visit(const document::GlobalId &gid, uint32_t lid) const override { _map.insert(std::make_pair(gid, lid)); }
+};
+
+GidMap collectGids(const std::unique_ptr<search::IGidToLidMapper> &mapper)
+{
+ GidMap result;
+ mapper->foreach(GidCollector(result));
+ return result;
+}
+
+void assertGids(const GidMap &expGids, const GidMap &gids)
+{
+ EXPECT_EQUAL(expGids, gids);
+}
+
}
struct Fixture
@@ -136,6 +162,17 @@ TEST_F("Test that mapper holds read guard", Fixture)
TEST_DO(f.assertPut(doc3, 2, 10, 7, [&]() -> auto & { return mapper; }));
}
+TEST_F("Test that gid mapper can iterate over known gids", Fixture)
+{
+ auto factory = f.getGidToLidMapperFactory();
+ auto mapper = factory->getMapper();
+ TEST_DO(assertGids({{toGid(doc1), 4}, {toGid(doc2), 7}}, collectGids(mapper)));
+ f.put(doc3);
+ TEST_DO(assertGids({{toGid(doc1), 4}, {toGid(doc2), 7}, {toGid(doc3), 1}}, collectGids(mapper)));
+ f.remove(4);
+ TEST_DO(assertGids({{toGid(doc2), 7}, {toGid(doc3), 1}}, collectGids(mapper)));
+}
+
}
TEST_MAIN()
