use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept in project popstellar by dedis.
the class ConsensusHandlerTest method handleConsensusElectAcceptTest.
// handle an electAccept from node3 for the elect of node2
// This test need be run after the elect message was handled, else the messageId would be invalid
private void handleConsensusElectAcceptTest() throws DataHandlingException {
ConsensusElectAccept electAccept = new ConsensusElectAccept(INSTANCE_ID, messageId, true);
MessageGeneral electAcceptMsg = getMsg(NODE_3_KEY, electAccept);
messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, electAcceptMsg);
Optional<ElectInstance> electInstanceOpt = lao.getElectInstance(electMsg.getMessageId());
assertTrue(electInstanceOpt.isPresent());
ElectInstance electInstance = electInstanceOpt.get();
Map<PublicKey, MessageID> acceptorsToMessageId = electInstance.getAcceptorsToMessageId();
assertEquals(1, acceptorsToMessageId.size());
assertEquals(electAcceptMsg.getMessageId(), acceptorsToMessageId.get(NODE_3));
assertEquals(3, lao.getNodes().size());
ConsensusNode organizer = lao.getNode(ORGANIZER);
ConsensusNode node2 = lao.getNode(NODE_2);
ConsensusNode node3 = lao.getNode(NODE_3);
assertNotNull(organizer);
assertNotNull(node2);
assertNotNull(node3);
Set<MessageID> organizerAcceptedMsg = organizer.getAcceptedMessageIds();
Set<MessageID> node2AcceptedMsg = node2.getAcceptedMessageIds();
Set<MessageID> node3AcceptedMsg = node3.getAcceptedMessageIds();
assertTrue(organizerAcceptedMsg.isEmpty());
assertTrue(node2AcceptedMsg.isEmpty());
assertEquals(Sets.newSet(electMsg.getMessageId()), node3AcceptedMsg);
}
use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept in project popstellar by dedis.
the class ElectionStartFragmentTest method acceptButtonSendElectAcceptMessageTest.
@Test
public void acceptButtonSendElectAcceptMessageTest() throws DataHandlingException {
setupViewModel(PAST_TIME);
// Nodes 3 try to start
MessageGeneral elect3Msg = createMsg(node3KeyPair, elect);
messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, elect3Msg);
// We try to accept node3
nodesGrid().atPosition(node3Pos).perform(ViewActions.click());
ArgumentCaptor<ConsensusElectAccept> captor = ArgumentCaptor.forClass(ConsensusElectAccept.class);
Mockito.verify(messageSender).publish(eq(mainKeyPair), eq(consensusChannel), captor.capture());
ConsensusElectAccept electAccept = captor.getValue();
ConsensusElectAccept expectedElectAccept = new ConsensusElectAccept(INSTANCE_ID, elect3Msg.getMessageId(), true);
assertEquals(expectedElectAccept, electAccept);
}
use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept in project popstellar by dedis.
the class LaoDetailViewModel method sendConsensusElectAccept.
/**
* Sends a ConsensusElectAccept message.
*
* <p>Publish a GeneralMessage containing ConsensusElectAccept data.
*
* @param electInstance the corresponding ElectInstance
* @param accept true if accepted, false if rejected
*/
public void sendConsensusElectAccept(ElectInstance electInstance, boolean accept) {
MessageID messageId = electInstance.getMessageId();
Log.d(TAG, "sending a new elect_accept for consensus with messageId : " + messageId + " with value " + accept);
Lao lao = getCurrentLaoValue();
if (lao == null) {
Log.d(TAG, LAO_FAILURE_MESSAGE);
return;
}
ConsensusElectAccept consensusElectAccept = new ConsensusElectAccept(electInstance.getInstanceId(), messageId, accept);
Log.d(TAG, PUBLISH_MESSAGE);
Disposable disposable = networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), electInstance.getChannel(), consensusElectAccept).subscribe(() -> Log.d(TAG, "sent an elect_accept successfully"), error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_consensus_accept));
disposables.add(disposable);
}
use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept in project popstellar by dedis.
the class ElectionStartFragmentTest method displayWithUpdatesIsCorrect.
@Test
public void displayWithUpdatesIsCorrect() throws DataHandlingException {
setupViewModel(PAST_TIME);
// Election start time has passed, should display that it's ready and start button enabled
displayAssertions(STATUS_READY, START_START, true);
DataInteraction grid = nodesGrid();
nodeAssertions(grid, ownPos, "Waiting\n" + publicKey, false);
nodeAssertions(grid, node2Pos, "Waiting\n" + node2, false);
nodeAssertions(grid, node3Pos, "Waiting\n" + node3, false);
// Nodes 3 try to start
MessageGeneral elect3Msg = createMsg(node3KeyPair, elect);
messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, elect3Msg);
nodeAssertions(grid, node3Pos, "Approve Start by\n" + node3, true);
// We try to start (it should disable the start button)
MessageGeneral elect1Msg = createMsg(mainKeyPair, elect);
messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, elect1Msg);
displayAssertions(STATUS_READY, START_START, false);
nodeAssertions(grid, ownPos, "Approve Start by\n" + publicKey, true);
// We accepted node 3 (it should disable button for node3)
ConsensusElectAccept electAccept3 = new ConsensusElectAccept(INSTANCE_ID, elect3Msg.getMessageId(), true);
MessageGeneral accept3Msg = createMsg(mainKeyPair, electAccept3);
messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, accept3Msg);
nodeAssertions(grid, node3Pos, "Approve Start by\n" + node3, false);
// Receive a learn message => node3 was accepted and has started the election
ConsensusLearn learn3 = new ConsensusLearn(INSTANCE_ID, elect3Msg.getMessageId(), PAST_TIME, true, Collections.emptyList());
MessageGeneral learn3Msg = createMsg(node3KeyPair, learn3);
messageHandler.handleMessage(laoRepository, messageSender, consensusChannel, learn3Msg);
displayAssertions(STATUS_STARTED, START_STARTED, false);
nodeAssertions(grid, node3Pos, "Started by\n" + node3, false);
}
use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept in project popstellar by dedis.
the class ElectInstanceTest method acceptorsResponsesTest.
@Test
public void acceptorsResponsesTest() {
MessageID messageId1 = generateMessageID();
MessageID messageId2 = generateMessageID();
String instanceId = electInstance.getInstanceId();
ConsensusElectAccept electAccept = new ConsensusElectAccept(instanceId, electMessageId, true);
ConsensusElectAccept electReject = new ConsensusElectAccept(instanceId, electMessageId, false);
electInstance.addElectAccept(node2, messageId1, electAccept);
electInstance.addElectAccept(node2, messageId2, electReject);
Map<PublicKey, MessageID> messageIds = electInstance.getAcceptorsToMessageId();
assertEquals(1, messageIds.size());
assertEquals(messageId1, messageIds.get(node2));
}
Aggregations