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());
128 {1,
"https://foo:443/1.tar.lz4"},
129 {2,
"https://foo:443/2.tar.lz4"},
130 {3,
"https://foo:443/3.tar.lz4"}};
132 for (
auto const& entry : dl)
136 handler->add(entry.first, {url, entry.second});
142 auto& session{handler->sqliteDB_->getSession()};
143 soci::rowset<soci::row> rs =
144 (session.prepare <<
"SELECT * FROM State;");
147 for (
auto it = rs.begin(); it != rs.end(); ++it, ++pos)
149 BEAST_EXPECT(it->get<
int>(0) == dl[pos].first);
150 BEAST_EXPECT(it->get<
std::string>(1) == dl[pos].second);
153 BEAST_EXPECT(pos == dl.size());
167 testcase(
"testStateDatabase3");
174 section.set(
"path", tempDir.
path());
175 section.set(
"max_size_gb",
"100");
176 c->setupControl(
true,
true,
true);
181 BEAST_EXPECT(handler);
183 BEAST_EXPECT(handler->init());
186 auto host = server.local_endpoint().address().to_string();
193 for (
int i = 1; i <= 10; ++i)
197 (boost::format(
"https://%s:%d/%d.tar.lz4") % host %
205 for (
auto const& entry : dl)
209 handler->add(entry.first, {url, entry.second});
212 BEAST_EXPECT(handler->start());
220 boost::filesystem::exists(stateDir) ||
221 handler->archives_.empty());
223 while (!handler->archives_.empty())
230 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
241 testcase(
"testStateDatabase4");
248 section.set(
"path", tempDir.
path());
249 section.set(
"max_size_gb",
"100");
250 c->setupControl(
true,
true,
true);
255 BEAST_EXPECT(handler);
257 BEAST_EXPECT(handler->init());
260 auto host = server.local_endpoint().address().to_string();
267 for (
int i = 1; i <= 10; ++i)
271 (boost::format(
"https://%s:%d/%d.tar.lz4") % host %
279 for (
auto const& entry : dl)
283 handler->add(entry.first, {url, entry.second});
289 boost::filesystem::copy_file(
293 BEAST_EXPECT(handler->start());
298 boost::filesystem::exists(stateDir) ||
299 handler->archives_.empty());
301 while (!handler->archives_.empty())
308 BEAST_EXPECT(!boost::filesystem::exists(stateDir));
310 boost::filesystem::create_directory(stateDir);
312 boost::filesystem::copy_file(
323 section.set(
"path", tempDir.
path());
324 section.set(
"max_size_gb",
"100");
325 c->setupControl(
true,
true,
true);
342 boost::filesystem::exists(stateDir) || handler->archives_.empty());
344 while (!handler->archives_.empty())
351 BEAST_EXPECT(!boost::filesystem::exists(stateDir));