aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/transactionlog/translogclient_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'searchlib/src/tests/transactionlog/translogclient_test.cpp')
-rw-r--r--searchlib/src/tests/transactionlog/translogclient_test.cpp493
1 files changed, 271 insertions, 222 deletions
diff --git a/searchlib/src/tests/transactionlog/translogclient_test.cpp b/searchlib/src/tests/transactionlog/translogclient_test.cpp
index 0dced597917..3c7b412eeaf 100644
--- a/searchlib/src/tests/transactionlog/translogclient_test.cpp
+++ b/searchlib/src/tests/transactionlog/translogclient_test.cpp
@@ -5,7 +5,6 @@
#include <vespa/vespalib/objects/identifiable.h>
#include <vespa/searchlib/index/dummyfileheadercontext.h>
#include <vespa/fastos/file.h>
-#include <map>
#include <vespa/log/log.h>
LOG_SETUP("translogclient_test");
@@ -14,9 +13,24 @@ using namespace search;
using namespace transactionlog;
using namespace document;
using namespace vespalib;
+using namespace std::chrono_literals;
using search::index::DummyFileHeaderContext;
-vespalib::string myhex(const void * b, size_t sz)
+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);
+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 createAndFillDomain(const vespalib::string & name, Encoding encoding, size_t preExistingDomains);
+void verifyDomain(const vespalib::string & name);
+
+vespalib::string
+myhex(const void * b, size_t sz)
{
static const char * hextab="0123456789ABCDEF";
const unsigned char * c = static_cast<const unsigned char *>(b);
@@ -29,35 +43,6 @@ vespalib::string myhex(const void * b, size_t sz)
return s;
}
-class Test : public vespalib::TestApp
-{
-public:
- int Main() override;
-private:
- 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);
- 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);
- bool partialUpdateTest();
- bool testVisitOverGeneratedDomain();
- bool testRemove();
- void createAndFillDomain(const vespalib::string & name, DomainPart::Crc crcMethod, size_t preExistingDomains);
- void verifyDomain(const vespalib::string & name);
- void testCrcVersions();
- bool testVisitOverPreExistingDomain();
- void testMany();
- void testErase();
- void testSync();
- void testTruncateOnShortRead();
- void testTruncateOnVersionMismatch();
-};
-
-TEST_APPHOOK(Test);
-
class CallBackTest : public TransLogClient::Visitor::Callback
{
private:
@@ -75,7 +60,8 @@ public:
bool _eof;
};
-RPC::Result CallBackTest::receive(const Packet & p)
+RPC::Result
+CallBackTest::receive(const Packet & p)
{
nbostream_longlivedbuf h(p.getHandle().data(), p.getHandle().size());
LOG(info,"CallBackTest::receive (%zu, %zu, %zu)(%s)", h.rp(), h.size(), h.capacity(), myhex(h.peek(), h.size()).c_str());
@@ -101,7 +87,8 @@ public:
size_t _value;
};
-RPC::Result CallBackManyTest::receive(const Packet & p)
+RPC::Result
+CallBackManyTest::receive(const Packet & p)
{
nbostream_longlivedbuf h(p.getHandle().data(), p.getHandle().size());
for(;h.size() > 0; _count++, _value++) {
@@ -133,7 +120,8 @@ public:
};
-RPC::Result CallBackUpdate::receive(const Packet & packet)
+RPC::Result
+CallBackUpdate::receive(const Packet & packet)
{
nbostream_longlivedbuf h(packet.getHandle().data(), packet.getHandle().size());
while (h.size() > 0) {
@@ -185,7 +173,8 @@ public:
SerialNum _prevSerial;
};
-RPC::Result CallBackStatsTest::receive(const Packet & p)
+RPC::Result
+CallBackStatsTest::receive(const Packet & p)
{
nbostream_longlivedbuf h(p.getHandle().data(), p.getHandle().size());
for(;h.size() > 0; ++_count) {
@@ -221,67 +210,10 @@ public:
IMPLEMENT_IDENTIFIABLE(TestIdentifiable, Identifiable);
-bool Test::partialUpdateTest()
-{
- bool retval(false);
- DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test7", 18377, ".", fileHeaderContext, 0x10000);
- TransLogClient tls("tcp/localhost:18377");
-
- TransLogClient::Session::UP s1 = openDomainTest(tls, "test1");
- TransLogClient::Session & session = *s1;
-
- TestIdentifiable du;
-
- nbostream os;
- os << du;
-
- vespalib::ConstBufferRef bb(os.data(), os.size());
- LOG(info, "DU : %s", myhex(bb.c_str(), bb.size()).c_str());
- Packet::Entry e(7, du.getClass().id(), bb);
- Packet pa;
- pa.add(e);
- pa.close();
- ASSERT_TRUE(session.commit(vespalib::ConstBufferRef(pa.getHandle().data(), pa.getHandle().size())));
-
- CallBackUpdate ca;
- TransLogClient::Visitor::UP 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); }
- ASSERT_TRUE( ca._eof );
- ASSERT_TRUE( ca.map().size() == 1);
- ASSERT_TRUE( ca.hasSerial(7) );
-
- CallBackUpdate ca1;
- TransLogClient::Visitor::UP 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); }
- ASSERT_TRUE( ca1._eof );
- ASSERT_TRUE( ca1.map().size() == 0);
-
- CallBackUpdate ca2;
- TransLogClient::Visitor::UP 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); }
- ASSERT_TRUE( ca2._eof );
- ASSERT_TRUE( ca2.map().size() == 0);
-
- CallBackUpdate ca3;
- TransLogClient::Visitor::UP 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); }
- ASSERT_TRUE( ca3._eof );
- ASSERT_TRUE( ca3.map().size() == 1);
- ASSERT_TRUE( ca3.hasSerial(7) );
-
- return retval;
-}
+constexpr size_t DEFAULT_PACKET_SIZE = 0xf000;
-bool Test::createDomainTest(TransLogClient & tls, const vespalib::string & name, size_t preExistingDomains)
+bool
+createDomainTest(TransLogClient & tls, const vespalib::string & name, size_t preExistingDomains)
{
bool retval(true);
std::vector<vespalib::string> dir;
@@ -298,43 +230,40 @@ bool Test::createDomainTest(TransLogClient & tls, const vespalib::string & name,
return retval;
}
-TransLogClient::Session::UP Test::openDomainTest(TransLogClient & tls, const vespalib::string & name)
+TransLogClient::Session::UP
+openDomainTest(TransLogClient & tls, const vespalib::string & name)
{
TransLogClient::Session::UP s1 = tls.open(name);
ASSERT_TRUE (s1.get() != NULL);
return s1;
}
-bool Test::fillDomainTest(TransLogClient::Session * s1, const vespalib::string & name)
+bool
+fillDomainTest(TransLogClient::Session * s1, const vespalib::string & name)
{
bool retval(true);
Packet::Entry e1(1, 1, vespalib::ConstBufferRef("Content in buffer A", 20));
Packet::Entry e2(2, 2, vespalib::ConstBufferRef("Content in buffer B", 20));
Packet::Entry e3(3, 1, vespalib::ConstBufferRef("Content in buffer C", 20));
- Packet a;
- ASSERT_TRUE (a.add(e1));
- Packet b;
- ASSERT_TRUE (b.add(e2));
- ASSERT_TRUE (b.add(e3));
- ASSERT_TRUE (!b.add(e1));
- a.close();
- b.close();
+ Packet a(DEFAULT_PACKET_SIZE);
+ a.add(e1);
+ Packet b(DEFAULT_PACKET_SIZE);
+ b.add(e2);
+ b.add(e3);
+ EXPECT_FALSE(b.add(e1));
ASSERT_TRUE (s1->commit(vespalib::ConstBufferRef(a.getHandle().data(), a.getHandle().size())));
ASSERT_TRUE (s1->commit(vespalib::ConstBufferRef(b.getHandle().data(), b.getHandle().size())));
- try {
- s1->commit(vespalib::ConstBufferRef(a.getHandle().data(), a.getHandle().size()));
- ASSERT_TRUE(false);
- } catch (const std::exception & e) {
- EXPECT_EQUAL(vespalib::string("commit failed with code -2. server says: Exception during commit on " + name + " : Incomming serial number(1) must be bigger than the last one (3)."), e.what());
- }
+ EXPECT_EXCEPTION(s1->commit(vespalib::ConstBufferRef(a.getHandle().data(), a.getHandle().size())),
+ std::runtime_error,
+ "commit failed with code -2. server says: Exception during commit on " + name + " : Incomming serial number(1) must be bigger than the last one (3).");
EXPECT_EQUAL(a.size(), 1u);
EXPECT_EQUAL(a.range().from(), 1u);
EXPECT_EQUAL(a.range().to(), 1u);
EXPECT_EQUAL(b.size(), 2u);
EXPECT_EQUAL(b.range().from(), 2u);
EXPECT_EQUAL(b.range().to(), 3u);
- EXPECT_TRUE(a.merge(b));
+ a.merge(b);
EXPECT_EQUAL(a.size(), 3u);
EXPECT_EQUAL(a.range().from(), 1u);
EXPECT_EQUAL(a.range().to(), 3u);
@@ -349,52 +278,82 @@ bool Test::fillDomainTest(TransLogClient::Session * s1, const vespalib::string &
return retval;
}
-void Test::fillDomainTest(TransLogClient::Session * s1, size_t numPackets, size_t numEntries)
+void
+fillDomainTest(TransLogClient::Session * s1, size_t numPackets, size_t numEntries)
{
size_t value(0);
for(size_t i=0; i < numPackets; i++) {
- std::unique_ptr<Packet> p(new Packet());
+ std::unique_ptr<Packet> p(new Packet(DEFAULT_PACKET_SIZE));
for(size_t j=0; j < numEntries; j++, value++) {
Packet::Entry e(value+1, j+1, vespalib::ConstBufferRef((const char *)&value, sizeof(value)));
- if ( ! p->add(e) ) {
- p->close();
+ p->add(e);
+ if (p->sizeBytes() > DEFAULT_PACKET_SIZE){
ASSERT_TRUE(s1->commit(vespalib::ConstBufferRef(p->getHandle().data(), p->getHandle().size())));
- p.reset(new Packet());
- ASSERT_TRUE(p->add(e));
+ p.reset(new Packet(DEFAULT_PACKET_SIZE));
}
}
- p->close();
ASSERT_TRUE(s1->commit(vespalib::ConstBufferRef(p->getHandle().data(), p->getHandle().size())));
}
}
+using Counter = std::atomic<size_t>;
+
+class CountDone : public IDestructorCallback {
+public:
+ CountDone(Counter & inFlight) : _inFlight(inFlight) { ++_inFlight; }
+ ~CountDone() override { --_inFlight; }
+private:
+ Counter & _inFlight;
+};
+
+void
+fillDomainTest(TransLogServer & s1, const vespalib::string & domain, size_t numPackets, size_t numEntries)
+{
+ size_t value(0);
+ Counter inFlight(0);
+ for(size_t i=0; i < numPackets; i++) {
+ std::unique_ptr<Packet> p(new Packet(DEFAULT_PACKET_SIZE));
+ for(size_t j=0; j < numEntries; j++, value++) {
+ Packet::Entry e(value+1, j+1, vespalib::ConstBufferRef((const char *)&value, sizeof(value)));
+ p->add(e);
+ if ( p->sizeBytes() > DEFAULT_PACKET_SIZE ) {
+ s1.commit(domain, *p, std::make_shared<CountDone>(inFlight));
+ p.reset(new Packet(DEFAULT_PACKET_SIZE));
+ }
+ }
+ s1.commit(domain, *p, std::make_shared<CountDone>(inFlight));
+ LOG(info, "Inflight %ld", inFlight.load());
+ }
+ while (inFlight.load() != 0) {
+ std::this_thread::sleep_for(10ms);
+ LOG(info, "Waiting for inflight %ld to reach zero", inFlight.load());
+ }
+
+}
+
void
-Test::fillDomainTest(TransLogClient::Session * s1,
- size_t numPackets, size_t numEntries,
- size_t entrySize)
+fillDomainTest(TransLogClient::Session * s1, size_t numPackets, size_t numEntries, size_t entrySize)
{
size_t value(0);
std::vector<char> entryBuffer(entrySize);
for(size_t i=0; i < numPackets; i++) {
- std::unique_ptr<Packet> p(new Packet());
+ std::unique_ptr<Packet> p(new Packet(DEFAULT_PACKET_SIZE));
for(size_t j=0; j < numEntries; j++, value++) {
Packet::Entry e(value+1, j+1, vespalib::ConstBufferRef((const char *)&entryBuffer[0], entryBuffer.size()));
- if ( ! p->add(e) ) {
- p->close();
+ p->add(e);
+ if (p->sizeBytes() > DEFAULT_PACKET_SIZE){
ASSERT_TRUE(s1->commit(vespalib::ConstBufferRef(p->getHandle().data(), p->getHandle().size())));
- p.reset(new Packet());
- ASSERT_TRUE(p->add(e));
+ p.reset(new Packet(DEFAULT_PACKET_SIZE));
}
}
- p->close();
ASSERT_TRUE(s1->commit(vespalib::ConstBufferRef(p->getHandle().data(), p->getHandle().size())));
}
}
uint32_t
-Test::countFiles(const vespalib::string &dir)
+countFiles(const vespalib::string &dir)
{
uint32_t res = 0;
FastOS_DirectoryScan dirScan(dir.c_str());
@@ -408,10 +367,8 @@ Test::countFiles(const vespalib::string &dir)
return res;
}
-
void
-Test::checkFilledDomainTest(const TransLogClient::Session::UP &s1,
- size_t numEntries)
+checkFilledDomainTest(const TransLogClient::Session::UP &s1, size_t numEntries)
{
SerialNum b(0), e(0);
size_t c(0);
@@ -421,8 +378,8 @@ Test::checkFilledDomainTest(const TransLogClient::Session::UP &s1,
EXPECT_EQUAL(c, numEntries);
}
-
-bool Test::visitDomainTest(TransLogClient & tls, TransLogClient::Session * s1, const vespalib::string & name)
+bool
+visitDomainTest(TransLogClient & tls, TransLogClient::Session * s1, const vespalib::string & name)
{
bool retval(true);
@@ -486,10 +443,31 @@ getMaxSessionRunTime(TransLogServer &tls, const vespalib::string &domain)
return tls.getDomainStats()[domain].maxSessionRunTime.count();
}
-bool Test::testVisitOverGeneratedDomain()
+void createAndFillDomain(const vespalib::string & name, Encoding encoding, size_t preExistingDomains)
{
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test7", 18377, ".", fileHeaderContext, 0x10000);
+ TransLogServer tlss("test13", 18377, ".", fileHeaderContext,
+ DomainConfig().setPartSizeLimit(0x1000000).setEncoding(encoding), 4);
+ TransLogClient tls("tcp/localhost:18377");
+
+ createDomainTest(tls, name, preExistingDomains);
+ TransLogClient::Session::UP s1 = openDomainTest(tls, name);
+ fillDomainTest(s1.get(), name);
+}
+
+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);
+ visitDomainTest(tls, s1.get(), name);
+}
+
+}
+
+TEST("testVisitOverGeneratedDomain") {
+ DummyFileHeaderContext fileHeaderContext;
+ TransLogServer tlss("test7", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000));
TransLogClient tls("tcp/localhost:18377");
vespalib::string name("test1");
@@ -501,42 +479,85 @@ bool Test::testVisitOverGeneratedDomain()
double maxSessionRunTime = getMaxSessionRunTime(tlss, "test1");
LOG(info, "testVisitOverGeneratedDomain(): maxSessionRunTime=%f", maxSessionRunTime);
EXPECT_GREATER(maxSessionRunTime, 0);
- return true;
}
-void Test::createAndFillDomain(const vespalib::string & name, DomainPart::Crc crcMethod, size_t preExistingDomains)
-{
+TEST("testVisitOverPreExistingDomain") {
+ // Depends on Test::testVisitOverGeneratedDomain()
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test13", 18377, ".", fileHeaderContext, 0x10000, 4, crcMethod);
+ TransLogServer tlss("test7", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000));
TransLogClient tls("tcp/localhost:18377");
- createDomainTest(tls, name, preExistingDomains);
+ vespalib::string name("test1");
TransLogClient::Session::UP s1 = openDomainTest(tls, name);
- fillDomainTest(s1.get(), name);
+ visitDomainTest(tls, s1.get(), name);
}
-void Test::verifyDomain(const vespalib::string & name)
-{
+TEST("partialUpdateTest") {
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test13", 18377, ".", fileHeaderContext, 0x10000);
+ TransLogServer tlss("test7", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000));
TransLogClient tls("tcp/localhost:18377");
- TransLogClient::Session::UP s1 = openDomainTest(tls, name);
- visitDomainTest(tls, s1.get(), name);
+
+ TransLogClient::Session::UP s1 = openDomainTest(tls, "test1");
+ TransLogClient::Session & session = *s1;
+
+ TestIdentifiable du;
+
+ nbostream os;
+ os << du;
+
+ vespalib::ConstBufferRef bb(os.data(), os.size());
+ LOG(info, "DU : %s", myhex(bb.c_str(), bb.size()).c_str());
+ Packet::Entry e(7, du.getClass().id(), bb);
+ Packet pa(DEFAULT_PACKET_SIZE);
+ pa.add(e);
+ ASSERT_TRUE(session.commit(vespalib::ConstBufferRef(pa.getHandle().data(), pa.getHandle().size())));
+
+ CallBackUpdate ca;
+ TransLogClient::Visitor::UP 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); }
+ ASSERT_TRUE( ca._eof );
+ ASSERT_TRUE( ca.map().size() == 1);
+ ASSERT_TRUE( ca.hasSerial(7) );
+
+ CallBackUpdate ca1;
+ TransLogClient::Visitor::UP 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); }
+ ASSERT_TRUE( ca1._eof );
+ ASSERT_TRUE( ca1.map().size() == 0);
+
+ CallBackUpdate ca2;
+ TransLogClient::Visitor::UP 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); }
+ ASSERT_TRUE( ca2._eof );
+ ASSERT_TRUE( ca2.map().size() == 0);
+
+ CallBackUpdate ca3;
+ TransLogClient::Visitor::UP 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); }
+ ASSERT_TRUE( ca3._eof );
+ ASSERT_TRUE( ca3.map().size() == 1);
+ ASSERT_TRUE( ca3.hasSerial(7) );
}
-void Test::testCrcVersions()
-{
- createAndFillDomain("ccitt_crc32", DomainPart::ccitt_crc32, 0);
- createAndFillDomain("xxh64", DomainPart::xxh64, 1);
+TEST("testCrcVersions") {
+ createAndFillDomain("ccitt_crc32", Encoding::Crc::ccitt_crc32, 0);
+ createAndFillDomain("xxh64", Encoding::Crc::xxh64, 1);
verifyDomain("ccitt_crc32");
verifyDomain("xxh64");
}
-bool Test::testRemove()
-{
+TEST("testRemove") {
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("testremove", 18377, ".", fileHeaderContext, 0x10000);
+ TransLogServer tlss("testremove", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000));
TransLogClient tls("tcp/localhost:18377");
vespalib::string name("test-delete");
@@ -545,21 +566,6 @@ bool Test::testRemove()
fillDomainTest(s1.get(), name);
visitDomainTest(tls, s1.get(), name);
ASSERT_TRUE(tls.remove(name));
-
- return true;
-}
-
-bool Test::testVisitOverPreExistingDomain()
-{
- // Depends on Test::testVisitOverGeneratedDomain()
- DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test7", 18377, ".", fileHeaderContext, 0x10000);
- TransLogClient tls("tcp/localhost:18377");
-
- vespalib::string name("test1");
- TransLogClient::Session::UP s1 = openDomainTest(tls, name);
- visitDomainTest(tls, s1.get(), name);
- return true;
}
namespace {
@@ -600,18 +606,19 @@ assertStatus(TransLogClient::Session &s,
}
-void Test::testMany()
-{
+TEST("test sending a lot of data") {
const unsigned int NUM_PACKETS = 1000;
const unsigned int NUM_ENTRIES = 100;
const unsigned int TOTAL_NUM_ENTRIES = NUM_PACKETS * NUM_ENTRIES;
+ const vespalib::string MANY("many");
{
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test8", 18377, ".", fileHeaderContext, 0x80000);
+ TransLogServer tlss("test8", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x80000)
+ .setChunkAgeLimit(100us));
TransLogClient tls("tcp/localhost:18377");
- createDomainTest(tls, "many", 0);
- TransLogClient::Session::UP s1 = openDomainTest(tls, "many");
+ createDomainTest(tls, MANY, 0);
+ TransLogClient::Session::UP s1 = openDomainTest(tls, MANY);
fillDomainTest(s1.get(), NUM_PACKETS, NUM_ENTRIES);
SerialNum b(0), e(0);
size_t c(0);
@@ -630,7 +637,7 @@ void Test::testMany()
}
{
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test8", 18377, ".", fileHeaderContext, 0x1000000);
+ TransLogServer tlss("test8", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000));
TransLogClient tls("tcp/localhost:18377");
TransLogClient::Session::UP s1 = openDomainTest(tls, "many");
@@ -641,7 +648,28 @@ void Test::testMany()
EXPECT_EQUAL(e, TOTAL_NUM_ENTRIES);
EXPECT_EQUAL(c, TOTAL_NUM_ENTRIES);
CallBackManyTest ca(2);
- TransLogClient::Visitor::UP visitor = tls.createVisitor("many", ca);
+ TransLogClient::Visitor::UP 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); }
+ ASSERT_TRUE( ca._eof );
+ EXPECT_EQUAL(ca._count, TOTAL_NUM_ENTRIES);
+ EXPECT_EQUAL(ca._value, TOTAL_NUM_ENTRIES);
+ }
+ {
+ DummyFileHeaderContext fileHeaderContext;
+ TransLogServer tlss("test8", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000));
+ TransLogClient tls("tcp/localhost:18377");
+
+ TransLogClient::Session::UP s1 = openDomainTest(tls, MANY);
+ SerialNum b(0), e(0);
+ size_t c(0);
+ EXPECT_TRUE(s1->status(b, e, c));
+ EXPECT_EQUAL(b, 1u);
+ EXPECT_EQUAL(e, TOTAL_NUM_ENTRIES);
+ EXPECT_EQUAL(c, TOTAL_NUM_ENTRIES);
+ CallBackManyTest ca(2);
+ TransLogClient::Visitor::UP 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); }
@@ -651,14 +679,67 @@ void Test::testMany()
}
}
-void Test::testErase()
-{
+TEST("test sending a lot of data async") {
const unsigned int NUM_PACKETS = 1000;
const unsigned int NUM_ENTRIES = 100;
const unsigned int TOTAL_NUM_ENTRIES = NUM_PACKETS * NUM_ENTRIES;
+ const vespalib::string MANY("many-async");
+ {
+ DummyFileHeaderContext fileHeaderContext;
+ TransLogServer tlss("test8", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x80000)
+ .setChunkAgeLimit(10ms));
+ TransLogClient tls("tcp/localhost:18377");
+ createDomainTest(tls, MANY, 1);
+ TransLogClient::Session::UP s1 = openDomainTest(tls, MANY);
+ fillDomainTest(tlss, MANY, NUM_PACKETS, NUM_ENTRIES);
+ SerialNum b(0), e(0);
+ size_t c(0);
+ EXPECT_TRUE(s1->status(b, e, c));
+
+ EXPECT_EQUAL(e, TOTAL_NUM_ENTRIES);
+ EXPECT_EQUAL(c, TOTAL_NUM_ENTRIES);
+ CallBackManyTest ca(2);
+ TransLogClient::Visitor::UP 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); }
+ ASSERT_TRUE( ca._eof );
+ EXPECT_EQUAL(ca._count, TOTAL_NUM_ENTRIES);
+ EXPECT_EQUAL(ca._value, TOTAL_NUM_ENTRIES);
+ }
{
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test12", 18377, ".", fileHeaderContext, 0x80000);
+ TransLogServer tlss("test8", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000));
+ TransLogClient tls("tcp/localhost:18377");
+
+ TransLogClient::Session::UP s1 = openDomainTest(tls, MANY);
+ SerialNum b(0), e(0);
+ size_t c(0);
+ EXPECT_TRUE(s1->status(b, e, c));
+ EXPECT_EQUAL(b, 1u);
+ EXPECT_EQUAL(e, TOTAL_NUM_ENTRIES);
+ EXPECT_EQUAL(c, TOTAL_NUM_ENTRIES);
+ CallBackManyTest ca(2);
+ TransLogClient::Visitor::UP 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); }
+ ASSERT_TRUE( ca._eof );
+ EXPECT_EQUAL(ca._count, TOTAL_NUM_ENTRIES);
+ EXPECT_EQUAL(ca._value, TOTAL_NUM_ENTRIES);
+ }
+}
+
+
+
+
+TEST("testErase") {
+ const unsigned int NUM_PACKETS = 1000;
+ const unsigned int NUM_ENTRIES = 100;
+ const unsigned int TOTAL_NUM_ENTRIES = NUM_PACKETS * NUM_ENTRIES;
+ {
+ DummyFileHeaderContext fileHeaderContext;
+ TransLogServer tlss("test12", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x80000));
TransLogClient tls("tcp/localhost:18377");
createDomainTest(tls, "erase", 0);
@@ -667,7 +748,7 @@ void Test::testErase()
}
{
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test12", 18377, ".", fileHeaderContext, 0x1000000);
+ TransLogServer tlss("test12", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000));
TransLogClient tls("tcp/localhost:18377");
TransLogClient::Session::UP s1 = openDomainTest(tls, "erase");
@@ -748,16 +829,13 @@ void Test::testErase()
}
}
-
-void
-Test::testSync()
-{
+TEST("testSync") {
const unsigned int NUM_PACKETS = 3;
const unsigned int NUM_ENTRIES = 4;
const unsigned int TOTAL_NUM_ENTRIES = NUM_PACKETS * NUM_ENTRIES;
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test9", 18377, ".", fileHeaderContext, 0x1000000);
+ TransLogServer tlss("test9", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000));
TransLogClient tls("tcp/localhost:18377");
createDomainTest(tls, "sync", 0);
@@ -770,10 +848,7 @@ Test::testSync()
EXPECT_EQUAL(syncedTo, TOTAL_NUM_ENTRIES);
}
-
-void
-Test::testTruncateOnVersionMismatch()
-{
+TEST("test truncate on version mismatch") {
const unsigned int NUM_PACKETS = 3;
const unsigned int NUM_ENTRIES = 4;
const unsigned int TOTAL_NUM_ENTRIES = NUM_PACKETS * NUM_ENTRIES;
@@ -782,7 +857,7 @@ Test::testTruncateOnVersionMismatch()
size_t countOld(0);
DummyFileHeaderContext fileHeaderContext;
{
- TransLogServer tlss("test11", 18377, ".", fileHeaderContext, 0x1000000);
+ TransLogServer tlss("test11", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000));
TransLogClient tls("tcp/localhost:18377");
createDomainTest(tls, "sync", 0);
@@ -803,7 +878,7 @@ Test::testTruncateOnVersionMismatch()
EXPECT_EQUAL(static_cast<ssize_t>(sizeof(tmp)), f.Write2(tmp, sizeof(tmp)));
EXPECT_TRUE(f.Close());
{
- TransLogServer tlss("test11", 18377, ".", fileHeaderContext, 0x1000000);
+ TransLogServer tlss("test11", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000));
TransLogClient tls("tcp/localhost:18377");
TransLogClient::Session::UP s1 = openDomainTest(tls, "sync");
uint64_t from(0), to(0);
@@ -815,9 +890,7 @@ Test::testTruncateOnVersionMismatch()
}
}
-void
-Test::testTruncateOnShortRead()
-{
+TEST("test truncation after short read") {
const unsigned int NUM_PACKETS = 17;
const unsigned int NUM_ENTRIES = 1;
const unsigned int TOTAL_NUM_ENTRIES = NUM_PACKETS * NUM_ENTRIES;
@@ -829,7 +902,7 @@ Test::testTruncateOnShortRead()
DummyFileHeaderContext fileHeaderContext;
{
- TransLogServer tlss(topdir, 18377, ".", fileHeaderContext, 0x10000);
+ TransLogServer tlss(topdir, 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000));
TransLogClient tls(tlsspec);
createDomainTest(tls, domain, 0);
@@ -845,7 +918,7 @@ Test::testTruncateOnShortRead()
EXPECT_EQUAL(2u, countFiles(dir));
}
{
- TransLogServer tlss(topdir, 18377, ".", fileHeaderContext, 0x10000);
+ TransLogServer tlss(topdir, 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000));
TransLogClient tls(tlsspec);
TransLogClient::Session::UP s1 = openDomainTest(tls, domain);
checkFilledDomainTest(s1, TOTAL_NUM_ENTRIES);
@@ -861,7 +934,7 @@ Test::testTruncateOnShortRead()
trfile.Close();
}
{
- TransLogServer tlss(topdir, 18377, ".", fileHeaderContext, 0x10000);
+ TransLogServer tlss(topdir, 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000));
TransLogClient tls(tlsspec);
TransLogClient::Session::UP s1 = openDomainTest(tls, domain);
checkFilledDomainTest(s1, TOTAL_NUM_ENTRIES - 1);
@@ -871,28 +944,4 @@ Test::testTruncateOnShortRead()
}
}
-
-int Test::Main()
-{
- TEST_INIT("translogclient_test");
-
- if (_argc > 0) {
- DummyFileHeaderContext::setCreator(_argv[0]);
- }
- testVisitOverGeneratedDomain();
- testVisitOverPreExistingDomain();
- testMany();
- testErase();
- partialUpdateTest();
-
- testRemove();
-
- testSync();
-
- testTruncateOnShortRead();
- testTruncateOnVersionMismatch();
-
- testCrcVersions();
-
- TEST_DONE();
-}
+TEST_MAIN() { TEST_RUN_ALL(); }