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>
55 testcase(
"testStateDatabase1");
62 section.set(
"path", tempDir.
path());
63 section.set(
"max_size_gb",
"100");
64 c->setupControl(
true,
true,
true);
69 BEAST_EXPECT(handler);
71 BEAST_EXPECT(handler->init());
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;");
87 uint64_t rowCount = 0;
89 for (
auto it = rs.begin(); it != rs.end(); ++it, ++rowCount)
91 BEAST_EXPECT(it->get<
int>(0) == 1);
95 BEAST_EXPECT(rowCount == 1);
109 testcase(
"testStateDatabase2");
116 section.set(
"path", tempDir.
path());
117 section.set(
"max_size_gb",
"100");
118 c->setupControl(
true,
true,
true);
123 BEAST_EXPECT(handler);
125 BEAST_EXPECT(handler->init());
127 Downloads const dl = {{1,
"https://foo:443/1.tar.lz4"},
128 {2,
"https://foo:443/2.tar.lz4"},
129 {3,
"https://foo:443/3.tar.lz4"}};
131 for (
auto const& entry : dl)
135 handler->add(entry.first, {url, entry.second});
141 auto& session{handler->sqliteDB_->getSession()};
142 soci::rowset<soci::row> rs =
143 (session.prepare <<
"SELECT * FROM State;");
146 for (
auto it = rs.begin(); it != rs.end(); ++it, ++pos)
148 BEAST_EXPECT(it->get<
int>(0) == dl[pos].first);
149 BEAST_EXPECT(it->get<
std::string>(1) == dl[pos].second);
152 BEAST_EXPECT(pos == dl.size());
166 testcase(
"testStateDatabase3");
173 section.set(
"path", tempDir.
path());
174 section.set(
"max_size_gb",
"100");
175 c->setupControl(
true,
true,
true);
180 BEAST_EXPECT(handler);
182 BEAST_EXPECT(handler->init());
185 auto host = server.local_endpoint().address().to_string();
192 for (
int i = 1; i <= 10; ++i)
195 (boost::format(
"https://%s:%d/%d.tar.lz4") %
203 for (
auto const& entry : dl)
207 handler->add(entry.first, {url, entry.second});
210 BEAST_EXPECT(handler->start());
218 boost::filesystem::exists(stateDir) ||
219 handler->archives_.empty());
221 while (!handler->archives_.empty())
228 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
239 testcase(
"testStateDatabase4");
246 section.set(
"path", tempDir.
path());
247 section.set(
"max_size_gb",
"100");
248 c->setupControl(
true,
true,
true);
253 BEAST_EXPECT(handler);
255 BEAST_EXPECT(handler->init());
258 auto host = server.local_endpoint().address().to_string();
265 for (
int i = 1; i <= 10; ++i)
268 (boost::format(
"https://%s:%d/%d.tar.lz4") %
276 for (
auto const& entry : dl)
280 handler->add(entry.first, {url, entry.second});
286 boost::filesystem::copy_file(
290 BEAST_EXPECT(handler->start());
295 boost::filesystem::exists(stateDir) ||
296 handler->archives_.empty());
298 while (!handler->archives_.empty())
305 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
307 boost::filesystem::create_directory(stateDir);
309 boost::filesystem::copy_file(
320 section.set(
"path", tempDir.
path());
321 section.set(
"max_size_gb",
"100");
322 c->setupControl(
true,
true,
true);
339 boost::filesystem::exists(stateDir) || handler->archives_.empty());
341 while (!handler->archives_.empty())
348 BEAST_EXPECT(!boost::filesystem::exists(stateDir));