Skip to content

Commit

Permalink
Merge pull request #136 from quickwit-oss/raphael_test
Browse files Browse the repository at this point in the history
chitchat-test: allow mark for deletion and pretty-print json.
  • Loading branch information
RaphaelMarinier authored Mar 7, 2024
2 parents ed8ec92 + f13a8a8 commit a88cbf7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions chitchat-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ to test the chitchat crate.

```bash
# First server
cargo run -- --listen_addr localhost:10000
cargo run -- --listen_addr 127.0.0.1:10000
# Second server
cargo run -- --listen_addr localhost:10001 --seed localhost:10000
cargo run -- --listen_addr 127.0.0.1:10001 --seed 127.0.0.1:10000
```

## Startup Flags that are optional
Expand Down
17 changes: 14 additions & 3 deletions chitchat-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cool_id_generator::Size;
use poem::listener::TcpListener;
use poem::{Route, Server};
use poem_openapi::param::Query;
use poem_openapi::payload::Json;
use poem_openapi::payload::{Json, PlainText};
use poem_openapi::{OpenApi, OpenApiService};
use structopt::StructOpt;
use tokio::sync::Mutex;
Expand All @@ -22,15 +22,15 @@ struct Api {
impl Api {
/// Chitchat state
#[oai(path = "/", method = "get")]
async fn index(&self) -> Json<serde_json::Value> {
async fn index(&self) -> PlainText<String> {
let chitchat_guard = self.chitchat.lock().await;
let response = ApiResponse {
cluster_id: chitchat_guard.cluster_id().to_string(),
cluster_state: chitchat_guard.state_snapshot(),
live_nodes: chitchat_guard.live_nodes().cloned().collect::<Vec<_>>(),
dead_nodes: chitchat_guard.dead_nodes().cloned().collect::<Vec<_>>(),
};
Json(serde_json::to_value(&response).unwrap())
PlainText(serde_json::to_string_pretty(&response).unwrap())
}

/// Sets a key-value pair on this node (without validation).
Expand All @@ -43,6 +43,17 @@ impl Api {

Json(serde_json::to_value(&SetKeyValueResponse { status: true }).unwrap())
}

/// Marks a key for deletion on this node (without validation).
#[oai(path = "/mark_for_deletion/", method = "get")]
async fn mark_for_deletion(&self, key: Query<String>) -> Json<serde_json::Value> {
let mut chitchat_guard = self.chitchat.lock().await;

let cc_state = chitchat_guard.self_node_state();
cc_state.mark_for_deletion(key.as_str());

Json(serde_json::to_value(&SetKeyValueResponse { status: true }).unwrap())
}
}

#[derive(Debug, StructOpt)]
Expand Down

0 comments on commit a88cbf7

Please sign in to comment.