mirror of
https://github.com/logos-blockchain/logos-blockchain-testing.git
synced 2026-03-31 16:23:08 +00:00
74 lines
2.3 KiB
Rust
74 lines
2.3 KiB
Rust
use cfgsync_adapter::MaterializedArtifacts;
|
|
use cfgsync_artifacts::{ArtifactFile, ArtifactSet};
|
|
use cfgsync_core::NodeRegistration;
|
|
use cfgsync_runtime::{Client, OutputMap, serve};
|
|
use tempfile::tempdir;
|
|
use tokio::time::{Duration, sleep};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
let port = 4401;
|
|
let artifacts = MaterializedArtifacts::from_nodes([
|
|
(
|
|
"node-1".to_owned(),
|
|
ArtifactSet::new(vec![ArtifactFile::new("/config.yaml", "id: node-1\n")]),
|
|
),
|
|
(
|
|
"node-2".to_owned(),
|
|
ArtifactSet::new(vec![ArtifactFile::new("/config.yaml", "id: node-2\n")]),
|
|
),
|
|
])
|
|
.with_shared(ArtifactSet::new(vec![ArtifactFile::new(
|
|
"/shared/cluster.yaml",
|
|
"cluster: demo\n",
|
|
)]));
|
|
|
|
let server = tokio::spawn(async move { serve(port, artifacts).await });
|
|
|
|
// Give the server a moment to bind before clients register.
|
|
sleep(Duration::from_millis(100)).await;
|
|
|
|
let node_1_dir = tempdir()?;
|
|
let node_1_outputs = OutputMap::config_and_shared(
|
|
node_1_dir.path().join("config.yaml"),
|
|
node_1_dir.path().join("shared"),
|
|
);
|
|
let node_1 = NodeRegistration::new("node-1", "127.0.0.1".parse()?);
|
|
|
|
Client::new("http://127.0.0.1:4401")
|
|
.fetch_and_write(&node_1, &node_1_outputs)
|
|
.await?;
|
|
|
|
println!(
|
|
"node-1 config:\n{}",
|
|
std::fs::read_to_string(node_1_dir.path().join("config.yaml"))?
|
|
);
|
|
|
|
// A later node still uses the same registration/fetch flow. The artifacts
|
|
// were already known; registration only gates delivery.
|
|
sleep(Duration::from_millis(250)).await;
|
|
|
|
let node_2_dir = tempdir()?;
|
|
let node_2_outputs = OutputMap::config_and_shared(
|
|
node_2_dir.path().join("config.yaml"),
|
|
node_2_dir.path().join("shared"),
|
|
);
|
|
let node_2 = NodeRegistration::new("node-2", "127.0.0.2".parse()?);
|
|
|
|
Client::new("http://127.0.0.1:4401")
|
|
.fetch_and_write(&node_2, &node_2_outputs)
|
|
.await?;
|
|
|
|
println!(
|
|
"node-2 config:\n{}",
|
|
std::fs::read_to_string(node_2_dir.path().join("config.yaml"))?
|
|
);
|
|
println!(
|
|
"shared artifact:\n{}",
|
|
std::fs::read_to_string(node_2_dir.path().join("shared/shared/cluster.yaml"))?
|
|
);
|
|
|
|
server.abort();
|
|
Ok(())
|
|
}
|