Skip to content

Commit

Permalink
Merge pull request #750 from drmingdrmer/42-metrics-test
Browse files Browse the repository at this point in the history
Chore: move Engine unit tests to "tests" dir
  • Loading branch information
drmingdrmer authored Apr 3, 2023
2 parents aebf6a8 + ac2e39d commit e20794f
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 477 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::testing::log_id;
use crate::EffectiveMembership;
use crate::Membership;
use crate::MembershipState;
use crate::MetricsChangeFlags;

fn m01() -> Membership<u64, ()> {
Membership::new(vec![btreeset! {0,1}], None)
Expand Down Expand Up @@ -48,16 +47,6 @@ fn test_following_handler_commit_entries_empty() -> anyhow::Result<()> {
),
eng.state.membership_state
);

assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: false,
cluster: false,
},
eng.output.metrics_flags
);

assert_eq!(0, eng.output.take_commands().len());

Ok(())
Expand All @@ -79,16 +68,6 @@ fn test_following_handler_commit_entries_ge_accepted() -> anyhow::Result<()> {
),
eng.state.membership_state
);

assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: true,
cluster: false,
},
eng.output.metrics_flags
);

assert_eq!(
vec![Command::FollowerCommit {
already_committed: Some(log_id(1, 1)),
Expand Down Expand Up @@ -116,16 +95,6 @@ fn test_following_handler_commit_entries_le_accepted() -> anyhow::Result<()> {
),
eng.state.membership_state
);

assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: true,
cluster: false,
},
eng.output.metrics_flags
);

assert_eq!(
vec![
Command::FollowerCommit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::Entry;
use crate::EntryPayload;
use crate::Membership;
use crate::MembershipState;
use crate::MetricsChangeFlags;
use crate::RaftTypeConfig;

fn m01() -> Membership<u64, ()> {
Expand Down Expand Up @@ -72,16 +71,6 @@ fn test_follower_do_append_entries_empty() -> anyhow::Result<()> {
eng.state.membership_state
);
assert_eq!(ServerState::Follower, eng.state.server_state);

assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: false,
cluster: false,
},
eng.output.metrics_flags
);

assert_eq!(0, eng.output.take_commands().len());

Ok(())
Expand Down Expand Up @@ -116,16 +105,6 @@ fn test_follower_do_append_entries_no_membership_entries() -> anyhow::Result<()>
eng.state.membership_state
);
assert_eq!(ServerState::Follower, eng.state.server_state);

assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: true,
cluster: false,
},
eng.output.metrics_flags
);

assert_eq!(
vec![
//
Expand Down Expand Up @@ -184,16 +163,6 @@ fn test_follower_do_append_entries_one_membership_entry() -> anyhow::Result<()>
eng.state.server_state,
"not in membership, become learner"
);

assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: true,
cluster: true,
},
eng.output.metrics_flags
);

assert_eq!(
vec![
Command::UpdateMembership {
Expand Down Expand Up @@ -260,16 +229,6 @@ fn test_follower_do_append_entries_three_membership_entries() -> anyhow::Result<
eng.state.server_state,
"in membership, become follower"
);

assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: true,
cluster: true,
},
eng.output.metrics_flags
);

assert_eq!(
vec![
Command::UpdateMembership {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::raft_state::LogStateReader;
use crate::testing::log_id;
use crate::EffectiveMembership;
use crate::Membership;
use crate::MetricsChangeFlags;
use crate::SnapshotMeta;
use crate::StoredMembership;
use crate::Vote;
Expand Down Expand Up @@ -68,16 +67,6 @@ fn test_install_snapshot_lt_last_snapshot() -> anyhow::Result<()> {
},
eng.state.snapshot_meta
);

assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: false,
cluster: false,
},
eng.output.metrics_flags
);

assert_eq!(
vec![Command::CancelSnapshot {
snapshot_meta: SnapshotMeta {
Expand Down Expand Up @@ -114,16 +103,6 @@ fn test_install_snapshot_lt_committed() -> anyhow::Result<()> {
},
eng.state.snapshot_meta
);

assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: false,
cluster: false,
},
eng.output.metrics_flags
);

assert_eq!(
vec![Command::CancelSnapshot {
snapshot_meta: SnapshotMeta {
Expand Down Expand Up @@ -163,16 +142,6 @@ fn test_install_snapshot_not_conflict() -> anyhow::Result<()> {
&Arc::new(EffectiveMembership::new(Some(log_id(1, 1)), m1234())),
eng.state.membership_state.committed()
);

assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: true,
cluster: true,
},
eng.output.metrics_flags
);

assert_eq!(
vec![
Command::UpdateMembership {
Expand Down Expand Up @@ -243,16 +212,6 @@ fn test_install_snapshot_conflict() -> anyhow::Result<()> {
&Arc::new(EffectiveMembership::new(Some(log_id(1, 1)), m1234())),
eng.state.membership_state.committed()
);

assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: true,
cluster: true,
},
eng.output.metrics_flags
);

assert_eq!(
vec![
Command::DeleteConflictLog { since: log_id(2, 4) },
Expand Down Expand Up @@ -304,16 +263,6 @@ fn test_install_snapshot_advance_last_log_id() -> anyhow::Result<()> {
&Arc::new(EffectiveMembership::new(Some(log_id(1, 1)), m1234())),
eng.state.membership_state.effective()
);

assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: true,
cluster: true,
},
eng.output.metrics_flags
);

assert_eq!(
vec![
Command::UpdateMembership {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::testing::log_id;
use crate::EffectiveMembership;
use crate::Membership;
use crate::MembershipState;
use crate::MetricsChangeFlags;
use crate::ServerState;

fn m01() -> Membership<u64, ()> {
Expand Down Expand Up @@ -55,14 +54,6 @@ fn test_truncate_logs_since_3() -> anyhow::Result<()> {

assert_eq!(Some(&log_id(2, 2)), eng.state.last_log_id());
assert_eq!(&[log_id(2, 2)], eng.state.log_ids.key_log_ids());
assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: true,
cluster: true,
},
eng.output.metrics_flags
);
assert_eq!(
MembershipState::new(
Arc::new(EffectiveMembership::new(Some(log_id(1, 1)), m01())),
Expand Down Expand Up @@ -94,14 +85,6 @@ fn test_truncate_logs_since_4() -> anyhow::Result<()> {

assert_eq!(Some(&log_id(2, 3)), eng.state.last_log_id());
assert_eq!(&[log_id(2, 2), log_id(2, 3)], eng.state.log_ids.key_log_ids());
assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: true,
cluster: false,
},
eng.output.metrics_flags
);
assert_eq!(
MembershipState::new(
Arc::new(EffectiveMembership::new(Some(log_id(1, 1)), m01())),
Expand All @@ -127,15 +110,6 @@ fn test_truncate_logs_since_5() -> anyhow::Result<()> {

assert_eq!(Some(&log_id(4, 4)), eng.state.last_log_id());
assert_eq!(&[log_id(2, 2), log_id(4, 4)], eng.state.log_ids.key_log_ids());
assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: true,
cluster: false,
},
eng.output.metrics_flags
);

assert_eq!(
vec![Command::DeleteConflictLog { since: log_id(4, 5) }],
eng.output.take_commands()
Expand All @@ -155,15 +129,6 @@ fn test_truncate_logs_since_6() -> anyhow::Result<()> {
&[log_id(2, 2), log_id(4, 4), log_id(4, 5)],
eng.state.log_ids.key_log_ids()
);
assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: true,
cluster: false,
},
eng.output.metrics_flags
);

assert_eq!(
vec![Command::DeleteConflictLog { since: log_id(4, 6) }],
eng.output.take_commands()
Expand All @@ -183,15 +148,6 @@ fn test_truncate_logs_since_7() -> anyhow::Result<()> {
&[log_id(2, 2), log_id(4, 4), log_id(4, 6)],
eng.state.log_ids.key_log_ids()
);
assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: false,
cluster: false,
},
eng.output.metrics_flags
);

assert!(eng.output.take_commands().is_empty());

Ok(())
Expand All @@ -208,15 +164,6 @@ fn test_truncate_logs_since_8() -> anyhow::Result<()> {
&[log_id(2, 2), log_id(4, 4), log_id(4, 6)],
eng.state.log_ids.key_log_ids()
);
assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: false,
cluster: false,
},
eng.output.metrics_flags
);

assert!(eng.output.take_commands().is_empty());

Ok(())
Expand All @@ -235,15 +182,6 @@ fn test_truncate_logs_revert_effective_membership() -> anyhow::Result<()> {

assert_eq!(Some(&log_id(2, 3)), eng.state.last_log_id());
assert_eq!(&[log_id(2, 2), log_id(2, 3)], eng.state.log_ids.key_log_ids());
assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: true,
cluster: true,
},
eng.output.metrics_flags
);

assert_eq!(
vec![
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::testing::log_id;
use crate::EffectiveMembership;
use crate::Membership;
use crate::MembershipState;
use crate::MetricsChangeFlags;

fn m01() -> Membership<u64, ()> {
Membership::<u64, ()>::new(vec![btreeset! {0,1}], None)
Expand Down Expand Up @@ -53,16 +52,6 @@ fn test_update_committed_membership_at_index_4() -> anyhow::Result<()> {
eng.state.membership_state
);
assert_eq!(ServerState::Learner, eng.state.server_state);

assert_eq!(
MetricsChangeFlags {
replication: false,
local_data: false,
cluster: true,
},
eng.output.metrics_flags
);

assert_eq!(
vec![Command::UpdateMembership {
membership: Arc::new(EffectiveMembership::new(Some(log_id(3, 4)), m34())),
Expand Down
Loading

0 comments on commit e20794f

Please sign in to comment.