Move to clang-format-16 (#908)

Fixes #848
This commit is contained in:
Alex Kremer
2023-10-19 16:55:04 +01:00
committed by GitHub
parent 5de87b9ef8
commit 1aab2b94b1
265 changed files with 3950 additions and 4743 deletions

View File

@@ -25,8 +25,7 @@
using namespace data;
class BackendCountersTest : public ::testing::Test
{
class BackendCountersTest : public ::testing::Test {
protected:
static boost::json::object
emptyReport()

View File

@@ -29,8 +29,7 @@ constexpr auto contactPoints = "127.0.0.1";
constexpr auto keyspace = "factory_test";
} // namespace
class BackendCassandraFactoryTest : public SyncAsioContextTest
{
class BackendCassandraFactoryTest : public SyncAsioContextTest {
protected:
void
SetUp() override
@@ -45,8 +44,7 @@ protected:
}
};
class BackendCassandraFactoryTestWithDB : public BackendCassandraFactoryTest
{
class BackendCassandraFactoryTestWithDB : public BackendCassandraFactoryTest {
protected:
void
SetUp() override
@@ -73,7 +71,8 @@ TEST_F(BackendCassandraFactoryTest, NoSuchBackend)
{
"type":"unknown"
}
})")};
})"
)};
EXPECT_THROW(make_Backend(cfg), std::runtime_error);
}
@@ -93,7 +92,8 @@ TEST_F(BackendCassandraFactoryTest, CreateCassandraBackendDBDisconnect)
}}
}})",
"127.0.0.2",
keyspace))};
keyspace
))};
EXPECT_THROW(make_Backend(cfg), std::runtime_error);
}
@@ -112,7 +112,8 @@ TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackend)
}}
}})",
contactPoints,
keyspace))};
keyspace
))};
{
auto backend = make_Backend(cfg);
@@ -154,7 +155,8 @@ TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackendReadOnlyWithEmpt
}}
}})",
contactPoints,
keyspace))};
keyspace
))};
EXPECT_THROW(make_Backend(cfg), std::runtime_error);
}
@@ -174,7 +176,8 @@ TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackendReadOnlyWithDBRe
}}
}})",
contactPoints,
keyspace))};
keyspace
))};
util::Config const cfgWrite{boost::json::parse(fmt::format(
R"({{
@@ -190,7 +193,8 @@ TEST_F(BackendCassandraFactoryTestWithDB, CreateCassandraBackendReadOnlyWithDBRe
}}
}})",
contactPoints,
keyspace))};
keyspace
))};
EXPECT_TRUE(make_Backend(cfgWrite));
EXPECT_TRUE(make_Backend(cfgReadOnly));

View File

@@ -29,11 +29,9 @@ using namespace data::cassandra;
using namespace data::cassandra::detail;
using namespace testing;
class BackendCassandraAsyncExecutorTest : public SyncAsioContextTest
{
class BackendCassandraAsyncExecutorTest : public SyncAsioContextTest {
protected:
struct CallbackMock
{
struct CallbackMock {
MOCK_METHOD(void, onComplete, (FakeResultOrError));
MOCK_METHOD(void, onRetry, ());
};
@@ -64,7 +62,8 @@ TEST_F(BackendCassandraAsyncExecutorTest, CompletionCalledOnSuccess)
callbackMock_.onComplete(std::move(resultOrError));
work.reset();
},
std::move(onRetry_));
std::move(onRetry_)
);
ctx.run();
}
@@ -78,12 +77,9 @@ TEST_F(BackendCassandraAsyncExecutorTest, ExecutedMultipleTimesByRetryPolicyOnMa
ON_CALL(handle, asyncExecute(An<FakeStatement const&>(), An<std::function<void(FakeResultOrError)>&&>()))
.WillByDefault([&callCount](auto const&, auto&& cb) {
++callCount;
if (callCount >= 3)
{
if (callCount >= 3) {
cb({});
}
else
{
} else {
cb({CassandraError{"timeout", CASS_ERROR_LIB_REQUEST_TIMED_OUT}});
}
@@ -104,7 +100,8 @@ TEST_F(BackendCassandraAsyncExecutorTest, ExecutedMultipleTimesByRetryPolicyOnMa
callbackMock_.onComplete(std::move(resultOrError));
work.reset();
},
std::move(onRetry_));
std::move(onRetry_)
);
ctx.run();
ASSERT_EQ(callCount, 3);
@@ -123,12 +120,9 @@ TEST_F(BackendCassandraAsyncExecutorTest, ExecutedMultipleTimesByRetryPolicyOnOt
ON_CALL(handle, asyncExecute(An<FakeStatement const&>(), An<std::function<void(FakeResultOrError)>&&>()))
.WillByDefault([&callCount](auto const&, auto&& cb) {
++callCount;
if (callCount >= 3)
{
if (callCount >= 3) {
cb({});
}
else
{
} else {
cb({CassandraError{"timeout", CASS_ERROR_LIB_REQUEST_TIMED_OUT}});
}
@@ -150,7 +144,8 @@ TEST_F(BackendCassandraAsyncExecutorTest, ExecutedMultipleTimesByRetryPolicyOnOt
work.reset();
work2.reset();
},
std::move(onRetry_));
std::move(onRetry_)
);
ctx.run();
EXPECT_EQ(callCount, 3);
@@ -187,7 +182,8 @@ TEST_F(BackendCassandraAsyncExecutorTest, CompletionCalledOnFailureAfterRetryCou
callbackMock_.onComplete(std::move(res));
work.reset();
},
std::move(onRetry_));
std::move(onRetry_)
);
ctx.run();
}

View File

@@ -41,8 +41,7 @@ constexpr auto contactPoints = "127.0.0.1";
constexpr auto keyspace = "clio_test";
} // namespace
class BackendCassandraTest : public SyncAsioContextTest
{
class BackendCassandraTest : public SyncAsioContextTest {
protected:
Config cfg{json::parse(fmt::format(
R"JSON({{
@@ -51,7 +50,8 @@ protected:
"replication_factor": 1
}})JSON",
contactPoints,
keyspace))};
keyspace
))};
SettingsProvider settingsProvider{cfg, 0};
// recreated for each test
@@ -327,7 +327,8 @@ TEST_F(BackendCassandraTest, Basic)
ripple::uint256 nftID;
EXPECT_TRUE(
nftID.parseHex("000800006203F49C21D5D6E022CB16DE3538F248662"
"FC73CEF7FF5C60000002C"));
"FC73CEF7FF5C60000002C")
);
std::string metaBlob = hexStringToBinaryString(metaHex);
std::string txnBlob = hexStringToBinaryString(txnHex);
@@ -350,8 +351,7 @@ TEST_F(BackendCassandraTest, Basic)
EXPECT_TRUE(hash256.parseHex(hashHex));
ripple::TxMeta txMeta{hash256, lgrInfoNext.seq, metaBlob};
auto accountsSet = txMeta.getAffectedAccounts();
for (auto& a : accountsSet)
{
for (auto& a : accountsSet) {
affectedAccounts.push_back(a);
}
std::vector<AccountTransactionsData> accountTxData;
@@ -378,7 +378,8 @@ TEST_F(BackendCassandraTest, Basic)
lgrInfoNext.seq,
lgrInfoNext.closeTime.time_since_epoch().count(),
std::string{txnBlob},
std::string{metaBlob});
std::string{metaBlob}
);
backend->writeAccountTransactions(std::move(accountTxData));
backend->writeNFTs(std::move(nftData));
backend->writeNFTTransactions(std::move(parsedNFTTxs));
@@ -402,15 +403,16 @@ TEST_F(BackendCassandraTest, Basic)
ASSERT_EQ(allTransactions.size(), 1);
EXPECT_STREQ(
reinterpret_cast<const char*>(allTransactions[0].transaction.data()),
static_cast<const char*>(txnBlob.data()));
static_cast<const char*>(txnBlob.data())
);
EXPECT_STREQ(
reinterpret_cast<const char*>(allTransactions[0].metadata.data()),
static_cast<const char*>(metaBlob.data()));
static_cast<const char*>(metaBlob.data())
);
auto hashes = backend->fetchAllTransactionHashesInLedger(lgrInfoNext.seq, yield);
EXPECT_EQ(hashes.size(), 1);
EXPECT_EQ(ripple::strHex(hashes[0]), hashHex);
for (auto& a : affectedAccounts)
{
for (auto& a : affectedAccounts) {
auto [accountTransactions, cursor] = backend->fetchAccountTransactions(a, 100, true, {}, yield);
EXPECT_EQ(accountTransactions.size(), 1);
EXPECT_EQ(accountTransactions[0], accountTransactions[0]);
@@ -518,8 +520,7 @@ TEST_F(BackendCassandraTest, Basic)
ripple::uint256 key;
key = ledgerSequence * 100000ul;
for (auto& blob : res)
{
for (auto& blob : res) {
++key;
std::string const keyStr{reinterpret_cast<const char*>(key.data()), ripple::uint256::size()};
blob.first = keyStr;
@@ -528,8 +529,7 @@ TEST_F(BackendCassandraTest, Basic)
return res;
};
auto updateObjects = [](uint32_t ledgerSequence, auto objs) {
for (auto& [key, obj] : objs)
{
for (auto& [key, obj] : objs) {
obj = std::to_string(ledgerSequence) + obj;
}
return objs;
@@ -538,8 +538,7 @@ TEST_F(BackendCassandraTest, Basic)
std::vector<std::tuple<std::string, std::string, std::string>> res{numTxns};
ripple::uint256 base;
base = ledgerSequence * 100000ul;
for (auto& blob : res)
{
for (auto& blob : res) {
++base;
std::string const hashStr{reinterpret_cast<const char*>(base.data()), ripple::uint256::size()};
std::string const txnStr = "tx" + std::to_string(ledgerSequence) + hashStr;
@@ -552,8 +551,7 @@ TEST_F(BackendCassandraTest, Basic)
std::vector<ripple::AccountID> accounts;
ripple::AccountID base;
base = ledgerSequence * 998765ul;
for (size_t i = 0; i < numAccounts; ++i)
{
for (size_t i = 0; i < numAccounts; ++i) {
++base;
accounts.push_back(base);
}
@@ -564,14 +562,12 @@ TEST_F(BackendCassandraTest, Basic)
auto accounts = generateAccounts(ledgerSequence, 10);
std::srand(std::time(nullptr));
uint32_t idx = 0;
for (auto& [hash, txn, meta] : txns)
{
for (auto& [hash, txn, meta] : txns) {
AccountTransactionsData data;
data.ledgerSequence = ledgerSequence;
data.transactionIndex = idx;
data.txHash = hash;
for (size_t i = 0; i < 3; ++i)
{
for (size_t i = 0; i < 3; ++i) {
data.accounts.insert(accounts[std::rand() % accounts.size()]);
}
++idx;
@@ -592,44 +588,38 @@ TEST_F(BackendCassandraTest, Basic)
backend->startWrites();
backend->writeLedger(lgrInfo, ledgerInfoToBinaryString(lgrInfo));
for (auto [hash, txn, meta] : txns)
{
for (auto [hash, txn, meta] : txns) {
backend->writeTransaction(
std::move(hash),
lgrInfo.seq,
lgrInfo.closeTime.time_since_epoch().count(),
std::move(txn),
std::move(meta));
std::move(meta)
);
}
for (auto [key, obj] : objs)
{
for (auto [key, obj] : objs) {
backend->writeLedgerObject(std::string{key}, lgrInfo.seq, std::string{obj});
}
if (state.count(lgrInfo.seq - 1) == 0 ||
std::find_if(state[lgrInfo.seq - 1].begin(), state[lgrInfo.seq - 1].end(), [&](auto obj) {
return obj.first == objs[0].first;
}) == state[lgrInfo.seq - 1].end())
{
for (size_t i = 0; i < objs.size(); ++i)
{
if (i + 1 < objs.size())
{
}) == state[lgrInfo.seq - 1].end()) {
for (size_t i = 0; i < objs.size(); ++i) {
if (i + 1 < objs.size()) {
backend->writeSuccessor(
std::string{objs[i].first}, lgrInfo.seq, std::string{objs[i + 1].first});
}
else
{
std::string{objs[i].first}, lgrInfo.seq, std::string{objs[i + 1].first}
);
} else {
backend->writeSuccessor(
std::string{objs[i].first}, lgrInfo.seq, uint256ToString(data::lastKey));
std::string{objs[i].first}, lgrInfo.seq, uint256ToString(data::lastKey)
);
}
}
if (state.contains(lgrInfo.seq - 1))
{
if (state.contains(lgrInfo.seq - 1)) {
backend->writeSuccessor(
std::string{state[lgrInfo.seq - 1].back().first}, lgrInfo.seq, std::string{objs[0].first});
}
else
{
std::string{state[lgrInfo.seq - 1].back().first}, lgrInfo.seq, std::string{objs[0].first}
);
} else {
backend->writeSuccessor(uint256ToString(data::firstKey), lgrInfo.seq, std::string{objs[0].first});
}
}
@@ -648,29 +638,27 @@ TEST_F(BackendCassandraTest, Basic)
EXPECT_TRUE(retLgr);
EXPECT_EQ(ledgerInfoToBlob(*retLgr), ledgerInfoToBlob(lgrInfo));
auto retTxns = backend->fetchAllTransactionsInLedger(seq, yield);
for (auto [hash, txn, meta] : txns)
{
for (auto [hash, txn, meta] : txns) {
bool found = false;
for (auto [retTxn, retMeta, retSeq, retDate] : retTxns)
{
for (auto [retTxn, retMeta, retSeq, retDate] : retTxns) {
if (std::strncmp(
reinterpret_cast<const char*>(retTxn.data()),
static_cast<const char*>(txn.data()),
txn.size()) == 0 &&
txn.size()
) == 0 &&
std::strncmp(
reinterpret_cast<const char*>(retMeta.data()),
static_cast<const char*>(meta.data()),
meta.size()) == 0)
meta.size()
) == 0)
found = true;
}
ASSERT_TRUE(found);
}
for (auto [account, data] : accountTx)
{
for (auto [account, data] : accountTx) {
std::vector<data::TransactionAndMetadata> retData;
std::optional<data::TransactionsCursor> cursor;
do
{
do {
uint32_t const limit = 10;
auto [accountTransactions, retCursor] =
backend->fetchAccountTransactions(account, limit, false, cursor, yield);
@@ -680,8 +668,7 @@ TEST_F(BackendCassandraTest, Basic)
cursor = retCursor;
} while (cursor);
EXPECT_EQ(retData.size(), data.size());
for (size_t i = 0; i < retData.size(); ++i)
{
for (size_t i = 0; i < retData.size(); ++i) {
auto [txn, meta, _, __] = retData[i];
auto [___, expTxn, expMeta] = data[i];
EXPECT_STREQ(reinterpret_cast<const char*>(txn.data()), static_cast<const char*>(expTxn.data()));
@@ -689,16 +676,12 @@ TEST_F(BackendCassandraTest, Basic)
}
}
std::vector<ripple::uint256> keys;
for (auto [key, obj] : objs)
{
for (auto [key, obj] : objs) {
auto retObj = backend->fetchLedgerObject(binaryStringToUint256(key), seq, yield);
if (obj.size())
{
if (obj.size()) {
ASSERT_TRUE(retObj.has_value());
EXPECT_STREQ(static_cast<const char*>(obj.data()), reinterpret_cast<const char*>(retObj->data()));
}
else
{
} else {
ASSERT_FALSE(retObj.has_value());
}
keys.push_back(binaryStringToUint256(key));
@@ -708,18 +691,15 @@ TEST_F(BackendCassandraTest, Basic)
auto retObjs = backend->fetchLedgerObjects(keys, seq, yield);
ASSERT_EQ(retObjs.size(), objs.size());
for (size_t i = 0; i < keys.size(); ++i)
{
for (size_t i = 0; i < keys.size(); ++i) {
auto [key, obj] = objs[i];
auto retObj = retObjs[i];
if (obj.size())
{
if (obj.size()) {
ASSERT_TRUE(retObj.size());
EXPECT_STREQ(
static_cast<const char*>(obj.data()), reinterpret_cast<const char*>(retObj.data()));
}
else
{
static_cast<const char*>(obj.data()), reinterpret_cast<const char*>(retObj.data())
);
} else {
ASSERT_FALSE(retObj.size());
}
}
@@ -727,20 +707,16 @@ TEST_F(BackendCassandraTest, Basic)
data::LedgerPage page;
std::vector<data::LedgerObject> retObjs;
do
{
do {
uint32_t const limit = 10;
page = backend->fetchLedgerPage(page.cursor, seq, limit, false, yield);
retObjs.insert(retObjs.end(), page.objects.begin(), page.objects.end());
} while (page.cursor);
for (const auto& obj : objs)
{
for (const auto& obj : objs) {
bool found = false;
for (const auto& retObj : retObjs)
{
if (ripple::strHex(obj.first) == ripple::strHex(retObj.key))
{
for (const auto& retObj : retObjs) {
if (ripple::strHex(obj.first) == ripple::strHex(retObj.key)) {
found = true;
ASSERT_EQ(ripple::strHex(obj.second), ripple::strHex(retObj.blob));
}
@@ -755,18 +731,16 @@ TEST_F(BackendCassandraTest, Basic)
std::unordered_map<std::string, std::pair<std::string, std::string>> allTxnsMap;
std::map<uint32_t, std::map<ripple::AccountID, std::vector<std::string>>> allAccountTx;
std::map<uint32_t, ripple::LedgerInfo> lgrInfos;
for (size_t i = 0; i < 10; ++i)
{
for (size_t i = 0; i < 10; ++i) {
lgrInfoNext = generateNextLedger(lgrInfoNext);
auto objs = generateObjects(25, lgrInfoNext.seq);
auto txns = generateTxns(10, lgrInfoNext.seq);
auto accountTx = generateAccountTx(lgrInfoNext.seq, txns);
for (auto rec : accountTx)
{
for (auto account : rec.accounts)
{
for (auto rec : accountTx) {
for (auto account : rec.accounts) {
allAccountTx[lgrInfoNext.seq][account].emplace_back(
reinterpret_cast<const char*>(rec.txHash.data()), ripple::uint256::size());
reinterpret_cast<const char*>(rec.txHash.data()), ripple::uint256::size()
);
}
}
EXPECT_EQ(objs.size(), 25);
@@ -778,32 +752,26 @@ TEST_F(BackendCassandraTest, Basic)
writeLedger(lgrInfoNext, txns, objs, accountTx, state);
allTxns[lgrInfoNext.seq] = txns;
lgrInfos[lgrInfoNext.seq] = lgrInfoNext;
for (auto& [hash, txn, meta] : txns)
{
for (auto& [hash, txn, meta] : txns) {
allTxnsMap[hash] = std::make_pair(txn, meta);
}
}
std::vector<std::pair<std::string, std::string>> objs;
for (size_t i = 0; i < 10; ++i)
{
for (size_t i = 0; i < 10; ++i) {
lgrInfoNext = generateNextLedger(lgrInfoNext);
if (objs.empty())
{
if (objs.empty()) {
objs = generateObjects(25, lgrInfoNext.seq);
}
else
{
} else {
objs = updateObjects(lgrInfoNext.seq, objs);
}
auto txns = generateTxns(10, lgrInfoNext.seq);
auto accountTx = generateAccountTx(lgrInfoNext.seq, txns);
for (auto rec : accountTx)
{
for (auto account : rec.accounts)
{
for (auto rec : accountTx) {
for (auto account : rec.accounts) {
allAccountTx[lgrInfoNext.seq][account].emplace_back(
reinterpret_cast<const char*>(rec.txHash.data()), ripple::uint256::size());
reinterpret_cast<const char*>(rec.txHash.data()), ripple::uint256::size()
);
}
}
EXPECT_EQ(objs.size(), 25);
@@ -815,8 +783,7 @@ TEST_F(BackendCassandraTest, Basic)
writeLedger(lgrInfoNext, txns, objs, accountTx, state);
allTxns[lgrInfoNext.seq] = txns;
lgrInfos[lgrInfoNext.seq] = lgrInfoNext;
for (auto& [hash, txn, meta] : txns)
{
for (auto& [hash, txn, meta] : txns) {
allTxnsMap[hash] = std::make_pair(txn, meta);
}
}
@@ -824,24 +791,18 @@ TEST_F(BackendCassandraTest, Basic)
auto flatten = [&](uint32_t max) {
std::vector<std::pair<std::string, std::string>> flat;
std::map<std::string, std::string> objs;
for (auto [seq, diff] : state)
{
for (auto [k, v] : diff)
{
if (seq > max)
{
for (auto [seq, diff] : state) {
for (auto [k, v] : diff) {
if (seq > max) {
if (!objs.contains(k))
objs[k] = "";
}
else
{
} else {
objs[k] = v;
}
}
}
flat.reserve(objs.size());
for (auto [key, value] : objs)
{
for (auto [key, value] : objs) {
flat.emplace_back(key, value);
}
return flat;
@@ -850,14 +811,11 @@ TEST_F(BackendCassandraTest, Basic)
auto flattenAccountTx = [&](uint32_t max) {
std::unordered_map<ripple::AccountID, std::vector<std::tuple<std::string, std::string, std::string>>>
accountTx;
for (auto [seq, map] : allAccountTx)
{
for (auto [seq, map] : allAccountTx) {
if (seq > max)
break;
for (auto& [account, hashes] : map)
{
for (auto& hash : hashes)
{
for (auto& [account, hashes] : map) {
for (auto& hash : hashes) {
auto& [txn, meta] = allTxnsMap[hash];
accountTx[account].emplace_back(hash, txn, meta);
}
@@ -868,8 +826,7 @@ TEST_F(BackendCassandraTest, Basic)
return accountTx;
};
for (auto [seq, diff] : state)
{
for (auto [seq, diff] : state) {
auto flat = flatten(seq);
checkLedger(lgrInfos[seq], allTxns[seq], flat, flattenAccountTx(seq));
}
@@ -1093,8 +1050,7 @@ TEST_F(BackendCassandraTest, CacheIntegration)
ripple::uint256 key;
key = ledgerSequence * 100000;
for (auto& blob : res)
{
for (auto& blob : res) {
++key;
std::string const keyStr{reinterpret_cast<const char*>(key.data()), ripple::uint256::size()};
blob.first = keyStr;
@@ -1103,8 +1059,7 @@ TEST_F(BackendCassandraTest, CacheIntegration)
return res;
};
auto updateObjects = [](uint32_t ledgerSequence, auto objs) {
for (auto& [key, obj] : objs)
{
for (auto& [key, obj] : objs) {
obj = std::to_string(ledgerSequence) + obj;
}
return objs;
@@ -1124,8 +1079,7 @@ TEST_F(BackendCassandraTest, CacheIntegration)
backend->writeLedger(lgrInfo, std::move(ledgerInfoToBinaryString(lgrInfo)));
std::vector<data::LedgerObject> cacheUpdates;
for (auto [key, obj] : objs)
{
for (auto [key, obj] : objs) {
backend->writeLedgerObject(std::string{key}, lgrInfo.seq, std::string{obj});
auto key256 = ripple::uint256::fromVoidChecked(key);
cacheUpdates.push_back({*key256, {obj.begin(), obj.end()}});
@@ -1134,28 +1088,23 @@ TEST_F(BackendCassandraTest, CacheIntegration)
if (state.count(lgrInfo.seq - 1) == 0 ||
std::find_if(state[lgrInfo.seq - 1].begin(), state[lgrInfo.seq - 1].end(), [&](auto obj) {
return obj.first == objs[0].first;
}) == state[lgrInfo.seq - 1].end())
{
for (size_t i = 0; i < objs.size(); ++i)
{
if (i + 1 < objs.size())
{
}) == state[lgrInfo.seq - 1].end()) {
for (size_t i = 0; i < objs.size(); ++i) {
if (i + 1 < objs.size()) {
backend->writeSuccessor(
std::string{objs[i].first}, lgrInfo.seq, std::string{objs[i + 1].first});
}
else
{
std::string{objs[i].first}, lgrInfo.seq, std::string{objs[i + 1].first}
);
} else {
backend->writeSuccessor(
std::string{objs[i].first}, lgrInfo.seq, uint256ToString(data::lastKey));
std::string{objs[i].first}, lgrInfo.seq, uint256ToString(data::lastKey)
);
}
}
if (state.contains(lgrInfo.seq - 1))
{
if (state.contains(lgrInfo.seq - 1)) {
backend->writeSuccessor(
std::string{state[lgrInfo.seq - 1].back().first}, lgrInfo.seq, std::string{objs[0].first});
}
else
{
std::string{state[lgrInfo.seq - 1].back().first}, lgrInfo.seq, std::string{objs[0].first}
);
} else {
backend->writeSuccessor(uint256ToString(data::firstKey), lgrInfo.seq, std::string{objs[0].first});
}
}
@@ -1180,16 +1129,12 @@ TEST_F(BackendCassandraTest, CacheIntegration)
<< "; lgr Info parentHash:" << lgrInfo.parentHash;
std::vector<ripple::uint256> keys;
for (auto [key, obj] : objs)
{
for (auto [key, obj] : objs) {
auto retObj = backend->fetchLedgerObject(binaryStringToUint256(key), seq, yield);
if (obj.size())
{
if (obj.size()) {
ASSERT_TRUE(retObj.has_value());
EXPECT_STREQ(static_cast<const char*>(obj.data()), reinterpret_cast<const char*>(retObj->data()));
}
else
{
} else {
ASSERT_FALSE(retObj.has_value());
}
keys.push_back(binaryStringToUint256(key));
@@ -1199,37 +1144,30 @@ TEST_F(BackendCassandraTest, CacheIntegration)
auto retObjs = backend->fetchLedgerObjects(keys, seq, yield);
ASSERT_EQ(retObjs.size(), objs.size());
for (size_t i = 0; i < keys.size(); ++i)
{
for (size_t i = 0; i < keys.size(); ++i) {
auto [key, obj] = objs[i];
auto retObj = retObjs[i];
if (obj.size())
{
if (obj.size()) {
ASSERT_TRUE(retObj.size());
EXPECT_STREQ(
static_cast<const char*>(obj.data()), reinterpret_cast<const char*>(retObj.data()));
}
else
{
static_cast<const char*>(obj.data()), reinterpret_cast<const char*>(retObj.data())
);
} else {
ASSERT_FALSE(retObj.size());
}
}
}
data::LedgerPage page;
std::vector<data::LedgerObject> retObjs;
do
{
do {
uint32_t const limit = 10;
page = backend->fetchLedgerPage(page.cursor, seq, limit, false, yield);
retObjs.insert(retObjs.end(), page.objects.begin(), page.objects.end());
} while (page.cursor);
for (const auto& obj : objs)
{
for (const auto& obj : objs) {
bool found = false;
for (const auto& retObj : retObjs)
{
if (ripple::strHex(obj.first) == ripple::strHex(retObj.key))
{
for (const auto& retObj : retObjs) {
if (ripple::strHex(obj.first) == ripple::strHex(retObj.key)) {
found = true;
ASSERT_EQ(ripple::strHex(obj.second), ripple::strHex(retObj.blob));
}
@@ -1241,8 +1179,7 @@ TEST_F(BackendCassandraTest, CacheIntegration)
std::map<uint32_t, std::vector<std::pair<std::string, std::string>>> state;
std::map<uint32_t, ripple::LedgerInfo> lgrInfos;
for (size_t i = 0; i < 10; ++i)
{
for (size_t i = 0; i < 10; ++i) {
lgrInfoNext = generateNextLedger(lgrInfoNext);
auto objs = generateObjects(25, lgrInfoNext.seq);
EXPECT_EQ(objs.size(), 25);
@@ -1254,15 +1191,11 @@ TEST_F(BackendCassandraTest, CacheIntegration)
}
std::vector<std::pair<std::string, std::string>> objs;
for (size_t i = 0; i < 10; ++i)
{
for (size_t i = 0; i < 10; ++i) {
lgrInfoNext = generateNextLedger(lgrInfoNext);
if (objs.empty())
{
if (objs.empty()) {
objs = generateObjects(25, lgrInfoNext.seq);
}
else
{
} else {
objs = updateObjects(lgrInfoNext.seq, objs);
}
EXPECT_EQ(objs.size(), 25);
@@ -1276,31 +1209,24 @@ TEST_F(BackendCassandraTest, CacheIntegration)
auto flatten = [&](uint32_t max) {
std::vector<std::pair<std::string, std::string>> flat;
std::map<std::string, std::string> objs;
for (auto [seq, diff] : state)
{
for (auto [k, v] : diff)
{
if (seq > max)
{
for (auto [seq, diff] : state) {
for (auto [k, v] : diff) {
if (seq > max) {
if (!objs.contains(k))
objs[k] = "";
}
else
{
} else {
objs[k] = v;
}
}
}
flat.reserve(objs.size());
for (auto [key, value] : objs)
{
for (auto [key, value] : objs) {
flat.emplace_back(key, value);
}
return flat;
};
for (auto [seq, diff] : state)
{
for (auto [seq, diff] : state) {
auto flat = flatten(seq);
checkLedger(lgrInfos[seq], flat);
}

View File

@@ -30,8 +30,7 @@ using namespace std;
using namespace data::cassandra;
class BackendCassandraBaseTest : public NoLoggerFixture
{
class BackendCassandraBaseTest : public NoLoggerFixture {
protected:
static Handle
createHandle(std::string_view contactPoints, std::string_view keyspace)
@@ -44,7 +43,8 @@ protected:
WITH replication = {{'class': 'SimpleStrategy', 'replication_factor': '1'}}
AND durable_writes = true
)",
keyspace);
keyspace
);
EXPECT_TRUE(handle.execute(query));
EXPECT_TRUE(handle.reconnect(keyspace));
return handle;
@@ -73,7 +73,8 @@ protected:
CREATE TABLE IF NOT EXISTS strings (hash blob PRIMARY KEY, sequence bigint)
WITH default_time_to_live = {}
)",
to_string(5000));
to_string(5000)
);
auto const f1 = handle.asyncExecute(q1);
auto const rc = f1.await();
@@ -195,13 +196,14 @@ TEST_F(BackendCassandraBaseTest, KeyspaceManipulation)
ASSERT_TRUE(rc); // expect that we can still connect without keyspace
}
{
const auto query = fmt::format(
auto const query = fmt::format(
R"(
CREATE KEYSPACE {}
WITH replication = {{'class': 'SimpleStrategy', 'replication_factor': '1'}}
AND durable_writes = true
)",
keyspace);
keyspace
);
auto const f = handle.asyncExecute(query);
auto const rc = f.await();
ASSERT_TRUE(rc); // keyspace created
@@ -238,7 +240,8 @@ TEST_F(BackendCassandraBaseTest, CreateTableWithStrings)
CREATE TABLE IF NOT EXISTS strings (hash blob PRIMARY KEY, sequence bigint)
WITH default_time_to_live = {}
)",
5000);
5000
);
{
auto const f1 = handle.asyncExecute(q1);
@@ -259,8 +262,7 @@ TEST_F(BackendCassandraBaseTest, CreateTableWithStrings)
futures.push_back(handle.asyncExecute(insert, entry, idx++));
ASSERT_EQ(futures.size(), entries.size());
for (auto const& f : futures)
{
for (auto const& f : futures) {
auto const rc = f.await();
ASSERT_TRUE(rc) << rc.error();
}
@@ -303,7 +305,8 @@ TEST_F(BackendCassandraBaseTest, BatchInsert)
CREATE TABLE IF NOT EXISTS strings (hash blob PRIMARY KEY, sequence bigint)
WITH default_time_to_live = {}
)",
5000);
5000
);
{
auto const f1 = handle.asyncExecute(q1);
auto const rc = f1.await();
@@ -361,7 +364,8 @@ TEST_F(BackendCassandraBaseTest, BatchInsertAsync)
CREATE TABLE IF NOT EXISTS strings (hash blob PRIMARY KEY, sequence bigint)
WITH default_time_to_live = {}
)",
5000);
5000
);
auto const f1 = handle.asyncExecute(q1);
auto const rc = f1.await();
ASSERT_TRUE(rc) << rc.error();
@@ -406,7 +410,8 @@ TEST_F(BackendCassandraBaseTest, AlterTableAddColumn)
CREATE TABLE IF NOT EXISTS strings (hash blob PRIMARY KEY, sequence bigint)
WITH default_time_to_live = {}
)",
5000);
5000
);
ASSERT_TRUE(handle.execute(q1));
std::string const update = "ALTER TABLE strings ADD tmp blob";
@@ -425,7 +430,8 @@ TEST_F(BackendCassandraBaseTest, AlterTableMoveToNewTable)
CREATE TABLE IF NOT EXISTS strings_v2 (hash blob PRIMARY KEY, sequence bigint, tmp bigint)
WITH default_time_to_live = {}
)",
5000);
5000
);
ASSERT_TRUE(handle.execute(newTable));
// now migrate data; tmp column will just get the sequence number + 1 stored
@@ -436,8 +442,7 @@ TEST_F(BackendCassandraBaseTest, AlterTableMoveToNewTable)
ASSERT_TRUE(res);
auto const& results = res.value();
for (auto [hash, seq] : extract<std::string, int64_t>(results))
{
for (auto [hash, seq] : extract<std::string, int64_t>(results)) {
static_assert(std::is_same_v<decltype(hash), std::string>);
static_assert(std::is_same_v<decltype(seq), int64_t>);
migrationStatements.push_back(migrationInsert.bind(hash, seq, seq + 1u));
@@ -451,8 +456,7 @@ TEST_F(BackendCassandraBaseTest, AlterTableMoveToNewTable)
auto const& resultsV2 = resV2.value();
EXPECT_EQ(results.numRows(), resultsV2.numRows());
for (auto [seq, tmp] : extract<int64_t, int64_t>(resultsV2))
{
for (auto [seq, tmp] : extract<int64_t, int64_t>(resultsV2)) {
static_assert(std::is_same_v<decltype(seq), int64_t>);
static_assert(std::is_same_v<decltype(tmp), int64_t>);
EXPECT_EQ(seq + 1, tmp);

View File

@@ -28,11 +28,9 @@ using namespace data::cassandra;
using namespace data::cassandra::detail;
using namespace testing;
class BackendCassandraExecutionStrategyTest : public SyncAsioContextTest
{
class BackendCassandraExecutionStrategyTest : public SyncAsioContextTest {
protected:
class MockBackendCounters
{
class MockBackendCounters {
public:
using PtrType = std::shared_ptr<StrictMock<MockBackendCounters>>;
static PtrType
@@ -173,7 +171,8 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadBatchInCoroutineSuccessful)
return FakeFutureWithCallback{};
});
EXPECT_CALL(
handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>()))
handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
)
.Times(1);
EXPECT_CALL(*counters, registerReadStartedImpl(NUM_STATEMENTS));
EXPECT_CALL(*counters, registerReadFinishedImpl(NUM_STATEMENTS));
@@ -196,7 +195,8 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadBatchInCoroutineThrowsOnTimeou
return FakeFutureWithCallback{res};
});
EXPECT_CALL(
handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>()))
handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
)
.Times(1);
EXPECT_CALL(*counters, registerReadStartedImpl(NUM_STATEMENTS));
EXPECT_CALL(*counters, registerReadErrorImpl(NUM_STATEMENTS));
@@ -219,7 +219,8 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadBatchInCoroutineThrowsOnInvali
return FakeFutureWithCallback{res};
});
EXPECT_CALL(
handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>()))
handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
)
.Times(1);
EXPECT_CALL(*counters, registerReadStartedImpl(NUM_STATEMENTS));
EXPECT_CALL(*counters, registerReadErrorImpl(NUM_STATEMENTS));
@@ -244,7 +245,8 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadBatchInCoroutineMarksBusyIfReq
return FakeFutureWithCallback{};
});
EXPECT_CALL(
handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>()))
handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
)
.Times(1);
EXPECT_CALL(*counters, registerReadStartedImpl(NUM_STATEMENTS));
EXPECT_CALL(*counters, registerReadFinishedImpl(NUM_STATEMENTS));
@@ -270,7 +272,9 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadEachInCoroutineSuccessful)
handle,
asyncExecute(
A<FakeStatement const&>(),
A<std::function<void(FakeResultOrError)>&&>()))
A<std::function<void(FakeResultOrError)>&&>()
)
)
.Times(NUM_STATEMENTS); // once per statement
EXPECT_CALL(*counters, registerReadStartedImpl(NUM_STATEMENTS));
EXPECT_CALL(*counters, registerReadFinishedImpl(NUM_STATEMENTS));
@@ -289,12 +293,9 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadEachInCoroutineThrowsOnFailure
ON_CALL(handle, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
.WillByDefault([&callCount](auto const&, auto&& cb) {
if (callCount == 1)
{ // error happens on one of the entries
if (callCount == 1) { // error happens on one of the entries
cb({CassandraError{"invalid data", CASS_ERROR_LIB_INVALID_DATA}});
}
else
{
} else {
cb({}); // pretend we got data
}
++callCount;
@@ -304,7 +305,9 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadEachInCoroutineThrowsOnFailure
handle,
asyncExecute(
A<FakeStatement const&>(),
A<std::function<void(FakeResultOrError)>&&>()))
A<std::function<void(FakeResultOrError)>&&>()
)
)
.Times(NUM_STATEMENTS); // once per statement
EXPECT_CALL(*counters, registerReadStartedImpl(NUM_STATEMENTS));
EXPECT_CALL(*counters, registerReadErrorImpl(1));
@@ -368,7 +371,9 @@ TEST_F(BackendCassandraExecutionStrategyTest, WriteMultipleAndCallSyncSucceeds)
handle,
asyncExecute(
A<std::vector<FakeStatement> const&>(),
A<std::function<void(FakeResultOrError)>&&>()))
A<std::function<void(FakeResultOrError)>&&>()
)
)
.Times(totalRequests); // one per write call
EXPECT_CALL(*counters, registerWriteStarted()).Times(totalRequests);
EXPECT_CALL(*counters, registerWriteFinished()).Times(totalRequests);

View File

@@ -28,9 +28,7 @@ using namespace data::cassandra;
using namespace data::cassandra::detail;
using namespace testing;
class BackendCassandraRetryPolicyTest : public SyncAsioContextTest
{
};
class BackendCassandraRetryPolicyTest : public SyncAsioContextTest {};
TEST_F(BackendCassandraRetryPolicyTest, ShouldRetryAlwaysTrue)
{
@@ -41,8 +39,7 @@ TEST_F(BackendCassandraRetryPolicyTest, ShouldRetryAlwaysTrue)
// this policy actually always returns true
auto const err = CassandraError{"ok", CASS_OK};
for (auto i = 0; i < 1024; ++i)
{
for (auto i = 0; i < 1024; ++i) {
EXPECT_TRUE(retryPolicy.shouldRetry(err));
}
}

View File

@@ -36,9 +36,7 @@ namespace json = boost::json;
using namespace data::cassandra;
class SettingsProviderTest : public NoLoggerFixture
{
};
class SettingsProviderTest : public NoLoggerFixture {};
TEST_F(SettingsProviderTest, Defaults)
{
@@ -125,7 +123,8 @@ TEST_F(SettingsProviderTest, CertificateConfig)
"contact_points": "127.0.0.1",
"certfile": "{}"
}})",
file.path))};
file.path
))};
SettingsProvider const provider{cfg};
auto const settings = provider.getSettings();

View File

@@ -27,12 +27,9 @@
using namespace data::cassandra;
using namespace data::cassandra::detail;
struct FakeResult
{
};
struct FakeResult {};
struct FakeResultOrError
{
struct FakeResultOrError {
CassandraError err{"<default>", CASS_OK};
operator bool() const
@@ -53,20 +50,13 @@ struct FakeResultOrError
}
};
struct FakeMaybeError
{
};
struct FakeMaybeError {};
struct FakeStatement
{
};
struct FakeStatement {};
struct FakePreparedStatement
{
};
struct FakePreparedStatement {};
struct FakeFuture
{
struct FakeFuture {
FakeResultOrError data;
FakeResultOrError
@@ -82,12 +72,9 @@ struct FakeFuture
}
};
struct FakeFutureWithCallback : public FakeFuture
{
};
struct FakeFutureWithCallback : public FakeFuture {};
struct MockHandle
{
struct MockHandle {
using ResultOrErrorType = FakeResultOrError;
using MaybeErrorType = FakeMaybeError;
using FutureWithCallbackType = FakeFutureWithCallback;
@@ -100,27 +87,30 @@ struct MockHandle
FutureWithCallbackType,
asyncExecute,
(StatementType const&, std::function<void(ResultOrErrorType)>&&),
(const));
(const)
);
MOCK_METHOD(
FutureWithCallbackType,
asyncExecute,
(std::vector<StatementType> const&, std::function<void(ResultOrErrorType)>&&),
(const));
(const)
);
MOCK_METHOD(ResultOrErrorType, execute, (StatementType const&), (const));
};
struct FakeRetryPolicy
{
struct FakeRetryPolicy {
FakeRetryPolicy(boost::asio::io_context&){}; // required by concept
std::chrono::milliseconds calculateDelay(uint32_t /* attempt */)
std::chrono::milliseconds
calculateDelay(uint32_t /* attempt */)
{
return std::chrono::milliseconds{1};
}
bool shouldRetry(CassandraError) const
bool
shouldRetry(CassandraError) const
{
return false;
}