Search in sources :

Example 11 with TestInfrastructure

use of net.dempsy.util.TestInfrastructure in project Dempsy by Dempsy.

the class TcpTransportTest method testReceiverStart.

@Test
public void testReceiverStart() throws Exception {
    final AtomicBoolean resolverCalled = new AtomicBoolean(false);
    try (ServiceTracker tr = new ServiceTracker()) {
        final AbstractTcpReceiver<?, ?> r = tr.track(receiver.get()).resolver(a -> {
            resolverCalled.set(true);
            return a;
        }).numHandlers(2).useLocalHost(true);
        final Infrastructure infra = tr.track(new TestInfrastructure(new DefaultThreadingModel(TcpTransportTest.class.getSimpleName() + ".testReceiverStart")));
        final TcpAddress addr = r.getAddress(infra);
        LOGGER.debug(addr.toString());
        r.start(null, infra);
        assertTrue(resolverCalled.get());
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestInfrastructure(net.dempsy.util.TestInfrastructure) ServiceTracker(net.dempsy.ServiceTracker) TestInfrastructure(net.dempsy.util.TestInfrastructure) Infrastructure(net.dempsy.Infrastructure) DefaultThreadingModel(net.dempsy.threading.DefaultThreadingModel) Test(org.junit.Test)

Example 12 with TestInfrastructure

use of net.dempsy.util.TestInfrastructure 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 13 with TestInfrastructure

use of net.dempsy.util.TestInfrastructure 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 14 with TestInfrastructure

use of net.dempsy.util.TestInfrastructure 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)

Example 15 with TestInfrastructure

use of net.dempsy.util.TestInfrastructure in project Dempsy by Dempsy.

the class TestOutputSchedulers method testRelativeSchedule.

/**
 * Test relative schedule.
 *
 * @throws Exception the exception
 */
@Test
public void testRelativeSchedule() throws Exception {
    try (final RelativeOutputSchedule relativeOutputSchedule = new RelativeOutputSchedule(1, TimeUnit.SECONDS)) {
        relativeOutputSchedule.setOutputInvoker(container);
        relativeOutputSchedule.start(new TestInfrastructure(null));
        assertTrue(poll(outputInvoked, oi -> oi.get()));
    }
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) NonLockingAltContainer(net.dempsy.container.altnonlocking.NonLockingAltContainer) ConditionPoll.poll(net.dempsy.utils.test.ConditionPoll.poll) TestInfrastructure(net.dempsy.util.TestInfrastructure) Assert.assertTrue(org.junit.Assert.assertTrue) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Container(net.dempsy.container.Container) Test(org.junit.Test) Before(org.junit.Before) TestInfrastructure(net.dempsy.util.TestInfrastructure) Test(org.junit.Test)

Aggregations

TestInfrastructure (net.dempsy.util.TestInfrastructure)17 Test (org.junit.Test)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 ConditionPoll.poll (net.dempsy.utils.test.ConditionPoll.poll)11 Assert.assertTrue (org.junit.Assert.assertTrue)11 DefaultThreadingModel (net.dempsy.threading.DefaultThreadingModel)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 Receiver (net.dempsy.transport.Receiver)7 Sender (net.dempsy.transport.Sender)7 SenderFactory (net.dempsy.transport.SenderFactory)7 Functional.chain (net.dempsy.util.Functional.chain)7 Infrastructure (net.dempsy.Infrastructure)6 ServiceTracker (net.dempsy.ServiceTracker)6 NonLockingAltContainer (net.dempsy.container.altnonlocking.NonLockingAltContainer)6 Inet4Address (java.net.Inet4Address)5 NetworkInterface (java.net.NetworkInterface)5 Arrays (java.util.Arrays)5 Collection (java.util.Collection)5 Collections (java.util.Collections)5