0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2025-05-20 06:48:19 +00:00
Files
libsql/libsql-server/tests/namespaces/meta.rs
Lucio Franco b1da52c722 server: Add initial MetaStore
This PR adds a new internal metadata store for namespace configuration.
This internally uses a normal namespace so that the replica also get's
synchronized. This is just initial work there are a few more issues to
solve regarding replica's getting updated configs and some internal
hardening that needs to be done. Tracking issue for follow up work #768.

Closes #501
2023-12-12 10:38:45 -05:00

89 lines
2.2 KiB
Rust

use libsql::Database;
use serde_json::json;
use tempfile::tempdir;
use turmoil::Builder;
use crate::common::{http::Client, net::TurmoilConnector};
use super::make_primary;
#[test]
fn meta_store() {
let mut sim = Builder::new().build();
let tmp = tempdir().unwrap();
make_primary(&mut sim, tmp.path().to_path_buf());
sim.client("client", async {
let client = Client::new();
// STEP 1: create namespace and check that it can be read from
client
.post(
"http://primary:9090/v1/namespaces/foo/create",
json!({
"max_db_size": "5mb"
}),
)
.await?;
{
let foo = Database::open_remote_with_connector(
"http://foo.primary:8080",
"",
TurmoilConnector,
)?;
let foo_conn = foo.connect()?;
foo_conn.execute("select 1", ()).await.unwrap();
}
// STEP 2: update namespace config to block reads
client
.post(
"http://primary:9090/v1/namespaces/foo/config",
json!({
"block_reads": true,
"block_writes": false,
}),
)
.await?;
{
let foo = Database::open_remote_with_connector(
"http://foo.primary:8080",
"",
TurmoilConnector,
)?;
let foo_conn = foo.connect()?;
foo_conn.execute("select 1", ()).await.unwrap_err();
}
// STEP 3: update config again to un-block reads
client
.post(
"http://primary:9090/v1/namespaces/foo/config",
json!({
"block_reads": false,
"block_writes": false,
}),
)
.await?;
{
let foo = Database::open_remote_with_connector(
"http://foo.primary:8080",
"",
TurmoilConnector,
)?;
let foo_conn = foo.connect()?;
foo_conn.execute("select 1", ()).await.unwrap();
}
Ok(())
});
sim.run().unwrap();
}