-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathmain.rs
More file actions
53 lines (41 loc) · 1.45 KB
/
main.rs
File metadata and controls
53 lines (41 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use tokio::time::sleep;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
sleep(std::time::Duration::new(2, 0)).await;
let port: u16 = std::env::var("DAPR_GRPC_PORT")?.parse()?;
let addr = format!("https://127.0.0.1:{}", port);
let mut client = dapr::Client::<dapr::client::TonicClient>::connect(addr).await?;
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();
assert!(result.success);
println!("Successfully locked some-data");
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();
assert!(!result.success);
println!("Unsuccessfully locked some-data");
let result = client
.unlock(dapr::client::UnlockRequest {
store_name: "lockstore".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 some-data");
Ok(())
}