Search in sources :

Example 91 with MockChannel

use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.

the class ActiveJmsConnectionErrorHandlerTest method testConnectionErrorHandlerWithJndi.

@Test
public void testConnectionErrorHandlerWithJndi() throws Exception {
    String oldName = Thread.currentThread().getName();
    Thread.currentThread().setName(testName.getMethodName());
    String queueName = testName.getMethodName() + "_queue";
    String topicName = testName.getMethodName() + "_topic";
    JmsConnection conn = activeMqBroker.getJndiPasConnection(new MyStandardJndiImpl(testName.getMethodName()), false, queueName, topicName);
    conn.setUniqueId(testName.getMethodName());
    conn.setConnectionAttempts(null);
    MockChannel channel = createChannel(activeMqBroker, conn, topicName);
    try {
        channel.requestStart();
        assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
        activeMqBroker.stop();
        // Give the ErrorHandler time to check that it's stopped
        log.trace("Waiting for channel death (i.e. !StartedState)");
        long totalWaitTime = waitForChannelToChangeState(StartedState.getInstance(), channel);
        // assertNotSame(StartedState.getInstance(), channel.retrieveComponentState());
        log.trace("Channel appears to be not started now, and I waited for " + totalWaitTime);
        activeMqBroker.start();
        waitForChannelToMatchState(StartedState.getInstance(), channel);
        assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
        assertEquals(2, channel.getStartCount());
    } finally {
        channel.requestClose();
        Thread.currentThread().setName(oldName);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) JmsConnection(com.adaptris.core.jms.JmsConnection) Test(org.junit.Test)

Example 92 with MockChannel

use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.

the class ActiveJmsConnectionErrorHandlerTest method testActiveRestartSharedConnection_ChannelNotStarted.

@Test
public void testActiveRestartSharedConnection_ChannelNotStarted() throws Exception {
    Adapter adapter = new Adapter();
    adapter.setUniqueId(testName.getMethodName());
    JmsConnection connection = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true);
    connection.setConnectionErrorHandler(createErrorHandler());
    connection.setConnectionAttempts(null);
    connection.setUniqueId(testName.getMethodName());
    connection.setConnectionRetryInterval(new TimeInterval(5L, "SECONDS"));
    adapter.getSharedComponents().addConnection(connection);
    MockChannel started = createChannel(activeMqBroker, new SharedConnection(testName.getMethodName()), testName.getMethodName());
    MockChannel neverStarted = createChannel(activeMqBroker, new SharedConnection(testName.getMethodName()), testName.getMethodName() + "_2");
    neverStarted.setAutoStart(false);
    MockMessageProducer producer = (MockMessageProducer) started.getWorkflowList().get(0).getProducer();
    adapter.getChannelList().add(started);
    adapter.getChannelList().add(neverStarted);
    try {
        adapter.requestStart();
        assertEquals(StartedState.getInstance(), started.retrieveComponentState());
        assertEquals(ClosedState.getInstance(), neverStarted.retrieveComponentState());
        // Now try and send a message
        ExampleServiceCase.execute(createProducer(activeMqBroker, testName.getMethodName()), AdaptrisMessageFactory.getDefaultInstance().newMessage("ABC"));
        waitForMessages(producer, 1);
        activeMqBroker.stop();
        log.trace(testName.getMethodName() + ": Waiting for channel death (i.e. !StartedState)");
        long totalWaitTime = waitForChannelToChangeState(StartedState.getInstance(), started);
        log.trace(testName.getMethodName() + ": Channel appears to be not started now, and I waited for " + totalWaitTime);
        activeMqBroker.start();
        totalWaitTime = waitForChannelToMatchState(StartedState.getInstance(), started);
        log.trace(testName.getMethodName() + ": Channel now started now, and I waited for " + totalWaitTime);
        assertEquals(StartedState.getInstance(), started.retrieveComponentState());
        // Now try and send a message
        ExampleServiceCase.execute(createProducer(activeMqBroker, testName.getMethodName()), AdaptrisMessageFactory.getDefaultInstance().newMessage("ABC"));
        waitForMessages(producer, 2);
        assertEquals(ClosedState.getInstance(), neverStarted.retrieveComponentState());
        assertEquals(0, neverStarted.getInitCount());
    } finally {
        adapter.requestClose();
    }
}
Also used : SharedConnection(com.adaptris.core.SharedConnection) MockChannel(com.adaptris.core.stubs.MockChannel) TimeInterval(com.adaptris.util.TimeInterval) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) Adapter(com.adaptris.core.Adapter) JmsConnection(com.adaptris.core.jms.JmsConnection) Test(org.junit.Test)

Example 93 with MockChannel

use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.

the class ActiveJmsConnectionErrorHandlerTest method testBug1926.

@Test
public void testBug1926() throws Exception {
    String queueName = testName.getMethodName() + "_queue";
    String topicName = testName.getMethodName() + "_topic";
    JmsConnection jmsCon = activeMqBroker.getJndiPasConnection(new StandardJndiImplementation(), false, queueName, topicName);
    jmsCon.setConnectionAttempts(null);
    MockChannel channel = createChannel(activeMqBroker, jmsCon, topicName);
    try {
        channel.requestStart();
        assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
        activeMqBroker.stop();
        // Give the ErrorHandler time to check that it's stopped
        Thread.sleep(1000);
        activeMqBroker.start();
        waitForChannelToMatchState(StartedState.getInstance(), channel);
        assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
    } finally {
        channel.requestClose();
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) StandardJndiImplementation(com.adaptris.core.jms.jndi.StandardJndiImplementation) JmsConnection(com.adaptris.core.jms.JmsConnection) Test(org.junit.Test)

Example 94 with MockChannel

use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.

the class BasicActiveMqConsumerTest method createChannel.

private Channel createChannel(AdaptrisConnection cc, Workflow wf) throws Exception {
    Channel result = new MockChannel();
    result.setMessageErrorHandler(new NullProcessingExceptionHandler());
    result.setConsumeConnection(cc);
    result.getWorkflowList().add(wf);
    result.prepare();
    return result;
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) NullProcessingExceptionHandler(com.adaptris.core.NullProcessingExceptionHandler)

Example 95 with MockChannel

use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.

the class ConnectionErrorHandlerTest method testChannelConnectionErrorHandler.

@Test
public void testChannelConnectionErrorHandler() throws Exception {
    MockChannel c = new MockChannel();
    TriggeredFailingConnection con = new TriggeredFailingConnection();
    c.setConsumeConnection(con);
    start(c);
    con.triggerError();
    assertEquals(2, c.getInitCount());
    assertEquals(2, c.getStartCount());
    assertEquals(1, c.getStopCount());
    assertEquals(1, c.getCloseCount());
    stop(c);
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) Test(org.junit.Test)

Aggregations

MockChannel (com.adaptris.core.stubs.MockChannel)145 Test (org.junit.Test)125 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)92 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)62 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)59 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)56 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)44 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)40 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)32 TimeInterval (com.adaptris.util.TimeInterval)28 EventHandlerAwareService (com.adaptris.core.stubs.EventHandlerAwareService)22 Iterator (java.util.Iterator)17 StandardWorkflow (com.adaptris.core.StandardWorkflow)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)11 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)10 Channel (com.adaptris.core.Channel)10 JmsConnectionErrorHandler (com.adaptris.core.jms.JmsConnectionErrorHandler)9 MockMessageConsumer (com.adaptris.core.stubs.MockMessageConsumer)9 JmsConnection (com.adaptris.core.jms.JmsConnection)8