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>
59 testcase(
"testSingleDownloadAndStateDB");
65 section.set(
"path", tempDir.
path());
66 section.set(
"max_historical_shards",
"20");
67 c->setupControl(
true,
true,
true);
71 BEAST_EXPECT(handler);
74 std::string const rawUrl =
"https://foo:443/1.tar.lz4";
78 handler->add(1, {url, rawUrl});
83 auto& session{handler->sqliteDB_->getSession()};
85 soci::rowset<soci::row> rs =
86 (session.prepare <<
"SELECT * FROM State;");
90 for (
auto it = rs.begin(); it != rs.end(); ++it, ++rowCount)
92 BEAST_EXPECT(it->get<
int>(0) == 1);
96 BEAST_EXPECT(rowCount == 1);
108 testcase(
"testDownloadsAndStateDB");
114 section.set(
"path", tempDir.
path());
115 section.set(
"max_historical_shards",
"20");
116 c->setupControl(
true,
true,
true);
120 BEAST_EXPECT(handler);
124 {1,
"https://foo:443/1.tar.lz4"},
125 {2,
"https://foo:443/2.tar.lz4"},
126 {3,
"https://foo:443/3.tar.lz4"}};
128 for (
auto const& entry : dl)
132 handler->add(entry.first, {url, entry.second});
138 auto& session{handler->sqliteDB_->getSession()};
139 soci::rowset<soci::row> rs =
140 (session.prepare <<
"SELECT * FROM State;");
143 for (
auto it = rs.begin(); it != rs.end(); ++it, ++pos)
145 BEAST_EXPECT(it->get<
int>(0) == dl[pos].first);
146 BEAST_EXPECT(it->get<
std::string>(1) == dl[pos].second);
149 BEAST_EXPECT(pos == dl.size());
162 testcase(
"testDownloadsAndFileSystem");
168 section.set(
"path", tempDir.
path());
169 section.set(
"max_historical_shards",
"20");
170 section.set(
"ledgers_per_shard",
"256");
171 section.set(
"earliest_seq",
"257");
173 sectionNode.set(
"earliest_seq",
"257");
174 c->setupControl(
true,
true,
true);
184 (numberOfDownloads + 1);
191 BEAST_EXPECT(handler);
195 auto host = server->local_endpoint().address().to_string();
199 Downloads const dl = [count = numberOfDownloads, &host, &port] {
202 for (
int i = 1; i <= count; ++i)
206 (boost::format(
"https://%s:%d/%d.tar.lz4") % host % port %
214 for (
auto const& entry : dl)
218 handler->add(entry.first, {url, entry.second});
221 BEAST_EXPECT(handler->start());
229 boost::filesystem::exists(stateDir) || handler->archives_.empty());
231 using namespace std::chrono_literals;
234 while (!handler->archives_.empty())
239 if (waitMax -= 1s; waitMax <= 0s)
248 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
259 testcase(
"testDownloadsAndRestart");
266 section.set(
"path", tempDir.
path());
267 section.set(
"max_historical_shards",
"20");
268 section.set(
"ledgers_per_shard",
"256");
269 section.set(
"earliest_seq",
"257");
271 sectionNode.set(
"earliest_seq",
"257");
272 c->setupControl(
true,
true,
true);
282 (numberOfDownloads + 1);
289 BEAST_EXPECT(handler);
294 auto host = server->local_endpoint().address().to_string();
298 Downloads const dl = [count = numberOfDownloads, &host, &port] {
301 for (
int i = 1; i <= count; ++i)
305 (boost::format(
"https://%s:%d/%d.tar.lz4") % host %
313 for (
auto const& entry : dl)
317 handler->add(entry.first, {url, entry.second});
323 boost::filesystem::copy_file(
327 BEAST_EXPECT(handler->start());
332 boost::filesystem::exists(stateDir) ||
333 handler->archives_.empty());
335 using namespace std::chrono_literals;
338 while (!handler->archives_.empty())
343 if (waitMax -= 1s; waitMax <= 0s)
352 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
354 boost::filesystem::create_directory(stateDir);
356 boost::filesystem::copy_file(
363 section.set(
"path", tempDir.
path());
364 section.set(
"max_historical_shards",
"20");
365 section.set(
"ledgers_per_shard",
"256");
366 section.set(
"shard_verification_retry_interval",
"1");
367 section.set(
"shard_verification_max_attempts",
"10000");
368 section.set(
"earliest_seq",
"257");
370 sectionNode.set(
"earliest_seq",
"257");
371 c->setupControl(
true,
true,
true);
381 (numberOfDownloads + 1);
396 boost::filesystem::exists(stateDir) || handler->archives_.empty());
398 using namespace std::chrono_literals;
401 while (!handler->archives_.empty())
406 if (waitMax -= 1s; waitMax <= 0s)
415 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
423 testcase(
"testShardCountFailure");
431 section.set(
"path", tempDir.
path());
432 section.set(
"max_historical_shards",
"1");
433 section.set(
"ledgers_per_shard",
"256");
434 section.set(
"earliest_seq",
"257");
436 sectionNode.set(
"earliest_seq",
"257");
437 c->setupControl(
true,
true,
true);
440 jtx::Env env(*
this, std::move(c), std::move(logs));
448 (numberOfDownloads + 1);
455 BEAST_EXPECT(handler);
460 auto host = server->local_endpoint().address().to_string();
464 Downloads const dl = [count = numberOfDownloads, &host, &port] {
467 for (
int i = 1; i <= count; ++i)
471 (boost::format(
"https://%s:%d/%d.tar.lz4") % host %
479 for (
auto const& entry : dl)
483 handler->add(entry.first, {url, entry.second});
486 BEAST_EXPECT(!handler->start());
491 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
494 auto const expectedErrorMessage =
495 "shards 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 maximum number of historical "
498 capturedLogs.
find(expectedErrorMessage) != std::string::npos);
505 section.set(
"path", tempDir.
path());
506 section.set(
"max_historical_shards",
"0");
507 section.set(
"ledgers_per_shard",
"256");
508 section.set(
"earliest_seq",
"257");
510 sectionNode.set(
"earliest_seq",
"257");
511 c->setupControl(
true,
true,
true);
514 jtx::Env env(*
this, std::move(c), std::move(logs));
522 ((numberOfDownloads * 3) + 1);
529 BEAST_EXPECT(handler);
534 auto host = server->local_endpoint().address().to_string();
538 Downloads const dl = [count = numberOfDownloads, &host, &port] {
541 for (
int i = 1; i <= count; ++i)
545 (boost::format(
"https://%s:%d/%d.tar.lz4") % host %
553 for (
auto const& entry : dl)
557 handler->add(entry.first, {url, entry.second});
560 BEAST_EXPECT(!handler->start());
565 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
568 auto const expectedErrorMessage2 =
569 "shard 1 maximum number of historical shards reached";
571 capturedLogs.
find(expectedErrorMessage2) != std::string::npos);
580 testcase(
"testRedundantShardFailure");
588 section.set(
"path", tempDir.
path());
589 section.set(
"max_historical_shards",
"1");
590 section.set(
"ledgers_per_shard",
"256");
591 section.set(
"earliest_seq",
"257");
593 sectionNode.set(
"earliest_seq",
"257");
594 c->setupControl(
true,
true,
true);
609 (numberOfDownloads + 1);
618 BEAST_EXPECT(handler);
623 auto host = server->local_endpoint().address().to_string();
627 Downloads const dl = [count = numberOfDownloads, &host, &port] {
630 for (
int i = 1; i <= count; ++i)
634 (boost::format(
"https://%s:%d/%d.tar.lz4") % host %
642 for (
auto const& entry : dl)
646 handler->add(entry.first, {url, entry.second});
649 BEAST_EXPECT(!handler->start());
654 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
657 auto const expectedErrorMessage =
658 "shard 1 is already queued for import";
660 capturedLogs.
find(expectedErrorMessage) != std::string::npos);