Search in sources :

Example 86 with MockChannel

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

the class JmsConnectionErrorHandlerTest method createChannel.

private MockChannel createChannel(EmbeddedActiveMq mq, SharedConnection con, String destinationName) throws Exception {
    MockChannel result = new MockChannel();
    result.setUniqueId(mq.getName() + "_channel" + "_" + destinationName);
    result.setConsumeConnection(con);
    Workflow workflow = createWorkflow(mq, destinationName);
    result.getWorkflowList().add(workflow);
    return result;
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) StandardWorkflow(com.adaptris.core.StandardWorkflow) Workflow(com.adaptris.core.Workflow)

Example 87 with MockChannel

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

the class JmsConnectionErrorHandlerTest method testConnectionErrorHandler_WithStartException.

@Test
public void testConnectionErrorHandler_WithStartException() throws Exception {
    MockChannel channel = new MockChannelFail(createChannel(activeMqBroker, activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true), testName.getMethodName(), new JmsConnectionErrorHandler()), MockChannelFail.WhenToFail.START_AFTER_CLOSE);
    try {
        channel.requestStart();
        assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
        activeMqBroker.stop();
        Thread.sleep(1000);
        activeMqBroker.start();
        waitForChannelToMatchState(InitialisedState.getInstance(), channel);
        assertEquals(InitialisedState.getInstance(), channel.retrieveComponentState());
        assertEquals(1, channel.getStartCount());
        assertEquals(2, channel.getInitCount());
    } finally {
        channel.requestClose();
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) JmsConnectionErrorHandler(com.adaptris.core.jms.JmsConnectionErrorHandler) Test(org.junit.Test)

Example 88 with MockChannel

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

the class JmsConnectionErrorHandlerTest method testConnectionErrorHandler_WithInitialiseException.

@Test
public void testConnectionErrorHandler_WithInitialiseException() throws Exception {
    MockChannel channel = new MockChannelFail(createChannel(activeMqBroker, activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true), testName.getMethodName(), new JmsConnectionErrorHandler()), MockChannelFail.WhenToFail.INIT_AFTER_CLOSE);
    try {
        channel.requestStart();
        assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
        activeMqBroker.stop();
        Thread.sleep(1000);
        activeMqBroker.start();
        // This is a bit artificial, but we shouldn't ever transition from ClosedState.
        Thread.sleep(1000);
        waitForChannelToMatchState(ClosedState.getInstance(), channel);
        assertEquals(ClosedState.getInstance(), channel.retrieveComponentState());
        assertEquals(1, channel.getStartCount());
        assertEquals(1, channel.getInitCount());
    } finally {
        channel.requestClose();
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) JmsConnectionErrorHandler(com.adaptris.core.jms.JmsConnectionErrorHandler) Test(org.junit.Test)

Example 89 with MockChannel

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

the class JmsConnectionErrorHandlerTest method testRestartSharedConnection.

@Test
public void testRestartSharedConnection() throws Exception {
    Adapter adapter = new Adapter();
    adapter.setUniqueId(testName.getMethodName());
    JmsConnection connection = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true);
    connection.setConnectionErrorHandler(new JmsConnectionErrorHandler());
    connection.setUniqueId(testName.getMethodName());
    connection.setConnectionRetryInterval(new TimeInterval(5L, "SECONDS"));
    connection.setConnectionAttempts(null);
    adapter.getSharedComponents().addConnection(connection);
    MockChannel channel = createChannel(activeMqBroker, new SharedConnection(testName.getMethodName()), testName.getMethodName());
    MockMessageProducer producer = (MockMessageProducer) channel.getWorkflowList().get(0).getProducer();
    adapter.getChannelList().add(channel);
    try {
        adapter.requestStart();
        assertEquals(StartedState.getInstance(), channel.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(), channel);
        log.trace(testName.getMethodName() + ": Channel appears to be not started now, and I waited for " + totalWaitTime);
        activeMqBroker.start();
        totalWaitTime = waitForChannelToMatchState(StartedState.getInstance(), channel);
        log.trace(testName.getMethodName() + ": Channel now started now, and I waited for " + totalWaitTime);
        waitForChannelToMatchState(StartedState.getInstance(), channel);
        assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
        // Now try and send a message
        ExampleServiceCase.execute(createProducer(activeMqBroker, testName.getMethodName()), AdaptrisMessageFactory.getDefaultInstance().newMessage("ABC"));
        waitForMessages(producer, 2);
    } 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) JmsConnectionErrorHandler(com.adaptris.core.jms.JmsConnectionErrorHandler) Test(org.junit.Test)

Example 90 with MockChannel

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

the class ActiveJmsConnectionErrorHandlerTest method testConnectionErrorHandler.

@Test
public void testConnectionErrorHandler() throws Exception {
    String topicName = testName.getMethodName() + "_topic";
    JmsConnection jmsCon = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true);
    jmsCon.setConnectionAttempts(null);
    MockChannel channel = createChannel(activeMqBroker, jmsCon, topicName);
    try {
        channel.requestStart();
        assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
        activeMqBroker.stop();
        log.trace("Waiting for channel death (i.e. !StartedState)");
        long totalWaitTime = waitForChannelToChangeState(StartedState.getInstance(), channel);
        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();
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) JmsConnection(com.adaptris.core.jms.JmsConnection) 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