Search in sources :

Example 11 with DefaultThreadingModel

use of net.dempsy.threading.DefaultThreadingModel in project Dempsy by Dempsy.

the class TcpTransportTest method testLargeMessage.

@Test
public void testLargeMessage() throws Exception {
    final String huge = TestWordCount.readBible();
    try (final ServiceTracker tr = new ServiceTracker()) {
        final AbstractTcpReceiver<?, ?> r = tr.track(receiver.get()).numHandlers(2).useLocalHost(true).maxMessageSize(1024 * 1024 * 1024);
        final ThreadingModel tm = tr.track(new DefaultThreadingModel(TcpTransportTest.class.getSimpleName() + ".testLargeMessage"));
        final Infrastructure infra = tr.track(new TestInfrastructure(tm));
        final TcpAddress addr = r.getAddress(infra);
        LOGGER.debug(addr.toString());
        final AtomicReference<RoutedMessage> rm = new AtomicReference<>(null);
        r.start((Listener<RoutedMessage>) msg -> {
            rm.set(msg);
            return true;
        }, infra);
        try (final SenderFactory sf = senderFactory.get()) {
            sf.start(new TestInfrastructure(null, null));
            final Sender sender = sf.getSender(addr);
            sender.send(new RoutedMessage(new int[] { 0 }, "Hello", huge));
            assertTrue(poll(o -> rm.get() != null));
            assertEquals(huge, rm.get().message);
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) NioReceiver(net.dempsy.transport.tcp.nio.NioReceiver) Arrays(java.util.Arrays) DefaultThreadingModel(net.dempsy.threading.DefaultThreadingModel) NioUtils.dontInterrupt(net.dempsy.transport.tcp.nio.internal.NioUtils.dontInterrupt) Listener(net.dempsy.transport.Listener) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) JsonSerializer(net.dempsy.serialization.jackson.JsonSerializer) KryoSerializer(net.dempsy.serialization.kryo.KryoSerializer) Serializer(net.dempsy.serialization.Serializer) Map(java.util.Map) ThreadingModel(net.dempsy.threading.ThreadingModel) TestInfrastructure(net.dempsy.util.TestInfrastructure) ServiceTracker(net.dempsy.ServiceTracker) DisruptableRecevier(net.dempsy.transport.DisruptableRecevier) Receiver(net.dempsy.transport.Receiver) Parameterized(org.junit.runners.Parameterized) NioSenderFactory(net.dempsy.transport.tcp.nio.NioSenderFactory) Sender(net.dempsy.transport.Sender) Logger(org.slf4j.Logger) Collection(java.util.Collection) Functional.uncheck(net.dempsy.util.Functional.uncheck) NetworkInterface(java.net.NetworkInterface) SenderFactory(net.dempsy.transport.SenderFactory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Inet4Address(java.net.Inet4Address) Collectors(java.util.stream.Collectors) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) TestWordCount(net.dempsy.TestWordCount) List(java.util.List) ConditionPoll.poll(net.dempsy.utils.test.ConditionPoll.poll) Infrastructure(net.dempsy.Infrastructure) Functional.chain(net.dempsy.util.Functional.chain) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) RoutedMessage(net.dempsy.transport.RoutedMessage) TestInfrastructure(net.dempsy.util.TestInfrastructure) ServiceTracker(net.dempsy.ServiceTracker) RoutedMessage(net.dempsy.transport.RoutedMessage) AtomicReference(java.util.concurrent.atomic.AtomicReference) DefaultThreadingModel(net.dempsy.threading.DefaultThreadingModel) Sender(net.dempsy.transport.Sender) DefaultThreadingModel(net.dempsy.threading.DefaultThreadingModel) ThreadingModel(net.dempsy.threading.ThreadingModel) TestInfrastructure(net.dempsy.util.TestInfrastructure) Infrastructure(net.dempsy.Infrastructure) NioSenderFactory(net.dempsy.transport.tcp.nio.NioSenderFactory) SenderFactory(net.dempsy.transport.SenderFactory) Test(org.junit.Test)

Example 12 with DefaultThreadingModel

use of net.dempsy.threading.DefaultThreadingModel 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)

Example 13 with DefaultThreadingModel

use of net.dempsy.threading.DefaultThreadingModel in project Dempsy by Dempsy.

the class TestInstanceManager method setupContainer.

@SuppressWarnings("resource")
public LockingContainer setupContainer(final MessageProcessorLifecycle<?> prototype) throws ContainerException {
    dispatcher = new DummyDispatcher();
    statsCollector = new BasicClusterStatsCollector();
    nodeStats = new BasicNodeStatsCollector();
    container = (LockingContainer) new LockingContainer().setMessageProcessor(prototype).setClusterId(new ClusterId("test", "test"));
    container.setDispatcher(dispatcher);
    container.setInbound(new DummyInbound());
    tm = new DefaultThreadingModel(TestInstanceManager.class.getName());
    tm.start(TestInstanceManager.class.getName());
    container.start(new TestInfrastructure(tm) {

        @Override
        public BasicClusterStatsCollector getClusterStatsCollector(final ClusterId clusterId) {
            return statsCollector;
        }

        @Override
        public NodeStatsCollector getNodeStatsCollector() {
            return nodeStats;
        }
    });
    return container;
}
Also used : DummyInbound(net.dempsy.container.mocks.DummyInbound) BasicNodeStatsCollector(net.dempsy.monitoring.basic.BasicNodeStatsCollector) NodeStatsCollector(net.dempsy.monitoring.NodeStatsCollector) TestInfrastructure(net.dempsy.util.TestInfrastructure) ClusterId(net.dempsy.config.ClusterId) BasicClusterStatsCollector(net.dempsy.monitoring.basic.BasicClusterStatsCollector) DefaultThreadingModel(net.dempsy.threading.DefaultThreadingModel) BasicNodeStatsCollector(net.dempsy.monitoring.basic.BasicNodeStatsCollector)

Aggregations

DefaultThreadingModel (net.dempsy.threading.DefaultThreadingModel)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 Receiver (net.dempsy.transport.Receiver)10 TestInfrastructure (net.dempsy.util.TestInfrastructure)10 Test (org.junit.Test)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)9 Assert.assertTrue (org.junit.Assert.assertTrue)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 Functional.chain (net.dempsy.util.Functional.chain)8 Collection (java.util.Collection)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Listener (net.dempsy.transport.Listener)7 Sender (net.dempsy.transport.Sender)7 SenderFactory (net.dempsy.transport.SenderFactory)7 ConditionPoll.poll (net.dempsy.utils.test.ConditionPoll.poll)7 Arrays (java.util.Arrays)6 Collections (java.util.Collections)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6