pub async fn assert_storage_state(
        &self,
        expect_term: u64,
        expect_last_log: u64,
        expect_voted_for: Option<u64>,
        expect_sm_last_applied_log: LogId,
        expect_snapshot: Option<(ValueTest<u64>, u64, MembershipConfig)>,
    ) {
        let rt = self.routing_table.read().await;
        for (id, (_node, storage)) in rt.iter() {
            let last_log = storage.get_log_entries(..).await.unwrap().last().unwrap().log_id.index;
            assert_eq!(
                last_log, expect_last_log,
                "expected node {} to have last_log {}, got {}",
                id, expect_last_log, last_log
            );

            let hs = storage.read_hard_state().await.unwrap_or_else(|| panic!("no hard state found for node {}", id));

            assert_eq!(
                hs.current_term, expect_term,
                "expected node {} to have term {}, got {}",
                id, expect_term, hs.current_term
            );
            if let Some(voted_for) = &expect_voted_for {
                assert_eq!(
                    hs.voted_for.as_ref(),
                    Some(voted_for),
                    "expected node {} to have voted for {}, got {:?}",
                    id,
                    voted_for,
                    hs.voted_for
                );
            }
            if let Some((index_test, term, cfg)) = &expect_snapshot {
                let snap = storage
                    .get_current_snapshot()
                    .await
                    .map_err(|err| panic!("{}", err))
                    .unwrap()
                    .unwrap_or_else(|| panic!("no snapshot present for node {}", id));
                match index_test {
                    ValueTest::Exact(index) => assert_eq!(
                        &snap.meta.last_log_id.index, index,
                        "expected node {} to have snapshot with index {}, got {}",
                        id, index, snap.meta.last_log_id.index
                    ),
                    ValueTest::Range(range) => assert!(
                        range.contains(&snap.meta.last_log_id.index),
                        "expected node {} to have snapshot within range {:?}, got {}",
                        id,
                        range,
                        snap.meta.last_log_id.index
                    ),
                }
                assert_eq!(
                    &snap.meta.last_log_id.term, term,
                    "expected node {} to have snapshot with term {}, got {}",
                    id, term, snap.meta.last_log_id.term
                );
                assert_eq!(
                    &snap.meta.membership, cfg,
                    "expected node {} to have membership config {:?}, got {:?}",
                    id, cfg, snap.meta.membership
                );
            }
            let sm = storage.get_state_machine().await;
            assert_eq!(
                &sm.last_applied_log, &expect_sm_last_applied_log,
                "expected node {} to have state machine last_applied_log {}, got {}",
                id, expect_sm_last_applied_log, sm.last_applied_log
            );
        }
    }
/// Assert against the state of the storage system per node in the cluster.
Assert against the state of the storage system per node in the cluster.
Assert against the state of the storage system per node in the cluster .
pub async fn assert_storage_state(
        &self,
        expect_term: u64,
        expect_last_log: u64,
        expect_voted_for: Option<u64>,
        expect_sm_last_applied_log: LogId,
        expect_snapshot: Option<(ValueTest<u64>, u64, MembershipConfig)>,
    ) {
        let rt = self.routing_table.read().await;
        for (id, (_node, storage)) in rt.iter() {
            let last_log = storage.get_log_entries(..).await.unwrap().last().unwrap().log_id.index;
            assert_eq!(
                last_log, expect_last_log,
                "expected node {} to have last_log {}, got {}",
                id, expect_last_log, last_log
            );
            let hs = storage.read_hard_state().await.unwrap_or_else(|| panic!("no hard state found for node {}", id));
            assert_eq!(
                hs.current_term, expect_term,
                "expected node {} to have term {}, got {}",
                id, expect_term, hs.current_term
            );
            if let Some(voted_for) = &expect_voted_for {
                assert_eq!(
                    hs.voted_for.as_ref(),
                    Some(voted_for),
                    "expected node {} to have voted for {}, got {:?}",
                    id,
                    voted_for,
                    hs.voted_for
                );
            }
            if let Some((index_test, term, cfg)) = &expect_snapshot {
                let snap = storage
                    .get_current_snapshot()
                    .await
                    .map_err(|err| panic!("{}", err))
                    .unwrap()
                    .unwrap_or_else(|| panic!("no snapshot present for node {}", id));
                match index_test {
                    ValueTest::Exact(index) => assert_eq!(
                        &snap.meta.last_log_id.index, index,
                        "expected node {} to have snapshot with index {}, got {}",
                        id, index, snap.meta.last_log_id.index
                    ),
                    ValueTest::Range(range) => assert!(
                        range.contains(&snap.meta.last_log_id.index),
                        "expected node {} to have snapshot within range {:?}, got {}",
                        id,
                        range,
                        snap.meta.last_log_id.index
                    ),
                }
                assert_eq!(
                    &snap.meta.last_log_id.term, term,
                    "expected node {} to have snapshot with term {}, got {}",
                    id, term, snap.meta.last_log_id.term
                );
                assert_eq!(
                    &snap.meta.membership, cfg,
                    "expected node {} to have membership config {:?}, got {:?}",
                    id, cfg, snap.meta.membership
                );
            }
            let sm = storage.get_state_machine().await;
            assert_eq!(
                &sm.last_applied_log, &expect_sm_last_applied_log,
                "expected node {} to have state machine last_applied_log {}, got {}",
                id, expect_sm_last_applied_log, sm.last_applied_log
            );
        }
    }
pub async fn assert_storage_state ( & self , expect_term : u64 , expect_last_log : u64 , expect_voted_for : Option < u64 > , expect_sm_last_applied_log : LogId , expect_snapshot : Option < ( ValueTest < u64 > , u64 , MembershipConfig ) > , ) { let rt = self . routing_table . read ( ) . await ; for ( id , ( _node , storage ) ) in rt . iter ( ) { let last_log = storage . get_log_entries ( .. ) . await . unwrap ( ) . last ( ) . unwrap ( ) . log_id . index ; assert_eq ! ( last_log expect_last_log " " id expect_last_log last_log ) ; let hs = storage . read_hard_state ( ) . await . unwrap_or_else ( | | panic ! ( " " id ) ) ; assert_eq ! ( hs current_term expect_term " " id expect_term hs current_term ) ; if let Some ( voted_for ) = & expect_voted_for { assert_eq ! ( hs voted_for as_ref ( ) Some ( voted_for ) " " id voted_for hs voted_for ) ; } if let Some ( ( index_test , term , cfg ) ) = & expect_snapshot { let snap = storage . get_current_snapshot ( ) . await . map_err ( | err | panic ! ( " " err ) ) . unwrap ( ) . unwrap_or_else ( | | panic ! ( " " id ) ) ; match index_test { ValueTest :: Exact ( index ) => assert_eq ! ( snap meta last_log_id index index " " id index snap meta last_log_id index ) , ValueTest :: Range ( range ) => assert ! ( range contains ( snap meta last_log_id index ) " " id range snap meta last_log_id index ) , } assert_eq ! ( snap meta last_log_id term term " " id term snap meta last_log_id term ) ; assert_eq ! ( snap meta membership cfg " " id cfg snap meta membership ) ; } let sm = storage . get_state_machine ( ) . await ; assert_eq ! ( sm last_applied_log expect_sm_last_applied_log " " id expect_sm_last_applied_log sm last_applied_log ) ; } }
Assert against the state of the storage system per node in the cluster.
Assert against the state of the storage system per node in the cluster .
&self
expect_term
u64
expect_last_log
u64
expect_voted_for
Option<u64>
expect_sm_last_applied_log
LogId
expect_snapshot
Option<(ValueTest<u64>, u64, MembershipConfig)>
&self
expect_term
u64
expect_last_log
u64
expect_voted_for
Option<u64>
expect_sm_last_applied_log
LogId
expect_snapshot
Option<(ValueTest<u64>, u64, MembershipConfig)>