summaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/transactionlog
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-09-15 11:32:16 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-09-15 11:33:09 +0000
commitaf3f5cd865a24507271c1525c61fc97119a1ce83 (patch)
treee20169f10c1a2c1ecd6e655e309f8d9db403c58a /searchlib/src/tests/transactionlog
parentf500f24745747137bad942c0c8c40db56be6c49e (diff)
Decouple code and reduce code visibility.
Diffstat (limited to 'searchlib/src/tests/transactionlog')
-rw-r--r--searchlib/src/tests/transactionlog/translogclient_test.cpp116
1 files changed, 61 insertions, 55 deletions
diff --git a/searchlib/src/tests/transactionlog/translogclient_test.cpp b/searchlib/src/tests/transactionlog/translogclient_test.cpp
index a20e0cc3aaa..e6cf44cb697 100644
--- a/searchlib/src/tests/transactionlog/translogclient_test.cpp
+++ b/searchlib/src/tests/transactionlog/translogclient_test.cpp
@@ -4,6 +4,7 @@
#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/vespalib/objects/identifiable.h>
#include <vespa/searchlib/index/dummyfileheadercontext.h>
+#include <vespa/document/util/bytebuffer.h>
#include <vespa/fastos/file.h>
#include <vespa/log/log.h>
@@ -15,17 +16,24 @@ using namespace document;
using namespace vespalib;
using namespace std::chrono_literals;
using search::index::DummyFileHeaderContext;
+using search::transactionlog::client::TransLogClient;
+using search::transactionlog::client::Session;
+using search::transactionlog::client::Visitor;
+using search::transactionlog::client::RPC;
+using search::transactionlog::client::Callback;
+using SessionUP = std::unique_ptr<Session>;
+using VisitorUP = std::unique_ptr<Visitor>;
namespace {
bool createDomainTest(TransLogClient & tls, const vespalib::string & name, size_t preExistingDomains=0);
-TransLogClient::Session::UP openDomainTest(TransLogClient & tls, const vespalib::string & name);
-bool fillDomainTest(TransLogClient::Session * s1, const vespalib::string & name);
-void fillDomainTest(TransLogClient::Session * s1, size_t numPackets, size_t numEntries);
-void fillDomainTest(TransLogClient::Session * s1, size_t numPackets, size_t numEntries, size_t entrySize);
+SessionUP openDomainTest(TransLogClient & tls, const vespalib::string & name);
+bool fillDomainTest(Session * s1, const vespalib::string & name);
+void fillDomainTest(Session * s1, size_t numPackets, size_t numEntries);
+void fillDomainTest(Session * s1, size_t numPackets, size_t numEntries, size_t entrySize);
uint32_t countFiles(const vespalib::string &dir);
-void checkFilledDomainTest(const TransLogClient::Session::UP &s1, size_t numEntries);
-bool visitDomainTest(TransLogClient & tls, TransLogClient::Session * s1, const vespalib::string & name);
+void checkFilledDomainTest(const SessionUP &s1, size_t numEntries);
+bool visitDomainTest(TransLogClient & tls, Session * s1, const vespalib::string & name);
void createAndFillDomain(const vespalib::string & name, Encoding encoding, size_t preExistingDomains);
void verifyDomain(const vespalib::string & name);
@@ -43,7 +51,7 @@ myhex(const void * b, size_t sz)
return s;
}
-class CallBackTest : public TransLogClient::Visitor::Callback
+class CallBackTest : public Callback
{
private:
virtual RPC::Result receive(const Packet & packet) override;
@@ -74,7 +82,7 @@ CallBackTest::receive(const Packet & p)
return RPC::OK;
}
-class CallBackManyTest : public TransLogClient::Visitor::Callback
+class CallBackManyTest : public Callback
{
private:
virtual RPC::Result receive(const Packet & packet) override;
@@ -103,7 +111,7 @@ CallBackManyTest::receive(const Packet & p)
return RPC::OK;
}
-class CallBackUpdate : public TransLogClient::Visitor::Callback
+class CallBackUpdate : public Callback
{
public:
typedef std::map<SerialNum, Identifiable *> PacketMap;
@@ -153,7 +161,7 @@ CallBackUpdate::receive(const Packet & packet)
return RPC::OK;
}
-class CallBackStatsTest : public TransLogClient::Session::Callback
+class CallBackStatsTest : public Callback
{
private:
virtual RPC::Result receive(const Packet & packet) override;
@@ -219,8 +227,8 @@ createDomainTest(TransLogClient & tls, const vespalib::string & name, size_t pre
std::vector<vespalib::string> dir;
tls.listDomains(dir);
EXPECT_EQUAL (dir.size(), preExistingDomains);
- TransLogClient::Session::UP s1 = tls.open(name);
- ASSERT_TRUE (s1.get() == NULL);
+ SessionUP s1 = tls.open(name);
+ ASSERT_FALSE (s1);
retval = tls.create(name);
ASSERT_TRUE (retval);
dir.clear();
@@ -230,16 +238,16 @@ createDomainTest(TransLogClient & tls, const vespalib::string & name, size_t pre
return retval;
}
-TransLogClient::Session::UP
+SessionUP
openDomainTest(TransLogClient & tls, const vespalib::string & name)
{
- TransLogClient::Session::UP s1 = tls.open(name);
- ASSERT_TRUE (s1.get() != NULL);
+ SessionUP s1 = tls.open(name);
+ ASSERT_TRUE (s1);
return s1;
}
bool
-fillDomainTest(TransLogClient::Session * s1, const vespalib::string & name)
+fillDomainTest(Session * s1, const vespalib::string & name)
{
bool retval(true);
Packet::Entry e1(1, 1, vespalib::ConstBufferRef("Content in buffer A", 20));
@@ -279,7 +287,7 @@ fillDomainTest(TransLogClient::Session * s1, const vespalib::string & name)
}
void
-fillDomainTest(TransLogClient::Session * s1, size_t numPackets, size_t numEntries)
+fillDomainTest(Session * s1, size_t numPackets, size_t numEntries)
{
size_t value(0);
for(size_t i=0; i < numPackets; i++) {
@@ -333,7 +341,7 @@ fillDomainTest(TransLogServer & s1, const vespalib::string & domain, size_t numP
void
-fillDomainTest(TransLogClient::Session * s1, size_t numPackets, size_t numEntries, size_t entrySize)
+fillDomainTest(Session * s1, size_t numPackets, size_t numEntries, size_t entrySize)
{
size_t value(0);
std::vector<char> entryBuffer(entrySize);
@@ -368,7 +376,7 @@ countFiles(const vespalib::string &dir)
}
void
-checkFilledDomainTest(const TransLogClient::Session::UP &s1, size_t numEntries)
+checkFilledDomainTest(const SessionUP &s1, size_t numEntries)
{
SerialNum b(0), e(0);
size_t c(0);
@@ -379,7 +387,7 @@ checkFilledDomainTest(const TransLogClient::Session::UP &s1, size_t numEntries)
}
bool
-visitDomainTest(TransLogClient & tls, TransLogClient::Session * s1, const vespalib::string & name)
+visitDomainTest(TransLogClient & tls, Session * s1, const vespalib::string & name)
{
bool retval(true);
@@ -391,7 +399,7 @@ visitDomainTest(TransLogClient & tls, TransLogClient::Session * s1, const vespal
EXPECT_EQUAL(c, 3u);
CallBackTest ca;
- TransLogClient::Visitor::UP visitor = tls.createVisitor(name, ca);
+ VisitorUP visitor = tls.createVisitor(name, ca);
ASSERT_TRUE(visitor.get());
EXPECT_TRUE( visitor->visit(0, 1) );
for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); }
@@ -451,7 +459,7 @@ void createAndFillDomain(const vespalib::string & name, Encoding encoding, size_
TransLogClient tls("tcp/localhost:18377");
createDomainTest(tls, name, preExistingDomains);
- TransLogClient::Session::UP s1 = openDomainTest(tls, name);
+ SessionUP s1 = openDomainTest(tls, name);
fillDomainTest(s1.get(), name);
}
@@ -459,7 +467,7 @@ void verifyDomain(const vespalib::string & name) {
DummyFileHeaderContext fileHeaderContext;
TransLogServer tlss("test13", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000));
TransLogClient tls("tcp/localhost:18377");
- TransLogClient::Session::UP s1 = openDomainTest(tls, name);
+ SessionUP s1 = openDomainTest(tls, name);
visitDomainTest(tls, s1.get(), name);
}
@@ -472,7 +480,7 @@ TEST("testVisitOverGeneratedDomain") {
vespalib::string name("test1");
createDomainTest(tls, name);
- TransLogClient::Session::UP s1 = openDomainTest(tls, name);
+ SessionUP s1 = openDomainTest(tls, name);
fillDomainTest(s1.get(), name);
EXPECT_EQUAL(0, getMaxSessionRunTime(tlss, "test1"));
visitDomainTest(tls, s1.get(), name);
@@ -488,7 +496,7 @@ TEST("testVisitOverPreExistingDomain") {
TransLogClient tls("tcp/localhost:18377");
vespalib::string name("test1");
- TransLogClient::Session::UP s1 = openDomainTest(tls, name);
+ SessionUP s1 = openDomainTest(tls, name);
visitDomainTest(tls, s1.get(), name);
}
@@ -497,8 +505,8 @@ TEST("partialUpdateTest") {
TransLogServer tlss("test7", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000));
TransLogClient tls("tcp/localhost:18377");
- TransLogClient::Session::UP s1 = openDomainTest(tls, "test1");
- TransLogClient::Session & session = *s1;
+ SessionUP s1 = openDomainTest(tls, "test1");
+ Session & session = *s1;
TestIdentifiable du;
@@ -513,7 +521,7 @@ TEST("partialUpdateTest") {
ASSERT_TRUE(session.commit(vespalib::ConstBufferRef(pa.getHandle().data(), pa.getHandle().size())));
CallBackUpdate ca;
- TransLogClient::Visitor::UP visitor = tls.createVisitor("test1", ca);
+ VisitorUP visitor = tls.createVisitor("test1", ca);
ASSERT_TRUE(visitor.get());
ASSERT_TRUE( visitor->visit(5, 7) );
for (size_t i(0); ! ca._eof && (i < 1000); i++ ) { std::this_thread::sleep_for(10ms); }
@@ -522,7 +530,7 @@ TEST("partialUpdateTest") {
ASSERT_TRUE( ca.hasSerial(7) );
CallBackUpdate ca1;
- TransLogClient::Visitor::UP visitor1 = tls.createVisitor("test1", ca1);
+ VisitorUP visitor1 = tls.createVisitor("test1", ca1);
ASSERT_TRUE(visitor1.get());
ASSERT_TRUE( visitor1->visit(4, 5) );
for (size_t i(0); ! ca1._eof && (i < 1000); i++ ) { std::this_thread::sleep_for(10ms); }
@@ -530,7 +538,7 @@ TEST("partialUpdateTest") {
ASSERT_TRUE( ca1.map().size() == 0);
CallBackUpdate ca2;
- TransLogClient::Visitor::UP visitor2 = tls.createVisitor("test1", ca2);
+ VisitorUP visitor2 = tls.createVisitor("test1", ca2);
ASSERT_TRUE(visitor2.get());
ASSERT_TRUE( visitor2->visit(5, 6) );
for (size_t i(0); ! ca2._eof && (i < 1000); i++ ) { std::this_thread::sleep_for(10ms); }
@@ -538,7 +546,7 @@ TEST("partialUpdateTest") {
ASSERT_TRUE( ca2.map().size() == 0);
CallBackUpdate ca3;
- TransLogClient::Visitor::UP visitor3 = tls.createVisitor("test1", ca3);
+ VisitorUP visitor3 = tls.createVisitor("test1", ca3);
ASSERT_TRUE(visitor3.get());
ASSERT_TRUE( visitor3->visit(5, 1000) );
for (size_t i(0); ! ca3._eof && (i < 1000); i++ ) { std::this_thread::sleep_for(10ms); }
@@ -562,7 +570,7 @@ TEST("testRemove") {
vespalib::string name("test-delete");
createDomainTest(tls, name);
- TransLogClient::Session::UP s1 = openDomainTest(tls, name);
+ SessionUP s1 = openDomainTest(tls, name);
fillDomainTest(s1.get(), name);
visitDomainTest(tls, s1.get(), name);
ASSERT_TRUE(tls.remove(name));
@@ -577,7 +585,7 @@ assertVisitStats(TransLogClient &tls, const vespalib::string &domain,
uint64_t expCount, uint64_t expInOrder)
{
CallBackStatsTest ca;
- TransLogClient::Visitor::UP visitor = tls.createVisitor(domain, ca);
+ VisitorUP visitor = tls.createVisitor(domain, ca);
ASSERT_TRUE(visitor.get());
ASSERT_TRUE( visitor->visit(visitStart, visitEnd) );
for (size_t i(0); ! ca._eof && (i < 60000); i++ ) {
@@ -591,9 +599,7 @@ assertVisitStats(TransLogClient &tls, const vespalib::string &domain,
}
void
-assertStatus(TransLogClient::Session &s,
- SerialNum expFirstSerial, SerialNum expLastSerial,
- uint64_t expCount)
+assertStatus(Session &s, SerialNum expFirstSerial, SerialNum expLastSerial, uint64_t expCount)
{
SerialNum b(0), e(0);
size_t c(0);
@@ -618,7 +624,7 @@ TEST("test sending a lot of data") {
TransLogClient tls("tcp/localhost:18377");
createDomainTest(tls, MANY, 0);
- TransLogClient::Session::UP s1 = openDomainTest(tls, MANY);
+ SessionUP s1 = openDomainTest(tls, MANY);
fillDomainTest(s1.get(), NUM_PACKETS, NUM_ENTRIES);
SerialNum b(0), e(0);
size_t c(0);
@@ -627,7 +633,7 @@ TEST("test sending a lot of data") {
EXPECT_EQUAL(e, TOTAL_NUM_ENTRIES);
EXPECT_EQUAL(c, TOTAL_NUM_ENTRIES);
CallBackManyTest ca(2);
- TransLogClient::Visitor::UP visitor = tls.createVisitor("many", ca);
+ VisitorUP visitor = tls.createVisitor("many", ca);
ASSERT_TRUE(visitor.get());
ASSERT_TRUE( visitor->visit(2, TOTAL_NUM_ENTRIES) );
for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); }
@@ -640,7 +646,7 @@ TEST("test sending a lot of data") {
TransLogServer tlss("test8", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000));
TransLogClient tls("tcp/localhost:18377");
- TransLogClient::Session::UP s1 = openDomainTest(tls, "many");
+ SessionUP s1 = openDomainTest(tls, "many");
SerialNum b(0), e(0);
size_t c(0);
EXPECT_TRUE(s1->status(b, e, c));
@@ -648,7 +654,7 @@ TEST("test sending a lot of data") {
EXPECT_EQUAL(e, TOTAL_NUM_ENTRIES);
EXPECT_EQUAL(c, TOTAL_NUM_ENTRIES);
CallBackManyTest ca(2);
- TransLogClient::Visitor::UP visitor = tls.createVisitor(MANY, ca);
+ VisitorUP visitor = tls.createVisitor(MANY, ca);
ASSERT_TRUE(visitor.get());
ASSERT_TRUE( visitor->visit(2, TOTAL_NUM_ENTRIES) );
for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); }
@@ -661,7 +667,7 @@ TEST("test sending a lot of data") {
TransLogServer tlss("test8", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000));
TransLogClient tls("tcp/localhost:18377");
- TransLogClient::Session::UP s1 = openDomainTest(tls, MANY);
+ SessionUP s1 = openDomainTest(tls, MANY);
SerialNum b(0), e(0);
size_t c(0);
EXPECT_TRUE(s1->status(b, e, c));
@@ -669,7 +675,7 @@ TEST("test sending a lot of data") {
EXPECT_EQUAL(e, TOTAL_NUM_ENTRIES);
EXPECT_EQUAL(c, TOTAL_NUM_ENTRIES);
CallBackManyTest ca(2);
- TransLogClient::Visitor::UP visitor = tls.createVisitor(MANY, ca);
+ VisitorUP visitor = tls.createVisitor(MANY, ca);
ASSERT_TRUE(visitor.get());
ASSERT_TRUE( visitor->visit(2, TOTAL_NUM_ENTRIES) );
for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); }
@@ -690,7 +696,7 @@ TEST("test sending a lot of data async") {
.setChunkAgeLimit(10ms));
TransLogClient tls("tcp/localhost:18377");
createDomainTest(tls, MANY, 1);
- TransLogClient::Session::UP s1 = openDomainTest(tls, MANY);
+ SessionUP s1 = openDomainTest(tls, MANY);
fillDomainTest(tlss, MANY, NUM_PACKETS, NUM_ENTRIES);
SerialNum b(0), e(0);
size_t c(0);
@@ -699,7 +705,7 @@ TEST("test sending a lot of data async") {
EXPECT_EQUAL(e, TOTAL_NUM_ENTRIES);
EXPECT_EQUAL(c, TOTAL_NUM_ENTRIES);
CallBackManyTest ca(2);
- TransLogClient::Visitor::UP visitor = tls.createVisitor(MANY, ca);
+ VisitorUP visitor = tls.createVisitor(MANY, ca);
ASSERT_TRUE(visitor.get());
ASSERT_TRUE( visitor->visit(2, TOTAL_NUM_ENTRIES) );
for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); }
@@ -712,7 +718,7 @@ TEST("test sending a lot of data async") {
TransLogServer tlss("test8", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000));
TransLogClient tls("tcp/localhost:18377");
- TransLogClient::Session::UP s1 = openDomainTest(tls, MANY);
+ SessionUP s1 = openDomainTest(tls, MANY);
SerialNum b(0), e(0);
size_t c(0);
EXPECT_TRUE(s1->status(b, e, c));
@@ -720,7 +726,7 @@ TEST("test sending a lot of data async") {
EXPECT_EQUAL(e, TOTAL_NUM_ENTRIES);
EXPECT_EQUAL(c, TOTAL_NUM_ENTRIES);
CallBackManyTest ca(2);
- TransLogClient::Visitor::UP visitor = tls.createVisitor(MANY, ca);
+ VisitorUP visitor = tls.createVisitor(MANY, ca);
ASSERT_TRUE(visitor.get());
ASSERT_TRUE( visitor->visit(2, TOTAL_NUM_ENTRIES) );
for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); }
@@ -743,7 +749,7 @@ TEST("testErase") {
TransLogClient tls("tcp/localhost:18377");
createDomainTest(tls, "erase", 0);
- TransLogClient::Session::UP s1 = openDomainTest(tls, "erase");
+ SessionUP s1 = openDomainTest(tls, "erase");
fillDomainTest(s1.get(), NUM_PACKETS, NUM_ENTRIES);
}
{
@@ -751,7 +757,7 @@ TEST("testErase") {
TransLogServer tlss("test12", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000));
TransLogClient tls("tcp/localhost:18377");
- TransLogClient::Session::UP s1 = openDomainTest(tls, "erase");
+ SessionUP s1 = openDomainTest(tls, "erase");
// Before erase
TEST_DO(assertVisitStats(tls, "erase", 2, TOTAL_NUM_ENTRIES,
@@ -839,7 +845,7 @@ TEST("testSync") {
TransLogClient tls("tcp/localhost:18377");
createDomainTest(tls, "sync", 0);
- TransLogClient::Session::UP s1 = openDomainTest(tls, "sync");
+ SessionUP s1 = openDomainTest(tls, "sync");
fillDomainTest(s1.get(), NUM_PACKETS, NUM_ENTRIES);
SerialNum syncedTo(0);
@@ -861,7 +867,7 @@ TEST("test truncate on version mismatch") {
TransLogClient tls("tcp/localhost:18377");
createDomainTest(tls, "sync", 0);
- TransLogClient::Session::UP s1 = openDomainTest(tls, "sync");
+ SessionUP s1 = openDomainTest(tls, "sync");
fillDomainTest(s1.get(), NUM_PACKETS, NUM_ENTRIES);
EXPECT_TRUE(s1->status(fromOld, toOld, countOld));
SerialNum syncedTo(0);
@@ -880,7 +886,7 @@ TEST("test truncate on version mismatch") {
{
TransLogServer tlss("test11", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000));
TransLogClient tls("tcp/localhost:18377");
- TransLogClient::Session::UP s1 = openDomainTest(tls, "sync");
+ SessionUP s1 = openDomainTest(tls, "sync");
uint64_t from(0), to(0);
size_t count(0);
EXPECT_TRUE(s1->status(from, to, count));
@@ -906,7 +912,7 @@ TEST("test truncation after short read") {
TransLogClient tls(tlsspec);
createDomainTest(tls, domain, 0);
- TransLogClient::Session::UP s1 = openDomainTest(tls, domain);
+ SessionUP s1 = openDomainTest(tls, domain);
fillDomainTest(s1.get(), NUM_PACKETS, NUM_ENTRIES, ENTRYSIZE);
SerialNum syncedTo(0);
@@ -920,7 +926,7 @@ TEST("test truncation after short read") {
{
TransLogServer tlss(topdir, 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000));
TransLogClient tls(tlsspec);
- TransLogClient::Session::UP s1 = openDomainTest(tls, domain);
+ SessionUP s1 = openDomainTest(tls, domain);
checkFilledDomainTest(s1, TOTAL_NUM_ENTRIES);
}
{
@@ -929,14 +935,14 @@ TEST("test truncation after short read") {
{
vespalib::string filename(dir + "/truncate-0000000000000017");
FastOS_File trfile(filename.c_str());
- EXPECT_TRUE(trfile.OpenReadWrite(NULL));
+ EXPECT_TRUE(trfile.OpenReadWrite(nullptr));
trfile.SetSize(trfile.getSize() - 1);
trfile.Close();
}
{
TransLogServer tlss(topdir, 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000));
TransLogClient tls(tlsspec);
- TransLogClient::Session::UP s1 = openDomainTest(tls, domain);
+ SessionUP s1 = openDomainTest(tls, domain);
checkFilledDomainTest(s1, TOTAL_NUM_ENTRIES - 1);
}
{