Search in sources :

Example 1 with BasicStatsCollector

use of com.nokia.dempsy.monitoring.basic.BasicStatsCollector in project Dempsy by Dempsy.

the class TestInvocation method testInvocationFailureNoHandler.

@Test(expected = ContainerException.class)
public void testInvocationFailureNoHandler() throws Exception {
    InvocationTestMP prototype = new InvocationTestMP();
    LifecycleHelper invoker = new LifecycleHelper(prototype);
    InvocationTestMP instance = (InvocationTestMP) invoker.newInstance();
    BasicStatsCollector statsCollector = new BasicStatsCollector();
    invoker.invoke(instance, new Object(), statsCollector);
}
Also used : BasicStatsCollector(com.nokia.dempsy.monitoring.basic.BasicStatsCollector) LifecycleHelper(com.nokia.dempsy.container.internal.LifecycleHelper) Test(org.junit.Test)

Example 2 with BasicStatsCollector

use of com.nokia.dempsy.monitoring.basic.BasicStatsCollector in project Dempsy by Dempsy.

the class TestInvocation method testInvocationCommonSuperclass.

@Test
public void testInvocationCommonSuperclass() throws Exception {
    InvocationTestMP prototype = new InvocationTestMP();
    LifecycleHelper invoker = new LifecycleHelper(prototype);
    InvocationTestMP instance = (InvocationTestMP) invoker.newInstance();
    BasicStatsCollector statsCollector = new BasicStatsCollector();
    Integer message1 = new Integer(1);
    Object o = invoker.invoke(instance, message1, statsCollector);
    assertEquals(message1, instance.lastNumberHandlerValue);
    assertNull(o);
    Double message2 = new Double(1.5);
    invoker.invoke(instance, message2, statsCollector);
    assertEquals(message2, instance.lastNumberHandlerValue);
}
Also used : BasicStatsCollector(com.nokia.dempsy.monitoring.basic.BasicStatsCollector) LifecycleHelper(com.nokia.dempsy.container.internal.LifecycleHelper) Test(org.junit.Test)

Example 3 with BasicStatsCollector

use of com.nokia.dempsy.monitoring.basic.BasicStatsCollector in project Dempsy by Dempsy.

the class TestInvocation method testInvocationFailureNullMessage.

@Test(expected = NullPointerException.class)
public void testInvocationFailureNullMessage() throws Exception {
    InvocationTestMP prototype = new InvocationTestMP();
    LifecycleHelper invoker = new LifecycleHelper(prototype);
    InvocationTestMP instance = (InvocationTestMP) invoker.newInstance();
    BasicStatsCollector statsCollector = new BasicStatsCollector();
    invoker.invoke(instance, null, statsCollector);
}
Also used : BasicStatsCollector(com.nokia.dempsy.monitoring.basic.BasicStatsCollector) LifecycleHelper(com.nokia.dempsy.container.internal.LifecycleHelper) Test(org.junit.Test)

Example 4 with BasicStatsCollector

use of com.nokia.dempsy.monitoring.basic.BasicStatsCollector in project Dempsy by Dempsy.

the class TestInvocation method testInvocationExactClass.

@Test
public void testInvocationExactClass() throws Exception {
    InvocationTestMP prototype = new InvocationTestMP();
    LifecycleHelper invoker = new LifecycleHelper(prototype);
    InvocationTestMP instance = (InvocationTestMP) invoker.newInstance();
    BasicStatsCollector statsCollector = new BasicStatsCollector();
    // pre-condition assertion
    assertNull(prototype.lastStringHandlerValue);
    assertNull(instance.lastStringHandlerValue);
    String message = "foo";
    Object o = invoker.invoke(instance, message, statsCollector);
    assertEquals(new Integer(42), o);
    // we assert that the prototype is still null to check for bad code
    assertNull(prototype.lastStringHandlerValue);
    assertEquals(message, instance.lastStringHandlerValue);
}
Also used : BasicStatsCollector(com.nokia.dempsy.monitoring.basic.BasicStatsCollector) LifecycleHelper(com.nokia.dempsy.container.internal.LifecycleHelper) Test(org.junit.Test)

Example 5 with BasicStatsCollector

use of com.nokia.dempsy.monitoring.basic.BasicStatsCollector in project Dempsy by Dempsy.

the class TcpTransportTest method transportMultipleConnectionsFailedClient.

/**
    * This test checks the various behaviors of a tcp transport when the 
    * client is disrupted at the 5th byte. Multiple senders are started from
    * multiple threads and ONLY ONE fails at the 5th byte. All senders should
    * be able to continue on when that happens and so the message counts should
    * increase.
    */
@Test
public void transportMultipleConnectionsFailedClient() throws Throwable {
    runAllCombinations(new Checker() {

        @Override
        public void check(int port, boolean localhost, long batchOutgoingMessagesDelayMillis) throws Throwable {
            SenderFactory factory = null;
            TcpReceiver adaptor = null;
            BasicStatsCollector statsCollector = new BasicStatsCollector();
            try {
                //===========================================
                // setup the sender and receiver
                adaptor = new TcpReceiver(null, getFailFast());
                adaptor.setStatsCollector(statsCollector);
                // distruptible sender factory
                factory = makeSenderFactory(true, statsCollector, batchOutgoingMessagesDelayMillis);
                if (port > 0)
                    adaptor.setPort(port);
                if (localhost)
                    adaptor.setUseLocalhost(localhost);
                //===========================================
                // start the adaptor
                adaptor.start();
                // get the destination
                Destination destination = adaptor.getDestination();
                //===========================================
                // Start up sender threads and save the off
                ArrayList<Thread> threadsToJoinOn = new ArrayList<Thread>();
                SenderRunnable[] senders = new SenderRunnable[numThreads];
                for (int i = 0; i < numThreads; i++) threadsToJoinOn.add(i, new Thread(senders[i] = new SenderRunnable(destination, i, factory), "Test Sender for " + i));
                for (Thread thread : threadsToJoinOn) thread.start();
                //===========================================
                //===========================================
                // check that one sender has failed since this is disruptable.
                assertTrue(TestUtils.poll(baseTimeoutMillis, statsCollector, new TestUtils.Condition<BasicStatsCollector>() {

                    @Override
                    public boolean conditionMet(BasicStatsCollector o) throws Throwable {
                        return o.getMessagesNotSentCount() > 0;
                    }
                }));
                //===========================================
                //===========================================
                // check that ONLY one failed (the others didn't) when we're not batching. Otherwise
                //  more may fail.
                Thread.sleep(10);
                if (// if we're batching then we only expect a failure but we don't know how many
                batchOutgoingMessagesDelayMillis >= 0)
                    assertTrue(statsCollector.getMessagesNotSentCount() > 0);
                else
                    assertEquals(1, statsCollector.getMessagesNotSentCount());
                //===========================================
                // all of the counts should increase.
                long[] curCounts = new long[numThreads];
                int i = 0;
                for (SenderRunnable sender : senders) curCounts[i++] = sender.sentMessageCount.get();
                // ==========================================
                // go until they are all higher. The Senders should still be running
                // and sending successfully (only one failed once) so all counts should
                // be increasing.
                boolean allHigher = false;
                for (long endTime = System.currentTimeMillis() + numThreads * (baseTimeoutMillis); endTime > System.currentTimeMillis() && !allHigher; ) {
                    allHigher = true;
                    Thread.sleep(1);
                    i = 0;
                    for (SenderRunnable sender : senders) if (curCounts[i++] >= sender.sentMessageCount.get())
                        allHigher = false;
                }
                assertTrue(allHigher);
                // Stop the senders.
                for (SenderRunnable sender : senders) sender.keepGoing.set(false);
                // wait until all threads are stopped
                for (Thread t : threadsToJoinOn) t.join(5000);
                // make sure everything actually stopped.
                for (SenderRunnable sender : senders) assertTrue(sender.isStopped.get());
            // ==========================================
            } finally {
                if (factory != null)
                    factory.stop();
                if (adaptor != null)
                    adaptor.stop();
            }
        }

        @Override
        public String toString() {
            return "transportMultipleConnectionsFailedClient";
        }
    });
}
Also used : BasicStatsCollector(com.nokia.dempsy.monitoring.basic.BasicStatsCollector) Destination(com.nokia.dempsy.messagetransport.Destination) ArrayList(java.util.ArrayList) TestUtils(com.nokia.dempsy.TestUtils) SenderFactory(com.nokia.dempsy.messagetransport.SenderFactory) Test(org.junit.Test)

Aggregations

BasicStatsCollector (com.nokia.dempsy.monitoring.basic.BasicStatsCollector)5 Test (org.junit.Test)5 LifecycleHelper (com.nokia.dempsy.container.internal.LifecycleHelper)4 TestUtils (com.nokia.dempsy.TestUtils)1 Destination (com.nokia.dempsy.messagetransport.Destination)1 SenderFactory (com.nokia.dempsy.messagetransport.SenderFactory)1 ArrayList (java.util.ArrayList)1