use of com.radixdlt.environment.deterministic.network.ControlledMessage in project radixdlt by radixdlt.
the class PacemakerTest method on_view_timeout_quorum_pacemaker_should_move_to_next_view.
@Test
public void on_view_timeout_quorum_pacemaker_should_move_to_next_view() {
// Arrange
createRunner().injectMembers(this);
processor.start();
ControlledMessage timeoutMsg = network.nextMessage(e -> Epoched.isInstance(e.message(), ScheduledLocalTimeout.class)).value();
processor.handleMessage(timeoutMsg.origin(), timeoutMsg.message(), new TypeLiteral<Epoched<ScheduledLocalTimeout>>() {
});
ControlledMessage bftUpdateMsg = network.nextMessage(e -> e.message() instanceof BFTInsertUpdate).value();
processor.handleMessage(bftUpdateMsg.origin(), bftUpdateMsg.message(), null);
// Act
ControlledMessage viewTimeout = network.nextMessage(e -> (e.message() instanceof Vote) && ((Vote) e.message()).isTimeout()).value();
processor.handleMessage(viewTimeout.origin(), viewTimeout.message(), null);
// Assert
assertThat(network.allMessages()).haveExactly(1, new Condition<>(msg -> msg.message() instanceof EpochViewUpdate, "A remote view timeout has been emitted"));
EpochViewUpdate nextEpochViewUpdate = network.allMessages().stream().filter(msg -> msg.message() instanceof EpochViewUpdate).map(ControlledMessage::message).map(EpochViewUpdate.class::cast).findAny().orElseThrow();
assertThat(nextEpochViewUpdate.getViewUpdate().getCurrentView()).isEqualTo(initialViewUpdate.getCurrentView().next());
}
use of com.radixdlt.environment.deterministic.network.ControlledMessage in project radixdlt by radixdlt.
the class MempoolFillAndEmptyTest method fillAndEmptyMempool.
private void fillAndEmptyMempool() {
while (systemCounters.get(SystemCounters.CounterType.MEMPOOL_CURRENT_SIZE) < 1000) {
ControlledMessage msg = network.nextMessage().value();
processor.handleMessage(msg.origin(), msg.message(), msg.typeLiteral());
if (msg.message() instanceof EpochViewUpdate) {
scheduledMempoolFillEventDispatcher.dispatch(ScheduledMempoolFill.create());
}
}
for (int i = 0; i < 10000; i++) {
ControlledMessage msg = network.nextMessage().value();
processor.handleMessage(msg.origin(), msg.message(), msg.typeLiteral());
if (systemCounters.get(SystemCounters.CounterType.MEMPOOL_CURRENT_SIZE) == 0) {
break;
}
}
assertThat(systemCounters.get(SystemCounters.CounterType.MEMPOOL_CURRENT_SIZE)).isZero();
}
use of com.radixdlt.environment.deterministic.network.ControlledMessage in project radixdlt by radixdlt.
the class DeterministicNodes method handleMessage.
public void handleMessage(Timed<ControlledMessage> timedNextMsg) {
ControlledMessage nextMsg = timedNextMsg.value();
int senderIndex = nextMsg.channelId().senderIndex();
int receiverIndex = nextMsg.channelId().receiverIndex();
BFTNode sender = this.nodeLookup.inverse().get(senderIndex);
var injector = nodeInstances.get(receiverIndex);
ThreadContext.put("self", " " + injector.getInstance(Key.get(String.class, Self.class)));
try {
log.debug("Received message {} at {}", nextMsg, timedNextMsg.time());
nodeInstances.get(receiverIndex).getInstance(DeterministicProcessor.class).handleMessage(sender, nextMsg.message(), nextMsg.typeLiteral());
} finally {
ThreadContext.remove("self");
}
}
use of com.radixdlt.environment.deterministic.network.ControlledMessage in project radixdlt by radixdlt.
the class PacemakerTest method on_timeout_pacemaker_should_send_vote_with_timeout.
@Test
public void on_timeout_pacemaker_should_send_vote_with_timeout() {
// Arrange
createRunner().injectMembers(this);
processor.start();
// Act
ControlledMessage timeoutMsg = network.nextMessage(e -> Epoched.isInstance(e.message(), ScheduledLocalTimeout.class)).value();
processor.handleMessage(timeoutMsg.origin(), timeoutMsg.message(), new TypeLiteral<Epoched<ScheduledLocalTimeout>>() {
});
ControlledMessage bftUpdateMsg = network.nextMessage(e -> e.message() instanceof BFTInsertUpdate).value();
processor.handleMessage(bftUpdateMsg.origin(), bftUpdateMsg.message(), null);
// Assert
assertThat(network.allMessages()).haveExactly(1, new Condition<>(msg -> (msg.message() instanceof Vote) && ((Vote) msg.message()).isTimeout(), "A remote timeout vote has been emitted"));
}
Aggregations