Search in sources :

Example 6 with SenderFactory

use of net.dempsy.transport.SenderFactory in project Dempsy by Dempsy.

the class BlockingQueueTest method testBlockingQueue.

/*
     * Test basic functionality for the BlockingQueue implementation of Message Transport. Verify that messages sent to the Sender arrive at the receiver via
     * handleMessage.
     */
@Test
public void testBlockingQueue() throws Exception {
    final AtomicReference<String> message = new AtomicReference<String>(null);
    final ArrayBlockingQueue<Object> input = new ArrayBlockingQueue<>(16);
    try (final Receiver r = new BlockingQueueReceiver(input);
        final TestInfrastructure infra = new TestInfrastructure(new DefaultThreadingModel("BQTest-testBlockingQueue-"));
        final TransportManager tranMan = chain(new TransportManager(), c -> c.start(infra));
        SenderFactory sf = tranMan.getAssociatedInstance(transportTypeId)) {
        final Sender sender = sf.getSender(r.getAddress(infra));
        r.start((final String msg) -> {
            message.set(new String(msg));
            return true;
        }, infra);
        sender.send("Hello");
        assertTrue(poll(o -> "Hello".equals(message.get())));
    }
}
Also used : Sender(net.dempsy.transport.Sender) TransportManager(net.dempsy.transport.TransportManager) DefaultThreadingModel(net.dempsy.threading.DefaultThreadingModel) SenderFactory(net.dempsy.transport.SenderFactory) SystemPropertyManager(net.dempsy.util.SystemPropertyManager) Assert.assertTrue(org.junit.Assert.assertTrue) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) AtomicLong(java.util.concurrent.atomic.AtomicLong) ConditionPoll.poll(net.dempsy.utils.test.ConditionPoll.poll) Assert.assertFalse(org.junit.Assert.assertFalse) Functional.chain(net.dempsy.util.Functional.chain) TestInfrastructure(net.dempsy.util.TestInfrastructure) MessageTransportException(net.dempsy.transport.MessageTransportException) Receiver(net.dempsy.transport.Receiver) TestInfrastructure(net.dempsy.util.TestInfrastructure) Receiver(net.dempsy.transport.Receiver) AtomicReference(java.util.concurrent.atomic.AtomicReference) DefaultThreadingModel(net.dempsy.threading.DefaultThreadingModel) Sender(net.dempsy.transport.Sender) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) SenderFactory(net.dempsy.transport.SenderFactory) TransportManager(net.dempsy.transport.TransportManager) Test(org.junit.Test)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 DefaultThreadingModel (net.dempsy.threading.DefaultThreadingModel)6 Receiver (net.dempsy.transport.Receiver)6 Sender (net.dempsy.transport.Sender)6 SenderFactory (net.dempsy.transport.SenderFactory)6 Functional.chain (net.dempsy.util.Functional.chain)6 TestInfrastructure (net.dempsy.util.TestInfrastructure)6 ConditionPoll.poll (net.dempsy.utils.test.ConditionPoll.poll)6 Assert.assertTrue (org.junit.Assert.assertTrue)6 Test (org.junit.Test)6 Inet4Address (java.net.Inet4Address)4 NetworkInterface (java.net.NetworkInterface)4 Arrays (java.util.Arrays)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4