NetworkedApplications: select the durable SQLite profile via storage_path
This commit is contained in:
1 parent
686f73ec9d
commit
e6aec57ad8
3 files changed
+79
-2
No files matched your search
@@ -4,7 +4,9 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -160,6 +162,68 @@ namespace
|
||||
assert(app->stop().has_value());
|
||||
assert(app->admin_bound_port() == 0);
|
||||
}
|
||||
|
||||
void durable_profile_survives_restart()
|
||||
{
|
||||
const auto directory = std::filesystem::temp_directory_path() /
|
||||
("void-netapp-" + std::to_string(::getpid()));
|
||||
std::filesystem::remove_all(directory);
|
||||
std::filesystem::create_directories(directory);
|
||||
const std::string path = (directory / "kv.db").string();
|
||||
|
||||
{
|
||||
ApplicationResources resources;
|
||||
resources.ownership = ResourceOwnership::Managed;
|
||||
NetworkedConfig config;
|
||||
config.listen_address = "127.0.0.1:0";
|
||||
config.bearer_token = "secret";
|
||||
config.storage_path = path;
|
||||
auto app = NetworkedApplication::create(resources, config);
|
||||
assert(app.has_value());
|
||||
assert(app->start().has_value());
|
||||
|
||||
Void::Net::HttpClient client;
|
||||
const std::string base =
|
||||
"http://127.0.0.1:" + std::to_string(app->health().bound_port);
|
||||
Void::Net::Request put;
|
||||
put.method = Void::Net::Method::Put;
|
||||
put.url = base + "/v1/kv/persist";
|
||||
put.body = std::string{"durable"};
|
||||
put.headers.push_back(
|
||||
Void::Net::Header{"authorization", "Bearer secret"});
|
||||
put.headers.push_back(Void::Net::Header{"x-request-id", "p1"});
|
||||
put.headers.push_back(Void::Net::Header{"if-none-match", "*"});
|
||||
auto created = client.send(put);
|
||||
assert(created.has_value());
|
||||
assert(created->status == 200);
|
||||
assert(app->stop().has_value());
|
||||
}
|
||||
|
||||
{
|
||||
ApplicationResources resources;
|
||||
resources.ownership = ResourceOwnership::Managed;
|
||||
NetworkedConfig config;
|
||||
config.listen_address = "127.0.0.1:0";
|
||||
config.bearer_token = "secret";
|
||||
config.storage_path = path;
|
||||
auto app = NetworkedApplication::create(resources, config);
|
||||
assert(app.has_value());
|
||||
assert(app->start().has_value());
|
||||
|
||||
Void::Net::HttpClient client;
|
||||
const std::string base =
|
||||
"http://127.0.0.1:" + std::to_string(app->health().bound_port);
|
||||
auto got = client.get(
|
||||
base + "/v1/kv/persist",
|
||||
{Void::Net::Header{"authorization", "Bearer secret"}});
|
||||
assert(got.has_value());
|
||||
assert(got->status == 200);
|
||||
assert(got->body == "durable");
|
||||
assert(app->stop().has_value());
|
||||
}
|
||||
|
||||
std::filesystem::remove_all(directory);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
@@ -170,6 +234,7 @@ int main()
|
||||
embedded_requires_a_host();
|
||||
http_listener_serves_kv();
|
||||
admin_listener_is_separate();
|
||||
durable_profile_survives_restart();
|
||||
std::puts("networked-kv lifecycle ok");
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user