Search in sources :

Example 1 with ConsensusElect

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);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) ConsensusElect(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElect) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) Channel(com.github.dedis.popstellar.model.objects.Channel) StateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao) Lao(com.github.dedis.popstellar.model.objects.Lao) UpdateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)

Example 2 with ConsensusElect

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

Aggregations

MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)2 ConsensusElect (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElect)2 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)1 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)1 Channel (com.github.dedis.popstellar.model.objects.Channel)1 Lao (com.github.dedis.popstellar.model.objects.Lao)1 HiltAndroidTest (dagger.hilt.android.testing.HiltAndroidTest)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1 Test (org.junit.Test)1