use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElect in project popstellar by dedis.
the class LaoDetailViewModel method sendConsensusElect.
/**
* Sends a ConsensusElect message.
*
* <p>Publish a GeneralMessage containing ConsensusElect data.
*
* @param creation the creation time of the consensus
* @param objId the id of the object the consensus refers to (e.g. election_id)
* @param type the type of object the consensus refers to (e.g. election)
* @param property the property the value refers to (e.g. "state")
* @param value the proposed new value for the property (e.g. "started")
*/
public void sendConsensusElect(long creation, String objId, String type, String property, Object value) {
Log.d(TAG, String.format("creating a new consensus for type: %s, property: %s, value: %s", type, property, value));
Lao lao = getCurrentLaoValue();
if (lao == null) {
Log.d(TAG, LAO_FAILURE_MESSAGE);
return;
}
Channel channel = lao.getChannel().subChannel("consensus");
ConsensusElect consensusElect = new ConsensusElect(creation, objId, type, property, value);
Log.d(TAG, PUBLISH_MESSAGE);
MessageGeneral msg = new MessageGeneral(keyManager.getMainKeyPair(), consensusElect, gson);
Disposable disposable = networkManager.getMessageSender().publish(channel, msg).subscribe(() -> Log.d(TAG, "created a consensus with message id : " + msg.getMessageId()), error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_start_election));
disposables.add(disposable);
}
use of com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElect in project popstellar by dedis.
the class ElectionStartFragmentTest method startButtonSendElectMessageTest.
@Test
public void startButtonSendElectMessageTest() {
setupViewModel(PAST_TIME);
long minCreation = Instant.now().getEpochSecond();
electionStartButton().perform(ViewActions.click());
ArgumentCaptor<MessageGeneral> captor = ArgumentCaptor.forClass(MessageGeneral.class);
Mockito.verify(messageSender).publish(eq(consensusChannel), captor.capture());
MessageGeneral msgGeneral = captor.getValue();
long maxCreation = Instant.now().getEpochSecond();
assertEquals(mainKeyPair.getPublicKey(), msgGeneral.getSender());
ConsensusElect elect = (ConsensusElect) msgGeneral.getData();
assertEquals(KEY, elect.getKey());
assertEquals(INSTANCE_ID, elect.getInstanceId());
assertEquals("started", elect.getValue());
assertTrue(minCreation <= elect.getCreation() && elect.getCreation() <= maxCreation);
}
Aggregations