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();
if let Err(err) = list.await {
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.code() == crate::HRESULT(FABRIC_E_SERVICE_DOES_NOT_EXIST.0)
|| e.code()
== crate::HRESULT(
mssf_com::FabricTypes::FABRIC_E_SERVICE_OFFLINE.0
)
);
} else {
assert_eq!(e.code(), crate::HRESULT(FABRIC_E_SERVICE_DOES_NOT_EXIST.0));
println!("EchoApp not provisioned. Skip validate.")
}
}
}
}
{
let pc = c.get_property_manager();
{
let err = pc
.create_name(&Uri::from("fabric:/bad?x=1"), timeout, None)
.await
.unwrap_err();
assert_eq!(
err.try_as_fabric_error_code().unwrap(),
ErrorCode::FABRIC_E_INVALID_NAME_URI
);
assert_eq!(
err.to_string(),
"FABRIC_E_INVALID_NAME_URI (-2147017794): The name 'fabric:/bad?x=1' is invalid: character '?' is not supported."
);
}
}
}