use of com.radixdlt.network.messaging.MessageCentralImpl in project radixdlt by radixdlt.
the class MessageCentralFuzzyTest method fuzzy_messaged_are_not_accepted.
@Test
@SuppressWarnings("unchecked")
public void fuzzy_messaged_are_not_accepted() throws Exception {
var inboundMessages = PublishSubject.<InboundMessage>create();
var config = mock(MessageCentralConfiguration.class);
var peerControl = mock(PeerControl.class);
var peerManager = mock(PeerManager.class);
var queueFactory = mock(EventQueueFactory.class);
when(config.messagingOutboundQueueMax(anyInt())).thenReturn(1);
when(config.messagingTimeToLive(anyLong())).thenReturn(30_000L);
when(peerManager.messages()).thenReturn(inboundMessages);
when(queueFactory.createEventQueue(anyInt(), any(Comparator.class))).thenReturn(new SimplePriorityBlockingQueue<>(1, OutboundMessageEvent.comparator()));
var messageCentral = new MessageCentralImpl(config, serialization, peerManager, Time::currentTimestamp, queueFactory, new SystemCountersImpl(), () -> peerControl, Addressing.ofNetwork(Network.LOCALNET));
var counter = new AtomicLong(0);
var disposable = messageCentral.messagesOf(Message.class).subscribe(nextItem -> counter.incrementAndGet(), error -> fail(error.getMessage()));
// Insert single valid message to ensure whole pipeline is working properly
emitSingleValidMessage(inboundMessages);
// Insert batch of randomly generated messages
emitFuzzyMessages(inboundMessages);
disposable.dispose();
// Ensure that only one (valid) message passed through
assertEquals(1L, counter.get());
}
Aggregations