Enable DB tests via ScyllaDB service (#1103)

Fixes #1092
This commit is contained in:
Alex Kremer
2024-01-15 12:09:00 +00:00
committed by GitHub
parent 350a45e7e2
commit 13d2d4e2ca
9 changed files with 143 additions and 27 deletions

View File

@@ -20,6 +20,7 @@
#include "data/BackendFactory.h"
#include "data/cassandra/Handle.h"
#include "util/Fixtures.h"
#include "util/TestGlobals.h"
#include "util/config/Config.h"
#include <boost/json/parse.hpp>
@@ -30,7 +31,6 @@
#include <string>
namespace {
constexpr auto contactPoints = "127.0.0.1";
constexpr auto keyspace = "factory_test";
} // namespace
@@ -62,7 +62,7 @@ protected:
{
BackendCassandraFactoryTest::TearDown();
// drop the keyspace for next test
data::cassandra::Handle const handle{contactPoints};
data::cassandra::Handle const handle{TestGlobals::instance().backendHost};
EXPECT_TRUE(handle.connect());
handle.execute("DROP KEYSPACE " + std::string{keyspace});
}
@@ -116,7 +116,7 @@ TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackend)
}}
}}
}})",
contactPoints,
TestGlobals::instance().backendHost,
keyspace
))};
@@ -128,7 +128,7 @@ TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackend)
EXPECT_FALSE(backend->fetchLedgerRange());
// insert range table
data::cassandra::Handle const handle{contactPoints};
data::cassandra::Handle const handle{TestGlobals::instance().backendHost};
EXPECT_TRUE(handle.connect());
handle.execute(fmt::format("INSERT INTO {}.ledger_range (is_latest, sequence) VALUES (False, 100)", keyspace));
handle.execute(fmt::format("INSERT INTO {}.ledger_range (is_latest, sequence) VALUES (True, 500)", keyspace));
@@ -159,7 +159,7 @@ TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackendReadOnlyWithEmpt
}}
}}
}})",
contactPoints,
TestGlobals::instance().backendHost,
keyspace
))};
EXPECT_THROW(make_Backend(cfg), std::runtime_error);
@@ -180,7 +180,7 @@ TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackendReadOnlyWithDBRe
}}
}}
}})",
contactPoints,
TestGlobals::instance().backendHost,
keyspace
))};
@@ -197,7 +197,7 @@ TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackendReadOnlyWithDBRe
}}
}}
}})",
contactPoints,
TestGlobals::instance().backendHost,
keyspace
))};

View File

@@ -29,6 +29,7 @@
#include "util/LedgerUtils.h"
#include "util/Random.h"
#include "util/StringUtils.h"
#include "util/TestGlobals.h"
#include "util/config/Config.h"
#include <boost/asio/impl/spawn.hpp>
@@ -68,11 +69,6 @@ namespace json = boost::json;
using namespace data::cassandra;
namespace {
constexpr auto contactPoints = "127.0.0.1";
constexpr auto keyspace = "clio_test";
} // namespace
class BackendCassandraTest : public SyncAsioContextTest {
protected:
Config cfg{json::parse(fmt::format(
@@ -81,8 +77,8 @@ protected:
"keyspace": "{}",
"replication_factor": 1
}})JSON",
contactPoints,
keyspace
TestGlobals::instance().backendHost,
TestGlobals::instance().backendKeyspace
))};
SettingsProvider settingsProvider{cfg, 0};
@@ -101,9 +97,9 @@ protected:
backend.reset();
// drop the keyspace for next test
Handle const handle{contactPoints};
Handle const handle{TestGlobals::instance().backendHost};
EXPECT_TRUE(handle.connect());
handle.execute("DROP KEYSPACE " + std::string{keyspace});
handle.execute("DROP KEYSPACE " + TestGlobals::instance().backendKeyspace);
}
std::default_random_engine randomEngine{0};

View File

@@ -20,6 +20,7 @@
#include "data/cassandra/Handle.h"
#include "data/cassandra/Types.h"
#include "util/Fixtures.h"
#include "util/TestGlobals.h"
#include <cassandra.h>
#include <fmt/core.h>
@@ -107,7 +108,7 @@ protected:
TEST_F(BackendCassandraBaseTest, ConnectionSuccess)
{
Handle const handle{"127.0.0.1"};
Handle const handle{TestGlobals::instance().backendHost};
auto const f = handle.asyncConnect();
auto const res = f.await();
@@ -144,7 +145,7 @@ TEST_F(BackendCassandraBaseTest, ConnectionFailTimeout)
TEST_F(BackendCassandraBaseTest, FutureCallback)
{
Handle const handle{"127.0.0.1"};
Handle const handle{TestGlobals::instance().backendHost};
ASSERT_TRUE(handle.connect());
auto const statement = handle.prepare("SELECT keyspace_name FROM system_schema.keyspaces").bind();
@@ -165,7 +166,7 @@ TEST_F(BackendCassandraBaseTest, FutureCallback)
TEST_F(BackendCassandraBaseTest, FutureCallbackSurviveMove)
{
Handle const handle{"127.0.0.1"};
Handle const handle{TestGlobals::instance().backendHost};
ASSERT_TRUE(handle.connect());
auto const statement = handle.prepare("SELECT keyspace_name FROM system_schema.keyspaces").bind();
@@ -192,7 +193,7 @@ TEST_F(BackendCassandraBaseTest, FutureCallbackSurviveMove)
TEST_F(BackendCassandraBaseTest, KeyspaceManipulation)
{
Handle const handle{"127.0.0.1"};
Handle const handle{TestGlobals::instance().backendHost};
std::string keyspace = "test_keyspace_manipulation";
{
@@ -244,7 +245,7 @@ TEST_F(BackendCassandraBaseTest, CreateTableWithStrings)
"fifth",
};
auto handle = createHandle("127.0.0.1", "test");
auto handle = createHandle(TestGlobals::instance().backendHost, "test");
auto q1 = fmt::format(
R"(
CREATE TABLE IF NOT EXISTS strings (hash blob PRIMARY KEY, sequence bigint)
@@ -309,7 +310,7 @@ TEST_F(BackendCassandraBaseTest, BatchInsert)
"fifth",
};
auto handle = createHandle("127.0.0.1", "test");
auto handle = createHandle(TestGlobals::instance().backendHost, "test");
auto const q1 = fmt::format(
R"(
CREATE TABLE IF NOT EXISTS strings (hash blob PRIMARY KEY, sequence bigint)
@@ -368,7 +369,7 @@ TEST_F(BackendCassandraBaseTest, BatchInsertAsync)
"fifth",
};
auto handle = createHandle("127.0.0.1", "test");
auto handle = createHandle(TestGlobals::instance().backendHost, "test");
auto const q1 = fmt::format(
R"(
CREATE TABLE IF NOT EXISTS strings (hash blob PRIMARY KEY, sequence bigint)
@@ -414,7 +415,7 @@ TEST_F(BackendCassandraBaseTest, BatchInsertAsync)
TEST_F(BackendCassandraBaseTest, AlterTableAddColumn)
{
auto handle = createHandle("127.0.0.1", "test");
auto handle = createHandle(TestGlobals::instance().backendHost, "test");
auto const q1 = fmt::format(
R"(
CREATE TABLE IF NOT EXISTS strings (hash blob PRIMARY KEY, sequence bigint)
@@ -432,7 +433,7 @@ TEST_F(BackendCassandraBaseTest, AlterTableAddColumn)
TEST_F(BackendCassandraBaseTest, AlterTableMoveToNewTable)
{
auto handle = createHandle("127.0.0.1", "test");
auto handle = createHandle(TestGlobals::instance().backendHost, "test");
prepStringsTable(handle);
auto const newTable = fmt::format(