aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests/proton/reference/gid_to_lid_change_handler/gid_to_lid_change_handler_test.cpp
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@broadpark.no>2020-11-19 12:53:49 +0100
committerTor Egge <Tor.Egge@broadpark.no>2020-11-19 16:39:21 +0100
commit67f83ab6dbf0912cf53885b65991aa63d5a41fcc (patch)
tree3cd9dbe568d77e7ded3d1f3b0f9146320efd0d1b /searchcore/src/tests/proton/reference/gid_to_lid_change_handler/gid_to_lid_change_handler_test.cpp
parent19e2e6fcc911a17041771784f2dfa27b002bb27b (diff)
Delay gid to lid change notifications for put operations.
Diffstat (limited to 'searchcore/src/tests/proton/reference/gid_to_lid_change_handler/gid_to_lid_change_handler_test.cpp')
-rw-r--r--searchcore/src/tests/proton/reference/gid_to_lid_change_handler/gid_to_lid_change_handler_test.cpp91
1 files changed, 37 insertions, 54 deletions
diff --git a/searchcore/src/tests/proton/reference/gid_to_lid_change_handler/gid_to_lid_change_handler_test.cpp b/searchcore/src/tests/proton/reference/gid_to_lid_change_handler/gid_to_lid_change_handler_test.cpp
index a10d48ee7fe..9d72045c918 100644
--- a/searchcore/src/tests/proton/reference/gid_to_lid_change_handler/gid_to_lid_change_handler_test.cpp
+++ b/searchcore/src/tests/proton/reference/gid_to_lid_change_handler/gid_to_lid_change_handler_test.cpp
@@ -6,6 +6,7 @@
#include <vespa/searchcore/proton/server/executor_thread_service.h>
#include <vespa/vespalib/util/lambdatask.h>
#include <vespa/searchcore/proton/reference/i_gid_to_lid_change_listener.h>
+#include <vespa/searchcore/proton/reference/i_pending_gid_to_lid_changes.h>
#include <vespa/searchcore/proton/reference/gid_to_lid_change_handler.h>
#include <vespa/searchlib/common/gatecallback.h>
#include <map>
@@ -112,11 +113,13 @@ public:
struct Fixture
{
std::vector<std::shared_ptr<ListenerStats>> _statss;
- std::shared_ptr<GidToLidChangeHandler> _handler;
+ std::shared_ptr<GidToLidChangeHandler> _real_handler;
+ std::shared_ptr<IGidToLidChangeHandler> _handler;
Fixture()
: _statss(),
- _handler(std::make_shared<GidToLidChangeHandler>())
+ _real_handler(std::make_shared<GidToLidChangeHandler>()),
+ _handler(_real_handler)
{
}
@@ -127,7 +130,7 @@ struct Fixture
void close()
{
- _handler->close();
+ _real_handler->close();
}
ListenerStats &addStats() {
@@ -139,10 +142,15 @@ struct Fixture
_handler->addListener(std::move(listener));
}
- void notifyPutDone(GlobalId gid, uint32_t lid, SerialNum serialNum) {
- vespalib::Gate gate;
- _handler->notifyPutDone(std::make_shared<search::GateCallback>(gate), gid, lid, serialNum);
- gate.await();
+ void commit() {
+ auto pending = _handler->grab_pending_changes();
+ if (pending) {
+ pending->notify_done();
+ }
+ }
+
+ void notifyPut(GlobalId gid, uint32_t lid, SerialNum serial_num) {
+ _handler->notifyPut(std::shared_ptr<search::IDestructorCallback>(), gid, lid, serial_num);
}
void notifyRemove(GlobalId gid, SerialNum serialNum) {
@@ -151,10 +159,6 @@ struct Fixture
gate.await();
}
- void notifyRemoveDone(GlobalId gid, SerialNum serialNum) {
- _handler->notifyRemoveDone(gid, serialNum);
- }
-
void removeListeners(const vespalib::string &docTypeName,
const std::set<vespalib::string> &keepNames) {
_handler->removeListeners(docTypeName, keepNames);
@@ -169,7 +173,8 @@ TEST_F("Test that we can register a listener", Fixture)
TEST_DO(stats.assertListeners(1, 0, 0));
f.addListener(std::move(listener));
TEST_DO(stats.assertListeners(1, 1, 0));
- f.notifyPutDone(toGid(doc1), 10, 10);
+ f.notifyPut(toGid(doc1), 10, 10);
+ f.commit();
TEST_DO(stats.assertChanges(1, 0));
f.removeListeners("testdoc", {});
TEST_DO(stats.assertListeners(1, 1, 1));
@@ -192,7 +197,8 @@ TEST_F("Test that we can register multiple listeners", Fixture)
TEST_DO(stats1.assertListeners(1, 1, 0));
TEST_DO(stats2.assertListeners(1, 1, 0));
TEST_DO(stats3.assertListeners(1, 1, 0));
- f.notifyPutDone(toGid(doc1), 10, 10);
+ f.notifyPut(toGid(doc1), 10, 10);
+ f.commit();
TEST_DO(stats1.assertChanges(1, 0));
TEST_DO(stats2.assertChanges(1, 0));
TEST_DO(stats3.assertChanges(1, 0));
@@ -250,62 +256,39 @@ public:
}
};
-TEST_F("Test that put is ignored if we have a pending remove", StatsFixture)
+TEST_F("Test that multiple puts are processed", StatsFixture)
{
- f.notifyRemove(toGid(doc1), 20);
- TEST_DO(f.assertChanges(0, 1));
- f.notifyPutDone(toGid(doc1), 10, 10);
- TEST_DO(f.assertChanges(0, 1));
- f.notifyRemoveDone(toGid(doc1), 20);
- TEST_DO(f.assertChanges(0, 1));
- f.notifyPutDone(toGid(doc1), 11, 30);
- TEST_DO(f.assertChanges(1, 1));
+ f.notifyPut(toGid(doc1), 10, 10);
+ TEST_DO(f.assertChanges(0, 0));
+ f.notifyPut(toGid(doc1), 11, 20);
+ TEST_DO(f.assertChanges(0, 0));
+ f.commit();
+ TEST_DO(f.assertChanges(2, 0));
}
-TEST_F("Test that pending removes are merged", StatsFixture)
+TEST_F("Test that put is ignored if we have a pending remove", StatsFixture)
{
+ f.notifyPut(toGid(doc1), 10, 10);
+ TEST_DO(f.assertChanges(0, 0));
f.notifyRemove(toGid(doc1), 20);
TEST_DO(f.assertChanges(0, 1));
- f.notifyRemove(toGid(doc1), 40);
+ f.commit();
TEST_DO(f.assertChanges(0, 1));
- f.notifyPutDone(toGid(doc1), 10, 10);
- TEST_DO(f.assertChanges(0, 1));
- f.notifyRemoveDone(toGid(doc1), 20);
- TEST_DO(f.assertChanges(0, 1));
- f.notifyPutDone(toGid(doc1), 11, 30);
- TEST_DO(f.assertChanges(0, 1));
- f.notifyRemoveDone(toGid(doc1), 40);
- TEST_DO(f.assertChanges(0, 1));
- f.notifyPutDone(toGid(doc1), 12, 50);
+ f.notifyPut(toGid(doc1), 11, 30);
+ f.commit();
TEST_DO(f.assertChanges(1, 1));
}
-TEST_F("Test that out of order notifyRemoveDone is handled", StatsFixture)
+TEST_F("Test that pending removes are merged", StatsFixture)
{
- f.notifyRemove(toGid(doc1), 20);
+ f.notifyPut(toGid(doc1), 10, 10);
+ TEST_DO(f.assertChanges(0, 0));
+ f.notifyRemove(toGid(doc1), 20);
TEST_DO(f.assertChanges(0, 1));
f.notifyRemove(toGid(doc1), 40);
TEST_DO(f.assertChanges(0, 1));
- f.notifyRemoveDone(toGid(doc1), 40);
- TEST_DO(f.assertChanges(0, 1));
- f.notifyRemoveDone(toGid(doc1), 20);
+ f.commit();
TEST_DO(f.assertChanges(0, 1));
- f.notifyPutDone(toGid(doc1), 12, 50);
- TEST_DO(f.assertChanges(1, 1));
-}
-
-TEST_F("Test that out of order notifyPutDone is partially handled", StatsFixture)
-{
- f.notifyRemove(toGid(doc1), 20);
- TEST_DO(f.assertChanges(0, 1));
- f.notifyPutDone(toGid(doc1), 12, 50);
- TEST_DO(f.assertChanges(1, 1));
- f.notifyPutDone(toGid(doc1), 11, 40);
- TEST_DO(f.assertChanges(1, 1));
- f.notifyPutDone(toGid(doc1), 13, 55);
- TEST_DO(f.assertChanges(2, 1));
- f.notifyRemoveDone(toGid(doc1), 20);
- TEST_DO(f.assertChanges(2, 1));
}
}