use std::time::Duration;
use crate::{WString, client::FabricClient, sync::SimpleCancelToken, types::Uri};
use mssf_com::FabricTypes::FABRIC_E_SERVICE_DOES_NOT_EXIST;
use crate::{
client::svc_mgmt_client::PartitionKeyType,
error::ErrorCode,
types::{NodeQueryDescription, NodeStatusFilter, PagedQueryDescription},
};
#[tokio::test]
async fn test_fabric_client() {
let c = FabricClient::builder()
.with_connection_strings(vec![WString::from("localhost:19000")])
.build()
.unwrap();
let qc = c.get_query_manager();
let timeout = Duration::from_secs(1);
let paging_status;
{
let desc = NodeQueryDescription {
node_status_filter: NodeStatusFilter::Up,
paged_query: PagedQueryDescription {
continuation_token: None,
max_results: Some(2),
},
..Default::default()
};
let qc_cp = qc.clone();
let list = tokio::spawn(async move {
qc_cp.get_node_list(&desc, timeout, None).await
})
.await
.unwrap()
.unwrap();
println!("Nodes: {list:?}");
paging_status = list.paging_status;
assert_ne!(list.nodes.len(), 0);
}
{
let desc = NodeQueryDescription {
node_status_filter: NodeStatusFilter::Up,
paged_query: PagedQueryDescription {
continuation_token: paging_status.map(|x| x.continuation_token),
max_results: Some(2),
},
..Default::default()
};
let list = qc.get_node_list(&desc, timeout, None).await.unwrap();
println!("Nodes: {list:?}");
}
{
let desc = NodeQueryDescription {
..Default::default()
};
let token = SimpleCancelToken::new_boxed();
let list = qc.get_node_list(&desc, timeout, Some(token.clone()));
token.cancel();
let err = list.await.expect_err("request should be cancelled");
assert_eq!(err, ErrorCode::E_ABORT.into());
}
let smgr = c.get_service_manager();
{
let res = smgr
.resolve_service_partition(
&Uri::from("fabric:/EchoApp/EchoAppService"),
&PartitionKeyType::None,
None,
timeout,
None,
)
.await;
match res {
Ok(ptt) => {
println!("Info: {ptt:?}");
let endpoints = ptt.endpoints;
println!("Endpoints: {endpoints:?}");
}
Err(e) => {
if cfg!(unix) {
assert!(
e.0 == crate::HRESULT(FABRIC_E_SERVICE_DOES_NOT_EXIST.0)
|| e.0
== crate::HRESULT(
mssf_com::FabricTypes::FABRIC_E_SERVICE_OFFLINE.0
)
);
} else {
assert_eq!(e.0, crate::HRESULT(FABRIC_E_SERVICE_DOES_NOT_EXIST.0));
println!("EchoApp not provisioned. Skip validate.")
}
}
}
}
}