Skip to content

Commit

Permalink
Updated examples
Browse files Browse the repository at this point in the history
Signed-off-by: Zachary Edgell <[email protected]>
  • Loading branch information
zedgell committed Mar 27, 2024
1 parent a1843fd commit 3b06b4c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
14 changes: 0 additions & 14 deletions examples/distributed-lock/components/statestore.yml

This file was deleted.

24 changes: 17 additions & 7 deletions examples/distributed-lock/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,46 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let mut client = dapr::Client::<dapr::client::TonicClient>::connect(addr).await?;

let files = vec![("my-data", b"some-data".to_vec())];
let result = client
.lock(dapr::client::TryLockRequest {
store_name: "lockstore".to_string(),
resource_id: "some-data".to_string(),
lock_owner: "some-random-id".to_string(),
expiry_in_seconds: 60,
})
.await
.unwrap();

client.save_state("statestore", files).await.unwrap();
assert!(result.success);

println!("Successfully locked some-data");

let result = client
.lock(dapr::client::TryLockRequest {
store_name: "lockstore".to_string(),
resource_id: "my-data".to_string(),
resource_id: "some-data".to_string(),
lock_owner: "some-random-id".to_string(),
expiry_in_seconds: 60,
})
.await
.unwrap();

assert!(result.success);
assert!(!result.success);

println!("Successfully locked my-data");
println!("Unsuccessfully locked some-data");

let result = client
.unlock(dapr::client::UnlockRequest {
store_name: "lockstore".to_string(),
resource_id: "my-data".to_string(),
resource_id: "some-data".to_string(),
lock_owner: "some-random-id".to_string(),
})
.await
.unwrap();

assert_eq!(0, result.status);

println!("Successfully unlocked my-data");
println!("Successfully unlocked some-data");

Ok(())
}

0 comments on commit 3b06b4c

Please sign in to comment.