Search in sources :

Example 1 with Sender

use of com.nokia.dempsy.messagetransport.Sender in project Dempsy by Dempsy.

the class BlockingQueueTest method testBlockingQueueUsingDestination.

@Test
public void testBlockingQueueUsingDestination() throws Exception {
    try {
        setUp2("/blockingqueueTest2AppContext.xml");
        Destination destination = destinationFactory.getDestination();
        Sender lsender = senderFactory.getSender(destination);
        lsender.send("Hello".getBytes());
        String message = new String(pojo.getMessage());
        assertEquals("Hello", message);
        assertEquals(0, overflowHandler.overflowCalled);
    } finally {
        if (ctx != null)
            tearDown();
    }
}
Also used : Sender(com.nokia.dempsy.messagetransport.Sender) Destination(com.nokia.dempsy.messagetransport.Destination) Test(org.junit.Test)

Example 2 with Sender

use of com.nokia.dempsy.messagetransport.Sender in project Dempsy by Dempsy.

the class BlockingQueueTest method setUp.

public void setUp(String applicationContextFilename) throws Exception {
    ctx = new ClassPathXmlApplicationContext(applicationContextFilename, getClass());
    ctx.registerShutdownHook();
    Sender lsender = (Sender) ctx.getBean("sender");
    sender = lsender;
    pojo = (MyPojo) ctx.getBean("testPojo");
    overflowHandler = (MyOverflowHandler) ctx.getBean("testOverflowHandler");
}
Also used : Sender(com.nokia.dempsy.messagetransport.Sender) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Example 3 with Sender

use of com.nokia.dempsy.messagetransport.Sender in project Dempsy by Dempsy.

the class TcpTransportTest method testTransportInstantiation.

/**
    * Just send a simple message and make sure it gets through.
    */
@Test
public void testTransportInstantiation() throws Throwable {
    final AtomicBoolean batchedAtLeastOnce = new AtomicBoolean(false);
    runAllCombinations(new Checker() {

        @Override
        public void check(int port, boolean localhost, long batchOutgoingMessagesDelayMillis) throws Throwable {
            final StatsCollector statsCollector = new StatsCollectorFactoryCoda().createStatsCollector(new ClusterId("test", "test-cluster"), new Destination() {
            });
            SenderFactory factory = null;
            TcpReceiver adaptor = null;
            try {
                boolean shouldBatch = batchOutgoingMessagesDelayMillis >= 0;
                if (shouldBatch)
                    batchedAtLeastOnce.set(true);
                TcpTransport transport = new TcpTransport();
                transport.setFailFast(getFailFast());
                // by default batching isn't disabled.
                assertFalse(transport.isBatchingDisabled());
                if (!shouldBatch)
                    transport.setDisableBatching(true);
                if (!shouldBatch)
                    assertTrue(transport.isBatchingDisabled());
                assertEquals(!shouldBatch, transport.isBatchingDisabled());
                //===========================================
                // setup the sender and receiver
                adaptor = (TcpReceiver) transport.createInbound(null);
                adaptor.setStatsCollector(statsCollector);
                StringListener receiver = new StringListener();
                adaptor.setListener(receiver);
                factory = transport.createOutbound(null, statsCollector);
                if (port > 0)
                    adaptor.setPort(port);
                if (localhost)
                    adaptor.setUseLocalhost(localhost);
                //===========================================
                // start the adaptor
                adaptor.start();
                // get the destination
                Destination destination = adaptor.getDestination();
                // send a message
                byte[] messageBytes = "Hello".getBytes();
                Sender sender = factory.getSender(destination);
                assertEquals((shouldBatch ? TcpTransport.defaultBatchingDelayMillis : -1), ((TcpSender) sender).getBatchOutgoingMessagesDelayMillis());
                sender.send(messageBytes);
                sender.send(messageBytes);
                // wait for it to be received.
                for (long endTime = System.currentTimeMillis() + baseTimeoutMillis; endTime > System.currentTimeMillis() && receiver.numMessages.get() < 2; ) Thread.sleep(1);
                assertEquals(2, receiver.numMessages.get());
                // verify everything came over ok.
                assertEquals(1, receiver.receivedStringMessages.size());
                assertEquals("Hello", receiver.receivedStringMessages.iterator().next());
                if (shouldBatch) {
                    // verify the histogram
                    Histogram histogram = ((TcpSender) sender).getBatchingHistogram();
                    assertEquals(calcMean(2), histogram.mean(), 0.0000001);
                    assertEquals(1, histogram.count());
                }
            } finally {
                if (factory != null)
                    factory.stop();
                if (adaptor != null)
                    adaptor.stop();
            }
        }

        @Override
        public String toString() {
            return "testTransportInstantiation";
        }
    });
    assertTrue(batchedAtLeastOnce.get());
}
Also used : Destination(com.nokia.dempsy.messagetransport.Destination) Histogram(com.yammer.metrics.core.Histogram) ClusterId(com.nokia.dempsy.config.ClusterId) StatsCollector(com.nokia.dempsy.monitoring.StatsCollector) BasicStatsCollector(com.nokia.dempsy.monitoring.basic.BasicStatsCollector) Sender(com.nokia.dempsy.messagetransport.Sender) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SenderFactory(com.nokia.dempsy.messagetransport.SenderFactory) StatsCollectorFactoryCoda(com.nokia.dempsy.monitoring.coda.StatsCollectorFactoryCoda) Test(org.junit.Test)

Aggregations

Sender (com.nokia.dempsy.messagetransport.Sender)3 Destination (com.nokia.dempsy.messagetransport.Destination)2 Test (org.junit.Test)2 ClusterId (com.nokia.dempsy.config.ClusterId)1 SenderFactory (com.nokia.dempsy.messagetransport.SenderFactory)1 StatsCollector (com.nokia.dempsy.monitoring.StatsCollector)1 BasicStatsCollector (com.nokia.dempsy.monitoring.basic.BasicStatsCollector)1 StatsCollectorFactoryCoda (com.nokia.dempsy.monitoring.coda.StatsCollectorFactoryCoda)1 Histogram (com.yammer.metrics.core.Histogram)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1