Search in sources :

Example 16 with Adapter

use of com.adaptris.core.Adapter in project interlok by adaptris.

the class BasicActiveMqConsumerTest method createDurableSubsAdapter.

private Adapter createDurableSubsAdapter(String adapterName, EmbeddedActiveMq activeMqBroker) throws Exception {
    Adapter adapter = new Adapter();
    adapter.setUniqueId(adapterName);
    Channel c = new Channel();
    JmsConnection conn = activeMqBroker.getJmsConnection(createVendorImpl());
    conn.setClientId(MY_CLIENT_ID);
    c.setConsumeConnection(conn);
    StandardWorkflow swf = new StandardWorkflow();
    PasConsumer pasConsumer = new PasConsumer().withTopic(new GuidGenerator().safeUUID());
    pasConsumer.setSubscriptionId(MY_SUBSCRIPTION_ID);
    swf.setConsumer(pasConsumer);
    c.getWorkflowList().add(swf);
    ChannelList cl = new ChannelList();
    cl.addChannel(c);
    adapter.setChannelList(cl);
    return adapter;
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) PasConsumer(com.adaptris.core.jms.PasConsumer) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) Adapter(com.adaptris.core.Adapter) JmsConnection(com.adaptris.core.jms.JmsConnection) GuidGenerator(com.adaptris.util.GuidGenerator) ChannelList(com.adaptris.core.ChannelList)

Example 17 with Adapter

use of com.adaptris.core.Adapter in project interlok by adaptris.

the class BasicActiveMqConsumerTest method testStartWithDurableSubscribers_WithNonBlockingChannelStrategy.

@Test
public void testStartWithDurableSubscribers_WithNonBlockingChannelStrategy() throws Exception {
    Adapter adapter = createDurableSubsAdapter(getName(), activeMqBroker);
    adapter.requestStart();
    assertEquals(StartedState.getInstance(), adapter.retrieveComponentState());
    adapter.requestClose();
    assertEquals(ClosedState.getInstance(), adapter.retrieveComponentState());
    adapter.getChannelList().setLifecycleStrategy(new NonBlockingChannelStartStrategy());
    adapter.requestStart();
    // Thread.sleep(1000);
    Channel c = adapter.getChannelList().getChannel(0);
    int maxAttempts = 100;
    int attempts = 0;
    while (attempts < maxAttempts && c.retrieveComponentState() != StartedState.getInstance()) {
        Thread.sleep(500);
        attempts++;
    }
    assertEquals(StartedState.getInstance(), c.retrieveComponentState());
    adapter.requestClose();
}
Also used : NonBlockingChannelStartStrategy(com.adaptris.core.lifecycle.NonBlockingChannelStartStrategy) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) Adapter(com.adaptris.core.Adapter) Test(org.junit.Test)

Example 18 with Adapter

use of com.adaptris.core.Adapter 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 19 with Adapter

use of com.adaptris.core.Adapter in project interlok by adaptris.

the class JmsConnectionErrorHandlerTest method testRestartSharedConnection_ChannelNotStarted.

@Test
public void testRestartSharedConnection_ChannelNotStarted() 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 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) JmsConnectionErrorHandler(com.adaptris.core.jms.JmsConnectionErrorHandler) Test(org.junit.Test)

Example 20 with Adapter

use of com.adaptris.core.Adapter in project interlok by adaptris.

the class FilteredSharedComponentStartTest method testNonBlockingStart.

@Test
public void testNonBlockingStart() throws Exception {
    Adapter adapter = new Adapter();
    adapter.setUniqueId(getName());
    TriggeredMockConnection sharedConnection = new TriggeredMockConnection(getName());
    try {
        adapter.getSharedComponents().addConnection(sharedConnection);
        adapter.getSharedComponents().setLifecycleStrategy(new FilteredSharedComponentStart(true));
        adapter.requestInit();
        // Will return straight away.
        assertEquals(InitialisedState.getInstance(), adapter.retrieveComponentState());
        assertNotSame(InitialisedState.getInstance(), sharedConnection.retrieveComponentState());
        sharedConnection.wakeup = true;
        waitFor(sharedConnection, InitialisedState.getInstance());
        assertEquals(InitialisedState.getInstance(), sharedConnection.retrieveComponentState());
        sharedConnection.wakeup = false;
        adapter.requestStart();
        assertEquals(StartedState.getInstance(), adapter.retrieveComponentState());
        assertNotSame(StartedState.getInstance(), sharedConnection.retrieveComponentState());
        sharedConnection.wakeup = true;
        waitFor(sharedConnection, StartedState.getInstance());
        assertEquals(StartedState.getInstance(), sharedConnection.retrieveComponentState());
        stop(adapter);
        // Initialise again, to make sure that we can.
        sharedConnection.wakeup = false;
        adapter.requestInit();
        // Will return straight away.
        assertEquals(InitialisedState.getInstance(), adapter.retrieveComponentState());
        assertNotSame(InitialisedState.getInstance(), sharedConnection.retrieveComponentState());
        sharedConnection.wakeup = true;
        waitFor(sharedConnection, InitialisedState.getInstance());
        assertEquals(InitialisedState.getInstance(), sharedConnection.retrieveComponentState());
    } finally {
        stop(adapter);
    }
}
Also used : Adapter(com.adaptris.core.Adapter) Test(org.junit.Test)

Aggregations

Adapter (com.adaptris.core.Adapter)342 Test (org.junit.Test)318 ObjectName (javax.management.ObjectName)234 Channel (com.adaptris.core.Channel)136 StandardWorkflow (com.adaptris.core.StandardWorkflow)93 ArrayList (java.util.ArrayList)80 URLString (com.adaptris.util.URLString)48 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)47 Properties (java.util.Properties)46 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)43 BootstrapProperties (com.adaptris.core.management.BootstrapProperties)41 Workflow (com.adaptris.core.Workflow)40 JunitBootstrapProperties (com.adaptris.core.stubs.JunitBootstrapProperties)40 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)38 File (java.io.File)37 CoreException (com.adaptris.core.CoreException)32 Notification (javax.management.Notification)28 TimeInterval (com.adaptris.util.TimeInterval)26 BaseComponentMBean (com.adaptris.core.runtime.BaseComponentMBean)25 NullConnection (com.adaptris.core.NullConnection)21