Пример #1
0
TEST(Proposer, OnAcceptReply_Reject)
{
    ProposerBuilder ob;

    MockProposerBP & oProposerBP = ob.oMockBreakpoint.m_oMockProposerBP;

    ob.poProposer->m_oProposerState.m_llProposalID = 100;
    ob.poProposer->m_bIsAccepting = true;
    ob.poProposer->m_oProposerState.m_sValue = "abc";
    PaxosMsg oPaxosMsg;
    oPaxosMsg.set_proposalid(100);

    //first call
    oPaxosMsg.set_rejectbypromiseid(101);
    oPaxosMsg.set_nodeid(2);
    ob.poProposer->OnAcceptReply(oPaxosMsg);

    EXPECT_TRUE(ob.poProposer->m_bWasRejectBySomeone == true);

    //second call
    oPaxosMsg.set_rejectbypromiseid(0);
    oPaxosMsg.set_nodeid(GetMyNode().GetNodeID());
    ob.poProposer->OnAcceptReply(oPaxosMsg);

    //third call
    oPaxosMsg.set_rejectbypromiseid(102);
    oPaxosMsg.set_nodeid(3);

    EXPECT_CALL(oProposerBP, AcceptNotPass()).Times(1);

    ob.poProposer->OnAcceptReply(oPaxosMsg);

    EXPECT_TRUE(ob.poProposer->m_bCanSkipPrepare == false);
    EXPECT_TRUE(ob.poProposer->m_oProposerState.m_sValue == "abc");
}
Пример #2
0
TEST(Proposer, OnPrepareReply_Pass)
{
    ProposerBuilder ob;

    MockProposerBP & oProposerBP = ob.oMockBreakpoint.m_oMockProposerBP;

    ob.poProposer->m_oProposerState.m_llProposalID = 100;
    ob.poProposer->m_bIsPreparing = true;
    ob.poProposer->m_oProposerState.m_sValue = "abc";
    PaxosMsg oPaxosMsg;
    oPaxosMsg.set_proposalid(100);

    //first call
    oPaxosMsg.set_preacceptid(95);
    oPaxosMsg.set_preacceptnodeid(GetMyNode().GetNodeID());
    oPaxosMsg.set_nodeid(GetMyNode().GetNodeID());
    oPaxosMsg.set_value("hello paxos");
    ob.poProposer->OnPrepareReply(oPaxosMsg);

    EXPECT_TRUE(ob.poProposer->m_oProposerState.m_sValue == "hello paxos");

    //second call
    oPaxosMsg.set_rejectbypromiseid(101);
    oPaxosMsg.set_nodeid(2);
    ob.poProposer->OnPrepareReply(oPaxosMsg);

    //third call
    oPaxosMsg.set_rejectbypromiseid(0);
    oPaxosMsg.set_preacceptid(98);
    oPaxosMsg.set_preacceptnodeid(3);
    oPaxosMsg.set_nodeid(3);
    oPaxosMsg.set_value("hello world");

    EXPECT_CALL(oProposerBP, PreparePass(_)).Times(1);

    ob.poProposer->OnPrepareReply(oPaxosMsg);

    EXPECT_TRUE(ob.poProposer->m_bCanSkipPrepare == true);
    EXPECT_TRUE(ob.poProposer->m_bIsAccepting == true);
    EXPECT_TRUE(ob.poProposer->m_oProposerState.m_sValue == "hello world");
}