Search in sources :

Example 1 with MessageCentralImpl

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());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) InboundMessage(com.radixdlt.network.messaging.InboundMessage) Message(org.radix.network.messaging.Message) PeerPingMessage(org.radix.network.messages.PeerPingMessage) MessageCentralImpl(com.radixdlt.network.messaging.MessageCentralImpl) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) InboundMessage(com.radixdlt.network.messaging.InboundMessage) Time(org.radix.time.Time) Comparator(java.util.Comparator) Test(org.junit.Test)

Aggregations

SystemCountersImpl (com.radixdlt.counters.SystemCountersImpl)1 InboundMessage (com.radixdlt.network.messaging.InboundMessage)1 MessageCentralImpl (com.radixdlt.network.messaging.MessageCentralImpl)1 Comparator (java.util.Comparator)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Test (org.junit.Test)1 PeerPingMessage (org.radix.network.messages.PeerPingMessage)1 Message (org.radix.network.messaging.Message)1 Time (org.radix.time.Time)1