Search in sources :

Example 1 with ConsensusPropose

use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusPropose in project popstellar by dedis.

the class ConsensusHandlerTest method handleConsensusDoNothingOnBackendMessageTest.

@Test
public void handleConsensusDoNothingOnBackendMessageTest() throws DataHandlingException {
    LAORepository mockLAORepository = mock(LAORepository.class);
    Map<MessageID, MessageGeneral> messageById = new HashMap<>();
    when(mockLAORepository.getMessageById()).thenReturn(messageById);
    ConsensusPrepare prepare = new ConsensusPrepare(INSTANCE_ID, messageId, CREATION_TIME, 3);
    ConsensusPromise promise = new ConsensusPromise(INSTANCE_ID, messageId, CREATION_TIME, 3, true, 2);
    ConsensusPropose propose = new ConsensusPropose(INSTANCE_ID, messageId, CREATION_TIME, 3, true, Collections.emptyList());
    ConsensusAccept accept = new ConsensusAccept(INSTANCE_ID, messageId, CREATION_TIME, 3, true);
    messageHandler.handleMessage(mockLAORepository, messageSender, CONSENSUS_CHANNEL, getMsg(ORGANIZER_KEY, prepare));
    messageHandler.handleMessage(mockLAORepository, messageSender, CONSENSUS_CHANNEL, getMsg(ORGANIZER_KEY, promise));
    messageHandler.handleMessage(mockLAORepository, messageSender, CONSENSUS_CHANNEL, getMsg(ORGANIZER_KEY, propose));
    messageHandler.handleMessage(mockLAORepository, messageSender, CONSENSUS_CHANNEL, getMsg(ORGANIZER_KEY, accept));
    // The handlers for prepare/promise/propose/accept should do nothing (call or update nothing)
    // because theses messages should only be handle in the backend server.
    verify(mockLAORepository, never()).getLaoByChannel(any(Channel.class));
    verify(mockLAORepository, never()).updateNodes(any(Channel.class));
}
Also used : MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) ConsensusAccept(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusAccept) HashMap(java.util.HashMap) Channel(com.github.dedis.popstellar.model.objects.Channel) LAORepository(com.github.dedis.popstellar.repository.LAORepository) ConsensusPropose(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusPropose) ConsensusPromise(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusPromise) ConsensusPrepare(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusPrepare) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) Test(org.junit.Test)

Aggregations

MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)1 ConsensusAccept (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusAccept)1 ConsensusPrepare (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusPrepare)1 ConsensusPromise (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusPromise)1 ConsensusPropose (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusPropose)1 Channel (com.github.dedis.popstellar.model.objects.Channel)1 MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)1 LAORepository (com.github.dedis.popstellar.repository.LAORepository)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1