Search in sources :

Example 1 with ConsensusFailure

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));
}
Also used : ElectInstance(com.github.dedis.popstellar.model.objects.ElectInstance) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) ConsensusFailure(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusFailure) ConsensusNode(com.github.dedis.popstellar.model.objects.ConsensusNode) Test(org.junit.Test)

Example 2 with ConsensusFailure

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);
}
Also used : MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) ConsensusFailure(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusFailure) HiltAndroidTest(dagger.hilt.android.testing.HiltAndroidTest) Test(org.junit.Test)

Example 3 with ConsensusFailure

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));
}
Also used : ConsensusElectAccept(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) ConsensusLearn(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusLearn) ConsensusFailure(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusFailure) Test(org.junit.Test)

Aggregations

MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)3 ConsensusFailure (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusFailure)3 Test (org.junit.Test)3 ConsensusElectAccept (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept)1 ConsensusLearn (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusLearn)1 ConsensusNode (com.github.dedis.popstellar.model.objects.ConsensusNode)1 ElectInstance (com.github.dedis.popstellar.model.objects.ElectInstance)1 HiltAndroidTest (dagger.hilt.android.testing.HiltAndroidTest)1