-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: implement instance resiliency test case
Signed-off-by: mikeee <[email protected]>
- Loading branch information
Showing
6 changed files
with
164 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
This example validates the resiliency of the instantiated client and does not | ||
demonstrate any extra functionality. It is based off the configuration example | ||
to connect to the sidecar and make a call for a configuration item stored in | ||
redis. | ||
|
||
1. Insert a key with the value `hello` to redis using the following command: | ||
|
||
|
||
<!-- STEP | ||
name: Insert test configuration item | ||
output_match_mode: substring | ||
expected_stdout_lines: | ||
- 'OK' | ||
background: false | ||
sleep: 5 | ||
timeout_seconds: 5 | ||
--> | ||
|
||
```bash | ||
docker exec dapr_redis redis-cli MSET hello "world" | ||
``` | ||
|
||
<!-- END_STEP --> | ||
|
||
2. Run the example without the sidecar | ||
|
||
<!-- STEP | ||
name: Run configuration app | ||
env: | ||
DAPR_GRPC_PORT: "3500" | ||
DAPR_API_MAX_RETRIES: "10" | ||
DAPR_API_TIMEOUT_MILLISECONDS: "10000" | ||
output_match_mode: substring | ||
expected_stdout_lines: | ||
- 'Configuration value: ConfigurationItem { value: "world"' | ||
- 'Configuration value: ConfigurationItem { value: "world2"' | ||
background: true | ||
sleep: 30 | ||
timeout_seconds: 30 | ||
--> | ||
|
||
```bash | ||
cargo run --example resiliency-instance | ||
``` | ||
|
||
<!-- END_STEP --> | ||
|
||
3. Run the Dapr sidecar | ||
|
||
<!-- STEP | ||
name: Run Dapr sidecar | ||
output_match_mode: substring | ||
expected_stdout_lines: | ||
- '' | ||
background: true | ||
sleep: 10 | ||
timeout_seconds: 10 | ||
--> | ||
|
||
```bash | ||
dapr run --app-id=rustapp --resources-path ../components --dapr-grpc-port 3500 | ||
``` | ||
|
||
<!-- END_STEP --> | ||
|
||
4. Update the hello key with the value `world2` to redis using the following command: | ||
|
||
|
||
<!-- STEP | ||
name: Update test configuration item | ||
output_match_mode: substring | ||
expected_stdout_lines: | ||
- 'OK' | ||
background: false | ||
sleep: 5 | ||
timeout_seconds: 5 | ||
--> | ||
|
||
```bash | ||
docker exec dapr_redis redis-cli MSET hello "world2" | ||
``` | ||
|
||
<!-- END_STEP --> | ||
|
||
5. Run the Dapr sidecar (for the second time) | ||
|
||
<!-- STEP | ||
name: Run Dapr sidecar | ||
output_match_mode: substring | ||
expected_stdout_lines: | ||
- '' | ||
background: true | ||
sleep: 10 | ||
timeout_seconds: 10 | ||
--> | ||
|
||
```bash | ||
dapr run --app-id=rustapp --resources-path ../components --dapr-grpc-port 3500 | ||
``` | ||
|
||
<!-- END_STEP --> | ||
The example app should make contact with the Dapr sidecar and the result should | ||
be returned from the configuration request successfully. | ||
|
||
``` | ||
Configuration value: ConfigurationItem { value: "world", version: "", metadata: {} } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::{ | ||
thread, | ||
time::{Duration, Instant}, | ||
}; | ||
|
||
const CONFIGSTORE_NAME: &str = "configstore"; | ||
type DaprClient = dapr::Client<dapr::client::TonicClient>; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
// Set the Dapr address | ||
let addr = "https://127.0.0.1".to_string(); | ||
|
||
// Create the client | ||
let start_time = Instant::now(); | ||
let mut client = match DaprClient::connect(addr).await { | ||
Ok(client) => { | ||
println!("connected to dapr sidecar"); | ||
client | ||
} | ||
Err(error) => { | ||
panic!("failed to connect to dapr sidecar: {:?}", error) | ||
} | ||
}; | ||
let client_start_duration = start_time.elapsed(); | ||
println!("Client connection took: {:?}", client_start_duration); | ||
|
||
let key = String::from("hello"); | ||
|
||
// get key-value pair in the state store | ||
let response = client | ||
.get_configuration(CONFIGSTORE_NAME, vec![(&key)], None) | ||
.await?; | ||
let val = response.items.get("hello").unwrap(); | ||
println!("Configuration value: {val:?}"); | ||
|
||
thread::sleep(Duration::from_secs(10)); | ||
println!("app slept for 15 seconds"); | ||
|
||
let response = client | ||
.get_configuration(CONFIGSTORE_NAME, vec![(&key)], None) | ||
.await?; | ||
let val = response.items.get("hello").unwrap(); | ||
println!("Configuration value: {val:?}"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters