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/Env.h>
28 #include <test/jtx/TrustedPublisherServer.h>
29 #include <test/jtx/envconfig.h>
30 #include <test/nodestore/TestBase.h>
58 testcase(
"testSingleDownloadAndStateDB");
64 section.set(
"path", tempDir.
path());
65 section.set(
"max_size_gb",
"100");
66 c->setupControl(
true,
true,
true);
70 BEAST_EXPECT(handler);
73 std::string const rawUrl =
"https://foo:443/1.tar.lz4";
77 handler->add(1, {url, rawUrl});
82 auto& session{handler->sqliteDB_->getSession()};
84 soci::rowset<soci::row> rs =
85 (session.prepare <<
"SELECT * FROM State;");
89 for (
auto it = rs.begin(); it != rs.end(); ++it, ++rowCount)
91 BEAST_EXPECT(it->get<
int>(0) == 1);
95 BEAST_EXPECT(rowCount == 1);
107 testcase(
"testDownloadsAndStateDB");
113 section.set(
"path", tempDir.
path());
114 section.set(
"max_size_gb",
"100");
115 c->setupControl(
true,
true,
true);
119 BEAST_EXPECT(handler);
123 {1,
"https://foo:443/1.tar.lz4"},
124 {2,
"https://foo:443/2.tar.lz4"},
125 {3,
"https://foo:443/3.tar.lz4"}};
127 for (
auto const& entry : dl)
131 handler->add(entry.first, {url, entry.second});
137 auto& session{handler->sqliteDB_->getSession()};
138 soci::rowset<soci::row> rs =
139 (session.prepare <<
"SELECT * FROM State;");
142 for (
auto it = rs.begin(); it != rs.end(); ++it, ++pos)
144 BEAST_EXPECT(it->get<
int>(0) == dl[pos].first);
145 BEAST_EXPECT(it->get<
std::string>(1) == dl[pos].second);
148 BEAST_EXPECT(pos == dl.size());
161 testcase(
"testDownloadsAndFileSystem");
167 section.set(
"path", tempDir.
path());
168 section.set(
"max_size_gb",
"100");
169 section.set(
"ledgers_per_shard",
"256");
170 section.set(
"earliest_seq",
"257");
172 sectionNode.set(
"earliest_seq",
"257");
173 c->setupControl(
true,
true,
true);
183 (numberOfDownloads + 1);
190 BEAST_EXPECT(handler);
194 auto host = server->local_endpoint().address().to_string();
198 Downloads const dl = [count = numberOfDownloads, &host, &port] {
201 for (
int i = 1; i <= count; ++i)
205 (boost::format(
"https://%s:%d/%d.tar.lz4") % host % port %
213 for (
auto const& entry : dl)
217 handler->add(entry.first, {url, entry.second});
220 BEAST_EXPECT(handler->start());
228 boost::filesystem::exists(stateDir) || handler->archives_.empty());
230 using namespace std::chrono_literals;
233 while (!handler->archives_.empty())
238 if (waitMax -= 1s; waitMax <= 0s)
247 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
258 testcase(
"testDownloadsAndRestart");
265 section.set(
"path", tempDir.
path());
266 section.set(
"max_size_gb",
"100");
267 section.set(
"ledgers_per_shard",
"256");
268 section.set(
"earliest_seq",
"257");
270 sectionNode.set(
"earliest_seq",
"257");
271 c->setupControl(
true,
true,
true);
281 (numberOfDownloads + 1);
288 BEAST_EXPECT(handler);
293 auto host = server->local_endpoint().address().to_string();
297 Downloads const dl = [count = numberOfDownloads, &host, &port] {
300 for (
int i = 1; i <= count; ++i)
304 (boost::format(
"https://%s:%d/%d.tar.lz4") % host %
312 for (
auto const& entry : dl)
316 handler->add(entry.first, {url, entry.second});
322 boost::filesystem::copy_file(
326 BEAST_EXPECT(handler->start());
331 boost::filesystem::exists(stateDir) ||
332 handler->archives_.empty());
334 using namespace std::chrono_literals;
337 while (!handler->archives_.empty())
342 if (waitMax -= 1s; waitMax <= 0s)
351 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
353 boost::filesystem::create_directory(stateDir);
355 boost::filesystem::copy_file(
362 section.set(
"path", tempDir.
path());
363 section.set(
"max_size_gb",
"100");
364 section.set(
"ledgers_per_shard",
"256");
365 section.set(
"shard_verification_retry_interval",
"1");
366 section.set(
"shard_verification_max_attempts",
"10000");
367 section.set(
"earliest_seq",
"257");
369 sectionNode.set(
"earliest_seq",
"257");
370 c->setupControl(
true,
true,
true);
380 (numberOfDownloads + 1);
395 boost::filesystem::exists(stateDir) || handler->archives_.empty());
397 using namespace std::chrono_literals;
400 while (!handler->archives_.empty())
405 if (waitMax -= 1s; waitMax <= 0s)
414 BEAST_EXPECT(!boost::filesystem::exists(stateDir));