-
Notifications
You must be signed in to change notification settings - Fork 11
/
server-client.rs
64 lines (54 loc) · 1.98 KB
/
server-client.rs
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
54
55
56
57
58
59
60
61
62
63
64
#![allow(unused_imports)]
use ate::prelude::*;
use serde::{Deserialize, Serialize};
use tracing::{debug, error, info, instrument, span, trace, warn, Level};
#[cfg(not(feature = "enable_server"))]
fn main() {}
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), AteError> {
ate::log_init(0, true);
// Create the server and listen on port 5000
let url = url::Url::parse("ws://localhost:5000/test-chain").unwrap();
let cfg_ate = ConfAte::default();
#[cfg(feature = "enable_dns")]
let cfg_mesh =
ConfMesh::solo_from_url(&cfg_ate, &url, &IpAddr::from_str("::").unwrap(), None, None)
.await?;
#[cfg(not(feature = "enable_dns"))]
let cfg_mesh = ConfMesh::solo_from_url(&cfg_ate, &url)?;
info!("create a persistent server");
let server = create_persistent_centralized_server(&cfg_ate, &cfg_mesh).await?;
info!("write some data to the server");
let key = {
let registry = Registry::new(&cfg_ate).await.cement();
let chain = registry
.open(
&url::Url::from_str("ws://localhost:5000/").unwrap(),
&ChainKey::from("test-chain"),
false
)
.await?;
let session = AteSessionUser::new();
let dio = chain.dio_mut(&session).await;
let dao = dio.store("my test string".to_string())?;
dio.commit().await?;
dao.key().clone()
};
info!("read it back again on a new client");
{
let registry = Registry::new(&cfg_ate).await.cement();
let chain = registry
.open(
&url::Url::from_str("ws://localhost:5000/").unwrap(),
&ChainKey::from("test-chain"),
false
)
.await?;
let session = AteSessionUser::new();
let dio = chain.dio(&session).await;
let dao = dio.load::<String>(&key).await?;
assert_eq!(*dao, "my test string".to_string());
}
server.shutdown().await;
Ok(())
}