Search in sources :

Example 6 with MockChannel

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

the class JmsTransactedWorkflowTest method createPlainChannel.

private Channel createPlainChannel() throws Exception {
    GuidGenerator guid = new GuidGenerator();
    Channel result = new MockChannel();
    result.setUniqueId(guid.create(result));
    result.setMessageErrorHandler(new NullProcessingExceptionHandler());
    return result;
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) GuidGenerator(com.adaptris.util.GuidGenerator) NullProcessingExceptionHandler(com.adaptris.core.NullProcessingExceptionHandler)

Example 7 with MockChannel

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

the class FailoverJmsConsumerCase method testBug1012.

@Test
public void testBug1012() throws Exception {
    FailoverJmsConnection connection = new FailoverJmsConnection();
    try {
        List<JmsConnection> ptp = new ArrayList<JmsConnection>();
        ptp.add(activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true));
        ptp.add(activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), false));
        connection.setConnections(ptp);
        LifecycleHelper.init(connection);
        assertEquals(1, connection.currentJmsConnection().retrieveExceptionListeners().size());
        AdaptrisComponent owner = (AdaptrisComponent) connection.currentJmsConnection().retrieveExceptionListeners().toArray()[0];
        assertTrue("Owner should be failover connection", connection == owner);
        LifecycleHelper.close(connection);
        Channel channel = new MockChannel();
        connection = new FailoverJmsConnection();
        connection.setRegisterOwner(true);
        channel.setConsumeConnection(connection);
        ptp = new ArrayList<JmsConnection>();
        ptp.add(activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true));
        ptp.add(activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), false));
        connection.setConnections(ptp);
        connection.setConnectionAttempts(1);
        LifecycleHelper.init(connection);
        assertEquals(0, connection.currentJmsConnection().retrieveExceptionListeners().size());
        LifecycleHelper.close(connection);
    } finally {
        LifecycleHelper.close(connection);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) BasicActiveMqImplementation(com.adaptris.core.jms.activemq.BasicActiveMqImplementation) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) ArrayList(java.util.ArrayList) AdaptrisComponent(com.adaptris.core.AdaptrisComponent) Test(org.junit.Test)

Example 8 with MockChannel

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

the class ActiveJmsConnectionErrorHandlerTest method createChannel.

private MockChannel createChannel(EmbeddedActiveMq mq, JmsConnection con, String destName) throws Exception {
    MockChannel result = new MockChannel();
    result.setUniqueId(testName.getMethodName() + "_channel");
    con.setConnectionRetryInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS.name()));
    con.setConnectionAttempts(50);
    con.setConnectionErrorHandler(createErrorHandler());
    result.setConsumeConnection(con);
    Workflow workflow = createWorkflow(mq, destName);
    result.getWorkflowList().add(workflow);
    return result;
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) TimeInterval(com.adaptris.util.TimeInterval) StandardWorkflow(com.adaptris.core.StandardWorkflow) Workflow(com.adaptris.core.Workflow)

Example 9 with MockChannel

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

the class ActiveJmsConnectionErrorHandlerTest method testActiveRestartSharedConnection.

@Test
public void testActiveRestartSharedConnection() throws Exception {
    Adapter adapter = new Adapter();
    adapter.setUniqueId(testName.getMethodName());
    JmsConnection connection = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true);
    connection.setConnectionErrorHandler(createErrorHandler());
    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);
        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) Test(org.junit.Test)

Example 10 with MockChannel

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

the class ActiveJmsConnectionErrorHandlerTest 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)

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