use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral in project popstellar by dedis.
the class LAONetworkManagerTest method publishSendsRightMessage.
@Test
public void publishSendsRightMessage() {
TestSchedulerProvider schedulerProvider = new TestSchedulerProvider();
TestScheduler testScheduler = schedulerProvider.getTestScheduler();
LAONetworkManager networkManager = new LAONetworkManager(laoRepository, handler, connection, JsonModule.provideGson(DataRegistryModule.provideDataRegistry()), schedulerProvider);
Answer<?> answer = args -> {
// Retrieve subscribe object
Publish publish = args.getArgument(0);
// Make sure the channel is correct
assertEquals(CHANNEL, publish.getChannel());
MessageGeneral messageGeneral = publish.getMessage();
assertEquals(DATA, messageGeneral.getData());
// Return a positive result
messages.onNext(new Result(publish.getRequestId()));
return null;
};
doAnswer(answer).when(connection).sendMessage(any(Publish.class));
// Actual test
Disposable disposable = networkManager.publish(KEY_PAIR, CHANNEL, DATA).subscribe();
testScheduler.advanceTimeBy(5, TimeUnit.SECONDS);
disposable.dispose();
networkManager.dispose();
verify(connection).sendMessage(any(Publish.class));
verify(connection, atLeastOnce()).observeMessage();
verify(connection).observeConnectionEvents();
verify(connection).close();
verifyNoMoreInteractions(connection);
}
use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral 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);
}
use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral in project popstellar by dedis.
the class RollCallHandlerTest method testHandleOpenRollCall.
@Test
public void testHandleOpenRollCall() throws DataHandlingException {
// Create the open Roll Call message
OpenRollCall openRollCall = new OpenRollCall(CREATE_LAO.getId(), rollCall.getId(), rollCall.getStart(), EventState.CREATED);
MessageGeneral message = new MessageGeneral(SENDER_KEY, openRollCall, GSON);
// Call the message handler
messageHandler.handleMessage(laoRepository, messageSender, LAO_CHANNEL, message);
// Check the Roll Call is present with state OPENED and the correct ID
Optional<RollCall> rollCallOpt = laoRepository.getLaoByChannel(LAO_CHANNEL).getRollCall(openRollCall.getUpdateId());
assertTrue(rollCallOpt.isPresent());
assertEquals(EventState.OPENED, rollCallOpt.get().getState());
assertEquals(openRollCall.getUpdateId(), rollCallOpt.get().getId());
// Check the WitnessMessage has been created
Optional<WitnessMessage> witnessMessage = laoRepository.getLaoByChannel(LAO_CHANNEL).getWitnessMessage(message.getMessageId());
assertTrue(witnessMessage.isPresent());
// Check the Witness message contains the expected title and description
WitnessMessage expectedMessage = openRollCallWitnessMessage(message.getMessageId(), rollCallOpt.get());
assertEquals(expectedMessage.getTitle(), witnessMessage.get().getTitle());
assertEquals(expectedMessage.getDescription(), witnessMessage.get().getDescription());
}
use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral in project popstellar by dedis.
the class LaoDetailViewModel method updateLaoName.
/**
* Method to update the name of a Lao by sending an updateLao msg and a stateLao msg to the
* backend
*/
public void updateLaoName() {
Log.d(TAG, "Updating lao name to " + mLaoName.getValue());
Lao lao = getCurrentLaoValue();
Channel channel = lao.getChannel();
KeyPair mainKey = keyManager.getMainKeyPair();
long now = Instant.now().getEpochSecond();
UpdateLao updateLao = new UpdateLao(mainKey.getPublicKey(), lao.getCreation(), mLaoName.getValue(), now, lao.getWitnesses());
MessageGeneral msg = new MessageGeneral(mainKey, updateLao, gson);
Disposable disposable = networkManager.getMessageSender().publish(channel, msg).subscribe(() -> {
Log.d(TAG, "updated lao name");
dispatchLaoUpdate("lao name", updateLao, lao, channel, msg);
}, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_update_lao));
disposables.add(disposable);
}
use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral in project popstellar by dedis.
the class LaoDetailViewModel method updateLaoWitnesses.
/**
* Method to update the list of witnesses of a Lao by sending an updateLao msg and a stateLao msg
* to the backend
*/
public void updateLaoWitnesses() {
Log.d(TAG, "Updating lao witnesses ");
Lao lao = getCurrentLaoValue();
if (lao == null) {
Log.d(TAG, LAO_FAILURE_MESSAGE);
return;
}
Channel channel = lao.getChannel();
KeyPair mainKey = keyManager.getMainKeyPair();
long now = Instant.now().getEpochSecond();
UpdateLao updateLao = new UpdateLao(mainKey.getPublicKey(), lao.getCreation(), lao.getName(), now, witnesses);
MessageGeneral msg = new MessageGeneral(mainKey, updateLao, gson);
Disposable disposable = networkManager.getMessageSender().publish(channel, msg).subscribe(() -> {
Log.d(TAG, "updated lao witnesses");
dispatchLaoUpdate("lao state with new witnesses", updateLao, lao, channel, msg);
}, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_update_lao));
disposables.add(disposable);
}
Aggregations