20 #include <ripple/beast/utility/temp_dir.h>
21 #include <ripple/core/ConfigSections.h>
22 #include <ripple/nodestore/DummyScheduler.h>
23 #include <ripple/nodestore/Manager.h>
24 #include <ripple/nodestore/impl/DecodedBlob.h>
25 #include <ripple/protocol/jss.h>
26 #include <ripple/rpc/ShardArchiveHandler.h>
27 #include <test/jtx/CaptureLogs.h>
28 #include <test/jtx/Env.h>
29 #include <test/jtx/TrustedPublisherServer.h>
30 #include <test/jtx/envconfig.h>
31 #include <test/nodestore/TestBase.h>
61 testcase(
"testSingleDownloadAndStateDB");
67 section.set(
"path", tempDir.
path());
68 section.set(
"max_historical_shards",
"20");
69 c->setupControl(
true,
true,
true);
73 BEAST_EXPECT(handler);
76 std::string const rawUrl =
"https://foo:443/1.tar.lz4";
80 handler->add(1, {url, rawUrl});
85 auto& session{handler->sqliteDB_->getSession()};
87 soci::rowset<soci::row> rs =
88 (session.prepare <<
"SELECT * FROM State;");
92 for (
auto it = rs.begin(); it != rs.end(); ++it, ++rowCount)
94 BEAST_EXPECT(it->get<
int>(0) == 1);
98 BEAST_EXPECT(rowCount == 1);
110 testcase(
"testDownloadsAndStateDB");
116 section.set(
"path", tempDir.
path());
117 section.set(
"max_historical_shards",
"20");
118 c->setupControl(
true,
true,
true);
122 BEAST_EXPECT(handler);
126 {1,
"https://foo:443/1.tar.lz4"},
127 {2,
"https://foo:443/2.tar.lz4"},
128 {3,
"https://foo:443/3.tar.lz4"}};
130 for (
auto const& entry : dl)
134 handler->add(entry.first, {url, entry.second});
140 auto& session{handler->sqliteDB_->getSession()};
141 soci::rowset<soci::row> rs =
142 (session.prepare <<
"SELECT * FROM State;");
145 for (
auto it = rs.begin(); it != rs.end(); ++it, ++pos)
147 BEAST_EXPECT(it->get<
int>(0) == dl[pos].first);
148 BEAST_EXPECT(it->get<
std::string>(1) == dl[pos].second);
151 BEAST_EXPECT(pos == dl.size());
164 testcase(
"testDownloadsAndFileSystem");
170 section.set(
"path", tempDir.
path());
171 section.set(
"max_historical_shards",
"20");
172 section.set(
"ledgers_per_shard",
"256");
173 section.set(
"earliest_seq",
"257");
175 sectionNode.set(
"earliest_seq",
"257");
176 c->setupControl(
true,
true,
true);
186 (numberOfDownloads + 1);
193 BEAST_EXPECT(handler);
197 auto host = server->local_endpoint().address().to_string();
201 Downloads const dl = [count = numberOfDownloads, &host, &port] {
204 for (
int i = 1; i <= count; ++i)
208 (boost::format(
"https://%s:%d/%d.tar.lz4") % host % port %
216 for (
auto const& entry : dl)
220 handler->add(entry.first, {url, entry.second});
223 BEAST_EXPECT(handler->start());
231 boost::filesystem::exists(stateDir) || handler->archives_.empty());
233 using namespace std::chrono_literals;
236 while (!handler->archives_.empty())
241 if (waitMax -= 1s; waitMax <= 0s)
250 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
261 testcase(
"testDownloadsAndRestart");
268 section.set(
"path", tempDir.
path());
269 section.set(
"max_historical_shards",
"20");
270 section.set(
"ledgers_per_shard",
"256");
271 section.set(
"earliest_seq",
"257");
273 sectionNode.set(
"earliest_seq",
"257");
274 c->setupControl(
true,
true,
true);
284 (numberOfDownloads + 1);
291 BEAST_EXPECT(handler);
296 auto host = server->local_endpoint().address().to_string();
300 Downloads const dl = [count = numberOfDownloads, &host, &port] {
303 for (
int i = 1; i <= count; ++i)
307 (boost::format(
"https://%s:%d/%d.tar.lz4") % host %
315 for (
auto const& entry : dl)
319 handler->add(entry.first, {url, entry.second});
325 boost::filesystem::copy_file(
329 BEAST_EXPECT(handler->start());
334 boost::filesystem::exists(stateDir) ||
335 handler->archives_.empty());
337 using namespace std::chrono_literals;
340 while (!handler->archives_.empty())
345 if (waitMax -= 1s; waitMax <= 0s)
354 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
356 boost::filesystem::create_directory(stateDir);
358 boost::filesystem::copy_file(
365 section.set(
"path", tempDir.
path());
366 section.set(
"max_historical_shards",
"20");
367 section.set(
"ledgers_per_shard",
"256");
368 section.set(
"shard_verification_retry_interval",
"1");
369 section.set(
"shard_verification_max_attempts",
"10000");
370 section.set(
"earliest_seq",
"257");
372 sectionNode.set(
"earliest_seq",
"257");
373 c->setupControl(
true,
true,
true);
383 (numberOfDownloads + 1);
398 boost::filesystem::exists(stateDir) || handler->archives_.empty());
400 using namespace std::chrono_literals;
403 while (!handler->archives_.empty())
408 if (waitMax -= 1s; waitMax <= 0s)
417 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
425 testcase(
"testShardCountFailure");
433 section.set(
"path", tempDir.
path());
434 section.set(
"max_historical_shards",
"1");
435 section.set(
"ledgers_per_shard",
"256");
436 section.set(
"earliest_seq",
"257");
438 sectionNode.set(
"earliest_seq",
"257");
439 c->setupControl(
true,
true,
true);
442 jtx::Env env(*
this, std::move(c), std::move(logs));
450 (numberOfDownloads + 1);
457 BEAST_EXPECT(handler);
462 auto host = server->local_endpoint().address().to_string();
466 Downloads const dl = [count = numberOfDownloads, &host, &port] {
469 for (
int i = 1; i <= count; ++i)
473 (boost::format(
"https://%s:%d/%d.tar.lz4") % host %
481 for (
auto const& entry : dl)
485 handler->add(entry.first, {url, entry.second});
488 BEAST_EXPECT(!handler->start());
493 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
496 auto const expectedErrorMessage =
497 "shards 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 maximum number of historical "
500 capturedLogs.
find(expectedErrorMessage) != std::string::npos);
507 section.set(
"path", tempDir.
path());
508 section.set(
"max_historical_shards",
"0");
509 section.set(
"ledgers_per_shard",
"256");
510 section.set(
"earliest_seq",
"257");
512 sectionNode.set(
"earliest_seq",
"257");
513 c->setupControl(
true,
true,
true);
516 jtx::Env env(*
this, std::move(c), std::move(logs));
524 ((numberOfDownloads * 3) + 1);
531 BEAST_EXPECT(handler);
536 auto host = server->local_endpoint().address().to_string();
540 Downloads const dl = [count = numberOfDownloads, &host, &port] {
543 for (
int i = 1; i <= count; ++i)
547 (boost::format(
"https://%s:%d/%d.tar.lz4") % host %
555 for (
auto const& entry : dl)
559 handler->add(entry.first, {url, entry.second});
562 BEAST_EXPECT(!handler->start());
567 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
570 auto const expectedErrorMessage2 =
571 "shard 1 maximum number of historical shards reached";
573 capturedLogs.
find(expectedErrorMessage2) != std::string::npos);
582 testcase(
"testRedundantShardFailure");
590 section.set(
"path", tempDir.
path());
591 section.set(
"max_historical_shards",
"1");
592 section.set(
"ledgers_per_shard",
"256");
593 section.set(
"earliest_seq",
"257");
595 sectionNode.set(
"earliest_seq",
"257");
596 c->setupControl(
true,
true,
true);
611 (numberOfDownloads + 1);
620 BEAST_EXPECT(handler);
625 auto host = server->local_endpoint().address().to_string();
629 Downloads const dl = [count = numberOfDownloads, &host, &port] {
632 for (
int i = 1; i <= count; ++i)
636 (boost::format(
"https://%s:%d/%d.tar.lz4") % host %
644 for (
auto const& entry : dl)
648 handler->add(entry.first, {url, entry.second});
651 BEAST_EXPECT(!handler->start());
656 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
659 auto const expectedErrorMessage =
660 "shard 1 is already queued for import";
662 capturedLogs.
find(expectedErrorMessage) != std::string::npos);