Example #1
0
// This func tests if executeList() will return error when there is
// an error returned by the state machine
func TestExecuteListWithError(t *testing.T) {
	r := commonTestlibExampleReplica()
	r.StateMachine = test.NewDummySM()
	makeCommitedInstances(r)

	// create an error
	r.InstanceMatrix[0][6].cmds = message.Commands{
		message.Command("error"),
	}

	// resolve conflicts
	assert.True(t, r.resolveConflicts(r.InstanceMatrix[0][6]))

	// should return an error
	assert.Equal(t, r.executeList(), epaxos.ErrStateMachineExecution)

	// construct executionLog
	expectLogStr := "["
	expectLogStr += "[0][2] [0][2] "
	expectLogStr += "[0][4] [0][4] "
	expectLogStr += "[1][3] [1][3] "
	expectLogStr += "[1][5] [1][5] "
	for i := 2; i < int(r.Size); i++ {
		expectLogStr += fmt.Sprintf("[%d][%d] [%d][%d] ", i, i+2, i, i+2)
		expectLogStr += fmt.Sprintf("[%d][%d] [%d][%d] ", i, i+4, i, i+4)
	}
	expectLogStr = expectLogStr[:len(expectLogStr)-1]
	expectLogStr += "]"

	// test the exection result
	executionLogStr := fmt.Sprint(r.StateMachine.(*test.DummySM).ExecutionLog)
	assert.Equal(t, executionLogStr, expectLogStr)
}
Example #2
0
// This func tests the result of executeList()
func TestExecuteList(t *testing.T) {
	r := commonTestlibExampleReplica()
	r.StateMachine = test.NewDummySM()

	makeCommitedInstances(r)
	// resolve conflicts
	assert.True(t, r.resolveConflicts(r.InstanceMatrix[0][6]))
	assert.Nil(t, r.executeList())

	// construct executionLog
	expectLogStr := "["
	expectLogStr += "[0][2] [0][2] "
	expectLogStr += "[0][4] [0][4] "
	expectLogStr += "[1][3] [1][3] "
	expectLogStr += "[1][5] [1][5] "

	for i := 2; i < int(r.Size); i++ {
		expectLogStr += fmt.Sprintf("[%d][%d] [%d][%d] ", i, i+2, i, i+2)
		expectLogStr += fmt.Sprintf("[%d][%d] [%d][%d] ", i, i+4, i, i+4)
	}
	// replace the last white-space to `]`
	expectLogStr += "[0][6] [0][6]]"

	// test the execution result
	executionLogStr := fmt.Sprint(r.StateMachine.(*test.DummySM).ExecutionLog)
	assert.Equal(t, executionLogStr, expectLogStr)
}