-
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.
Signed-off-by: mikeee <hey@mike.ee>
- Loading branch information
Showing
3 changed files
with
133 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
This example validates the resiliency 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 using the following command: | ||
|
||
<!-- STEP | ||
name: Run configuration app (expecting a fail) | ||
env: | ||
DAPR_GRPC_PORT: "3500" | ||
DAPR_API_MAX_RETRIES: "10" | ||
DAPR_API_TIMEOUT_MILLISECONDS: "10000" | ||
output_match_mode: substring | ||
expected_stdout_lines: | ||
- '' | ||
expected_stderr_lines: | ||
- 'TransportError' | ||
expected_return_code: 101 | ||
background: false | ||
sleep: 30 | ||
timeout_seconds: 30 | ||
--> | ||
|
||
```bash | ||
cargo run --example resiliency | ||
``` | ||
|
||
<!-- END_STEP --> | ||
|
||
The result should be that the request will fail. | ||
|
||
3. Run the example without the sidecar (this time in the background) | ||
|
||
<!-- STEP | ||
name: Run configuration app (expecting a success eventually) | ||
env: | ||
DAPR_GRPC_PORT: "3500" | ||
DAPR_API_MAX_RETRIES: "10" | ||
DAPR_API_TIMEOUT_MILLISECONDS: "10000" | ||
output_match_mode: substring | ||
expected_stdout_lines: | ||
- '== APP == Configuration value: ConfigurationItem { value: "world"' | ||
background: true | ||
sleep: 30 | ||
timeout_seconds: 30 | ||
--> | ||
|
||
```bash | ||
cargo run --example resiliency | ||
``` | ||
|
||
<!-- END_STEP --> | ||
|
||
|
||
|
||
4. 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 --> | ||
|
||
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,31 @@ | ||
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 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) | ||
} | ||
}; | ||
println!("debug"); | ||
|
||
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:?}"); | ||
|
||
Ok(()) | ||
} |