use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusFailure in project popstellar by dedis.
the class ConsensusHandlerTest method handleConsensusFailure.
@Test
public void handleConsensusFailure() throws DataHandlingException {
// handle an elect from node2 then handle a failure for this elect
// the state of the node2 for this instanceId should be FAILED
ConsensusFailure failure = new ConsensusFailure(INSTANCE_ID, messageId, CREATION_TIME);
MessageGeneral failureMsg = getMsg(ORGANIZER_KEY, failure);
messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, electMsg);
messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, failureMsg);
Optional<ElectInstance> electInstanceOpt = lao.getElectInstance(electMsg.getMessageId());
assertTrue(electInstanceOpt.isPresent());
ElectInstance electInstance = electInstanceOpt.get();
assertEquals(FAILED, electInstance.getState());
ConsensusNode node2 = lao.getNode(NODE_2);
assertNotNull(node2);
assertEquals(FAILED, node2.getState(INSTANCE_ID));
}
use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusFailure in project popstellar by dedis.
the class ElectionStartFragmentTest method failureTest.
@Test
public void failureTest() throws DataHandlingException {
setupViewModel(PAST_TIME);
// Nodes 3 try to start and failed
MessageGeneral elect3Msg = createMsg(node3KeyPair, elect);
messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, elect3Msg);
ConsensusFailure failure3 = new ConsensusFailure(INSTANCE_ID, elect3Msg.getMessageId(), PAST_TIME);
MessageGeneral failure3Msg = createMsg(node3KeyPair, failure3);
messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, failure3Msg);
nodeAssertions(nodesGrid(), node3Pos, "Start Failed\n" + node3, false);
// We try to start and failed
MessageGeneral elect1Msg = createMsg(mainKeyPair, elect);
messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, elect1Msg);
ConsensusFailure failure1 = new ConsensusFailure(INSTANCE_ID, elect1Msg.getMessageId(), PAST_TIME);
MessageGeneral failure1Msg = createMsg(mainKeyPair, failure1);
messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, failure1Msg);
displayAssertions(STATUS_READY, START_START, true);
nodeAssertions(nodesGrid(), ownPos, "Start Failed\n" + publicKey, false);
}
use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusFailure in project popstellar by dedis.
the class ConsensusHandlerTest method handleConsensusWithInvalidMessageIdTest.
@Test
public void handleConsensusWithInvalidMessageIdTest() {
// When an invalid instance id is used in handler for elect_accept and learn,
// it should throw an InvalidMessageIdException
ConsensusElectAccept electAcceptInvalid = new ConsensusElectAccept(INSTANCE_ID, INVALID_MSG_ID, true);
ConsensusLearn learnInvalid = new ConsensusLearn(INSTANCE_ID, INVALID_MSG_ID, CREATION_TIME, true, Collections.emptyList());
ConsensusFailure failureInvalid = new ConsensusFailure(INSTANCE_ID, INVALID_MSG_ID, CREATION_TIME);
MessageGeneral electAcceptInvalidMsg = getMsg(ORGANIZER_KEY, electAcceptInvalid);
MessageGeneral learnInvalidMsg = getMsg(ORGANIZER_KEY, learnInvalid);
MessageGeneral failureMsg = getMsg(ORGANIZER_KEY, failureInvalid);
assertThrows(InvalidMessageIdException.class, () -> messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, electAcceptInvalidMsg));
assertThrows(InvalidMessageIdException.class, () -> messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, learnInvalidMsg));
assertThrows(InvalidMessageIdException.class, () -> messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, failureMsg));
}
Aggregations