photoncloud-monorepo/flaredb/crates/flaredb-server/examples/test_cluster.rs
centra 8f94aee1fa Fix R8: Convert submodule gitlinks to regular directories
- Remove gitlinks (160000 mode) for chainfire, flaredb, iam
- Add workspace contents as regular tracked files
- Update flake.nix to use simple paths instead of builtins.fetchGit

This resolves the nix build failure where submodule directories
appeared empty in the nix store.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-09 16:51:20 +09:00

69 lines
2 KiB
Rust

use flaredb_proto::kvrpc::kv_cas_client::KvCasClient;
use flaredb_proto::kvrpc::{CasRequest, GetRequest};
use tonic::transport::Channel;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Testing CAS operations on node 1...");
// Connect to node 1
let channel = Channel::from_static("http://127.0.0.1:50051")
.connect()
.await?;
let mut client = KvCasClient::new(channel);
// Write key
println!("Writing key 'test-key' = 'hello-world'...");
let req = CasRequest {
key: b"test-key".to_vec(),
value: b"hello-world".to_vec(),
expected_version: 0,
namespace: "default".to_string(),
};
let resp = client.compare_and_swap(req).await?.into_inner();
println!(
"CAS response: success={}, version={}",
resp.success, resp.new_version
);
// Read back
println!("Reading key 'test-key'...");
let req = GetRequest {
key: b"test-key".to_vec(),
namespace: "default".to_string(),
};
let resp = client.get(req).await?.into_inner();
println!(
"Get response: found={}, value={:?}, version={}",
resp.found,
String::from_utf8_lossy(&resp.value),
resp.version
);
// Connect to node 2 and check if data is there
println!("\nConnecting to node 2...");
let channel2 = Channel::from_static("http://127.0.0.1:50052")
.connect()
.await?;
let mut client2 = KvCasClient::new(channel2);
let req = GetRequest {
key: b"test-key".to_vec(),
namespace: "default".to_string(),
};
match client2.get(req).await {
Ok(resp) => {
let resp = resp.into_inner();
println!(
"Node 2 Get response: found={}, value={:?}",
resp.found,
String::from_utf8_lossy(&resp.value)
);
}
Err(e) => {
println!("Node 2 error (expected if not leader): {}", e);
}
}
Ok(())
}