// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include #include #include #include #include #include #include #include #include #include LOG_SETUP("gid_to_lid_change_registrator_test"); namespace proton { class MyListener : public IGidToLidChangeListener { vespalib::string _docTypeName; vespalib::string _name; public: MyListener(const vespalib::string &docTypeName, const vespalib::string &name) : _docTypeName(docTypeName), _name(name) { } ~MyListener() override { } void notifyPutDone(IDestructorCallbackSP, document::GlobalId, uint32_t) override { } void notifyRemove(IDestructorCallbackSP, document::GlobalId) override { } void notifyRegistered(const std::vector&) override { } const vespalib::string &getName() const override { return _name; } const vespalib::string &getDocTypeName() const override { return _docTypeName; } }; using test::MockGidToLidChangeHandler; using AddEntry = MockGidToLidChangeHandler::AddEntry; using RemoveEntry = MockGidToLidChangeHandler::RemoveEntry; struct Fixture { std::shared_ptr _handler; Fixture() : _handler(std::make_shared()) { } ~Fixture() { } std::unique_ptr getRegistrator(const vespalib::string &docTypeName) { return std::make_unique(_handler, docTypeName); } void assertAdds(const std::vector &expAdds) { _handler->assertAdds(expAdds); } void assertRemoves(const std::vector &expRemoves) { _handler->assertRemoves(expRemoves); } }; TEST_F("Test that we can register a listener", Fixture) { auto registrator = f.getRegistrator("testdoc"); TEST_DO(f.assertAdds({})); TEST_DO(f.assertRemoves({})); registrator->addListener(std::make_unique("testdoc", "f1")); TEST_DO(f.assertAdds({{"testdoc","f1"}})); TEST_DO(f.assertRemoves({})); registrator.reset(); TEST_DO(f.assertAdds({{"testdoc","f1"}})); TEST_DO(f.assertRemoves({{"testdoc",{"f1"}}})); } TEST_F("Test that we can register multiple listeners", Fixture) { auto registrator = f.getRegistrator("testdoc"); TEST_DO(f.assertAdds({})); TEST_DO(f.assertRemoves({})); registrator->addListener(std::make_unique("testdoc", "f1")); registrator->addListener(std::make_unique("testdoc", "f2")); TEST_DO(f.assertAdds({{"testdoc","f1"},{"testdoc","f2"}})); TEST_DO(f.assertRemoves({})); registrator.reset(); TEST_DO(f.assertAdds({{"testdoc","f1"},{"testdoc","f2"}})); TEST_DO(f.assertRemoves({{"testdoc",{"f1","f2"}}})); } } TEST_MAIN() { TEST_RUN_ALL(); }