summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-12-06 11:18:14 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-12-06 11:18:14 +0000
commit005413e8664f0f59fc60599cee34355a8324af8f (patch)
tree715e87f93c3fa9a314da65a1dfb1d798fef067ed /searchlib
parenta204a7f1938031e0e44114e744c76f2e5bdeca0e (diff)
Make tests selfcontained avoiding av enxtra cleanup step in a script.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/transactionlog/CMakeLists.txt3
-rw-r--r--searchlib/src/tests/transactionlog/translogclient_test.cpp101
-rwxr-xr-xsearchlib/src/tests/transactionlog/translogclient_test.sh6
3 files changed, 65 insertions, 45 deletions
diff --git a/searchlib/src/tests/transactionlog/CMakeLists.txt b/searchlib/src/tests/transactionlog/CMakeLists.txt
index b09271eefe2..0904dc3ee36 100644
--- a/searchlib/src/tests/transactionlog/CMakeLists.txt
+++ b/searchlib/src/tests/transactionlog/CMakeLists.txt
@@ -5,8 +5,7 @@ vespa_add_executable(searchlib_translogclient_test_app TEST
DEPENDS
searchlib
)
-vespa_add_test(NAME searchlib_translogclient_test_app COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/translogclient_test.sh
- DEPENDS searchlib_translogclient_test_app COST 100)
+vespa_add_test(NAME searchlib_translogclient_test_app COMMAND searchlib_translogclient_test_app)
vespa_add_executable(searchlib_translog_chunks_test_app TEST
SOURCES
diff --git a/searchlib/src/tests/transactionlog/translogclient_test.cpp b/searchlib/src/tests/transactionlog/translogclient_test.cpp
index de8f9e5c462..5740eeb610d 100644
--- a/searchlib/src/tests/transactionlog/translogclient_test.cpp
+++ b/searchlib/src/tests/transactionlog/translogclient_test.cpp
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/searchlib/transactionlog/translogclient.h>
#include <vespa/searchlib/transactionlog/translogserver.h>
+#include <vespa/searchlib/test/directory_handler.h>
#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/vespalib/objects/identifiable.h>
#include <vespa/searchlib/index/dummyfileheadercontext.h>
@@ -34,8 +35,8 @@ void fillDomainTest(Session * s1, size_t numPackets, size_t numEntries, size_t e
uint32_t countFiles(const vespalib::string &dir);
void checkFilledDomainTest(Session &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);
+void createAndFillDomain(const vespalib::string & dir, const vespalib::string & name, Encoding encoding, size_t preExistingDomains);
+void verifyDomain(const vespalib::string & dir, const vespalib::string & name);
vespalib::string
myhex(const void * b, size_t sz)
@@ -357,7 +358,7 @@ void
fillDomainTest(Session * s1, size_t numPackets, size_t numEntries, size_t entrySize)
{
size_t value(0);
- std::vector<char> entryBuffer(entrySize);
+ std::vector<char> entryBuffer(entrySize);
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++) {
@@ -464,10 +465,11 @@ getMaxSessionRunTime(TransLogServer &tls, const vespalib::string &domain)
return tls.getDomainStats()[domain].maxSessionRunTime.count();
}
-void createAndFillDomain(const vespalib::string & name, Encoding encoding, size_t preExistingDomains)
+void
+createAndFillDomain(const vespalib::string & dir, const vespalib::string & name, Encoding encoding, size_t preExistingDomains)
{
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test13", 18377, ".", fileHeaderContext,
+ TransLogServer tlss(dir, 18377, ".", fileHeaderContext,
createDomainConfig(0x1000000).setEncoding(encoding), 4);
TransLogClient tls("tcp/localhost:18377");
@@ -476,19 +478,21 @@ void createAndFillDomain(const vespalib::string & name, Encoding encoding, size_
fillDomainTest(s1.get(), name);
}
-void verifyDomain(const vespalib::string & name) {
+void
+verifyDomain(const vespalib::string & dir, const vespalib::string & name) {
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test13", 18377, ".", fileHeaderContext, createDomainConfig(0x1000000));
+ TransLogServer tlss(dir, 18377, ".", fileHeaderContext, createDomainConfig(0x1000000));
TransLogClient tls("tcp/localhost:18377");
auto s1 = openDomainTest(tls, name);
visitDomainTest(tls, s1.get(), name);
}
-}
-TEST("testVisitOverGeneratedDomain") {
+
+void
+testVisitOverGeneratedDomain(const vespalib::string & testDir) {
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test7", 18377, ".", fileHeaderContext, createDomainConfig(0x10000));
+ TransLogServer tlss(testDir, 18377, ".", fileHeaderContext, createDomainConfig(0x10000));
TransLogClient tls("tcp/localhost:18377");
vespalib::string name("test1");
@@ -502,10 +506,11 @@ TEST("testVisitOverGeneratedDomain") {
EXPECT_GREATER(maxSessionRunTime, 0);
}
-TEST("testVisitOverPreExistingDomain") {
+void
+testVisitOverPreExistingDomain(const vespalib::string & testDir) {
// Depends on Test::testVisitOverGeneratedDomain()
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test7", 18377, ".", fileHeaderContext, createDomainConfig(0x10000));
+ TransLogServer tlss(testDir, 18377, ".", fileHeaderContext, createDomainConfig(0x10000));
TransLogClient tls("tcp/localhost:18377");
vespalib::string name("test1");
@@ -513,9 +518,10 @@ TEST("testVisitOverPreExistingDomain") {
visitDomainTest(tls, s1.get(), name);
}
-TEST("partialUpdateTest") {
+void
+partialUpdateTest(const vespalib::string & testDir) {
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test7", 18377, ".", fileHeaderContext, createDomainConfig(0x10000));
+ TransLogServer tlss(testDir, 18377, ".", fileHeaderContext, createDomainConfig(0x10000));
TransLogClient tls("tcp/localhost:18377");
auto s1 = openDomainTest(tls, "test1");
@@ -568,21 +574,33 @@ TEST("partialUpdateTest") {
ASSERT_TRUE( ca3.hasSerial(7) );
}
+}
+
+TEST("testVisitAndUpdates") {
+ test::DirectoryHandler testDir("test7");
+ testVisitOverGeneratedDomain(testDir.getDir());
+ testVisitOverPreExistingDomain(testDir.getDir());
+ partialUpdateTest(testDir.getDir());
+}
+
+
TEST("testCrcVersions") {
+ test::DirectoryHandler testDir("test13");
try {
- createAndFillDomain("ccitt_crc32", Encoding(Encoding::Crc::ccitt_crc32, Encoding::Compression::none), 0);
+ createAndFillDomain(testDir.getDir(),"ccitt_crc32", Encoding(Encoding::Crc::ccitt_crc32, Encoding::Compression::none), 0);
ASSERT_TRUE(false);
} catch (vespalib::IllegalArgumentException & e) {
EXPECT_TRUE(e.getMessage().find("Compression:none is not allowed for the tls") != vespalib::string::npos);
}
- createAndFillDomain("xxh64", Encoding(Encoding::Crc::xxh64, Encoding::Compression::zstd), 0);
+ createAndFillDomain(testDir.getDir(), "xxh64", Encoding(Encoding::Crc::xxh64, Encoding::Compression::zstd), 0);
- verifyDomain("xxh64");
+ verifyDomain(testDir.getDir(), "xxh64");
}
TEST("testRemove") {
+ test::DirectoryHandler testDir("testremove");
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("testremove", 18377, ".", fileHeaderContext, createDomainConfig(0x10000));
+ TransLogServer tlss(testDir.getDir(), 18377, ".", fileHeaderContext, createDomainConfig(0x10000));
TransLogClient tls("tcp/localhost:18377");
vespalib::string name("test-delete");
@@ -629,14 +647,15 @@ assertStatus(Session &s, SerialNum expFirstSerial, SerialNum expLastSerial, uint
}
-TEST("test sending a lot of data") {
+void
+ testSendingAlotOfDataSync(const vespalib::string & testDir) {
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, createDomainConfig(0x80000));
+ TransLogServer tlss(testDir, 18377, ".", fileHeaderContext, createDomainConfig(0x80000));
TransLogClient tls("tcp/localhost:18377");
createDomainTest(tls, MANY, 0);
@@ -659,7 +678,7 @@ TEST("test sending a lot of data") {
}
{
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test8", 18377, ".", fileHeaderContext, createDomainConfig(0x1000000));
+ TransLogServer tlss(testDir, 18377, ".", fileHeaderContext, createDomainConfig(0x1000000));
TransLogClient tls("tcp/localhost:18377");
auto s1 = openDomainTest(tls, "many");
@@ -680,7 +699,7 @@ TEST("test sending a lot of data") {
}
{
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test8", 18377, ".", fileHeaderContext, createDomainConfig(0x1000000));
+ TransLogServer tlss(testDir, 18377, ".", fileHeaderContext, createDomainConfig(0x1000000));
TransLogClient tls("tcp/localhost:18377");
auto s1 = openDomainTest(tls, MANY);
@@ -701,14 +720,14 @@ TEST("test sending a lot of data") {
}
}
-TEST("test sending a lot of data async") {
+void testSendingAlotOfDataAsync(const vespalib::string & testDir) {
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, createDomainConfig(0x80000));
+ TransLogServer tlss(testDir, 18377, ".", fileHeaderContext, createDomainConfig(0x80000));
TransLogClient tls("tcp/localhost:18377");
createDomainTest(tls, MANY, 1);
auto s1 = openDomainTest(tls, MANY);
@@ -730,7 +749,7 @@ TEST("test sending a lot of data async") {
}
{
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test8", 18377, ".", fileHeaderContext, createDomainConfig(0x1000000));
+ TransLogServer tlss(testDir, 18377, ".", fileHeaderContext, createDomainConfig(0x1000000));
TransLogClient tls("tcp/localhost:18377");
auto s1 = openDomainTest(tls, MANY);
@@ -751,16 +770,21 @@ TEST("test sending a lot of data async") {
}
}
-
+TEST("test sending a lot of data both sync and async") {
+ test::DirectoryHandler testDir("test8");
+ testSendingAlotOfDataSync(testDir.getDir());
+ testSendingAlotOfDataAsync(testDir.getDir());
+}
TEST("testErase") {
const unsigned int NUM_PACKETS = 1000;
const unsigned int NUM_ENTRIES = 100;
const unsigned int TOTAL_NUM_ENTRIES = NUM_PACKETS * NUM_ENTRIES;
+ test::DirectoryHandler testDir("test12");
{
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test12", 18377, ".", fileHeaderContext, createDomainConfig(0x80000));
+ TransLogServer tlss(testDir.getDir(), 18377, ".", fileHeaderContext, createDomainConfig(0x80000));
TransLogClient tls("tcp/localhost:18377");
createDomainTest(tls, "erase", 0);
@@ -769,7 +793,7 @@ TEST("testErase") {
}
{
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test12", 18377, ".", fileHeaderContext, createDomainConfig(0x1000000));
+ TransLogServer tlss(testDir.getDir(), 18377, ".", fileHeaderContext, createDomainConfig(0x1000000));
TransLogClient tls("tcp/localhost:18377");
auto s1 = openDomainTest(tls, "erase");
@@ -856,7 +880,8 @@ TEST("testSync") {
const unsigned int TOTAL_NUM_ENTRIES = NUM_PACKETS * NUM_ENTRIES;
DummyFileHeaderContext fileHeaderContext;
- TransLogServer tlss("test9", 18377, ".", fileHeaderContext, createDomainConfig(0x1000000));
+ test::DirectoryHandler testDir("test9");
+ TransLogServer tlss(testDir.getDir(), 18377, ".", fileHeaderContext, createDomainConfig(0x1000000));
TransLogClient tls("tcp/localhost:18377");
createDomainTest(tls, "sync", 0);
@@ -877,8 +902,9 @@ TEST("test truncate on version mismatch") {
uint64_t fromOld(0), toOld(0);
size_t countOld(0);
DummyFileHeaderContext fileHeaderContext;
+ test::DirectoryHandler testDir("test11");
{
- TransLogServer tlss("test11", 18377, ".", fileHeaderContext, createDomainConfig(0x1000000));
+ TransLogServer tlss(testDir.getDir(), 18377, ".", fileHeaderContext, createDomainConfig(0x1000000));
TransLogClient tls("tcp/localhost:18377");
createDomainTest(tls, "sync", 0);
@@ -890,7 +916,7 @@ TEST("test truncate on version mismatch") {
EXPECT_TRUE(s1->sync(2, syncedTo));
EXPECT_EQUAL(syncedTo, TOTAL_NUM_ENTRIES);
}
- FastOS_File f("test11/sync/sync-0000000000000000");
+ FastOS_File f((testDir.getDir() + "/sync/sync-0000000000000000").c_str());
EXPECT_TRUE(f.OpenWriteOnlyExisting());
EXPECT_TRUE(f.SetPosition(f.GetSize()));
@@ -899,7 +925,7 @@ TEST("test truncate on version mismatch") {
EXPECT_EQUAL(static_cast<ssize_t>(sizeof(tmp)), f.Write2(tmp, sizeof(tmp)));
EXPECT_TRUE(f.Close());
{
- TransLogServer tlss("test11", 18377, ".", fileHeaderContext, createDomainConfig(0x10000));
+ TransLogServer tlss(testDir.getDir(), 18377, ".", fileHeaderContext, createDomainConfig(0x10000));
TransLogClient tls("tcp/localhost:18377");
auto s1 = openDomainTest(tls, "sync");
uint64_t from(0), to(0);
@@ -916,15 +942,16 @@ TEST("test truncation after short read") {
const unsigned int NUM_ENTRIES = 1;
const unsigned int TOTAL_NUM_ENTRIES = NUM_PACKETS * NUM_ENTRIES;
const unsigned int ENTRYSIZE = 4080;
- vespalib::string topdir("test10");
+ test::DirectoryHandler topdir("test10");
vespalib::string domain("truncate");
- vespalib::string dir(topdir + "/" + domain);
+ vespalib::string dir(topdir.getDir() + "/" + domain);
vespalib::string tlsspec("tcp/localhost:18377");
+
DomainConfig domainConfig = createDomainConfig(0x10000);
DummyFileHeaderContext fileHeaderContext;
{
- TransLogServer tlss(topdir, 18377, ".", fileHeaderContext, domainConfig);
+ TransLogServer tlss(topdir.getDir(), 18377, ".", fileHeaderContext, domainConfig);
TransLogClient tls(tlsspec);
createDomainTest(tls, domain, 0);
@@ -938,7 +965,7 @@ TEST("test truncation after short read") {
}
EXPECT_EQUAL(2u, countFiles(dir));
{
- TransLogServer tlss(topdir, 18377, ".", fileHeaderContext, domainConfig);
+ TransLogServer tlss(topdir.getDir(), 18377, ".", fileHeaderContext, domainConfig);
TransLogClient tls(tlsspec);
auto s1 = openDomainTest(tls, domain);
checkFilledDomainTest(*s1, TOTAL_NUM_ENTRIES);
@@ -952,7 +979,7 @@ TEST("test truncation after short read") {
trfile.Close();
}
{
- TransLogServer tlss(topdir, 18377, ".", fileHeaderContext, domainConfig);
+ TransLogServer tlss(topdir.getDir(), 18377, ".", fileHeaderContext, domainConfig);
TransLogClient tls(tlsspec);
auto s1 = openDomainTest(tls, domain);
checkFilledDomainTest(*s1, TOTAL_NUM_ENTRIES - 1);
diff --git a/searchlib/src/tests/transactionlog/translogclient_test.sh b/searchlib/src/tests/transactionlog/translogclient_test.sh
deleted file mode 100755
index 50d7c73fd6a..00000000000
--- a/searchlib/src/tests/transactionlog/translogclient_test.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/bash
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-set -e
-rm -rf test7 test8 test9 test10 test11 test12 test13 testremove
-$VALGRIND ./searchlib_translogclient_test_app
-rm -rf test7 test8 test9 test10 test11 test12 test13 testremove