-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
204 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tests/tests/metrics/t10_server_metrics_and_data_metrics.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::sync::Arc; | ||
|
||
use anyhow::Result; | ||
use maplit::btreeset; | ||
use openraft::Config; | ||
#[allow(unused_imports)] use pretty_assertions::assert_eq; | ||
#[allow(unused_imports)] use pretty_assertions::assert_ne; | ||
|
||
use crate::fixtures::init_default_ut_tracing; | ||
use crate::fixtures::RaftRouter; | ||
|
||
/// Server metrics and data metrics method should work. | ||
#[async_entry::test(worker_threads = 8, init = "init_default_ut_tracing()", tracing_span = "debug")] | ||
async fn server_metrics_and_data_metrics() -> Result<()> { | ||
// Setup test dependencies. | ||
let config = Arc::new( | ||
Config { | ||
enable_heartbeat: false, | ||
enable_elect: false, | ||
..Default::default() | ||
} | ||
.validate()?, | ||
); | ||
let mut router = RaftRouter::new(config.clone()); | ||
|
||
tracing::info!("--- initializing cluster"); | ||
let mut log_index = router.new_cluster(btreeset! {0,1,2}, btreeset! {}).await?; | ||
|
||
let node = router.get_raft_handle(&0)?; | ||
let mut server_metrics = node.server_metrics(); | ||
let data_metrics = node.data_metrics(); | ||
|
||
let current_leader = router.current_leader(0).await; | ||
let leader = server_metrics.borrow_and_update().current_leader; | ||
assert_eq!(leader, current_leader, "current_leader should be {:?}", current_leader); | ||
|
||
// Write some logs. | ||
let n = 10; | ||
tracing::info!(log_index, "--- write {} logs", n); | ||
log_index += router.client_request_many(0, "foo", n).await?; | ||
|
||
let last_log_index = data_metrics.borrow().last_log.unwrap_or_default().index; | ||
assert_eq!(last_log_index, log_index, "last_log_index should be {:?}", log_index); | ||
assert!( | ||
!server_metrics.borrow().has_changed(), | ||
"server metrics should not update" | ||
); | ||
Ok(()) | ||
} |