Search in sources :

Example 46 with TimeInterval

use of com.adaptris.util.TimeInterval in project interlok by adaptris.

the class JmsConnectionErrorHandlerTest method createChannel.

private MockChannel createChannel(String channelName, EmbeddedActiveMq mq, JmsConnection con, String destinationName, JmsConnectionErrorHandler handler) throws Exception {
    MockChannel result = new MockChannel();
    result.setUniqueId(channelName);
    con.setConnectionRetryInterval(new TimeInterval(1L, TimeUnit.SECONDS.name()));
    con.setConnectionAttempts(50);
    con.setConnectionErrorHandler(handler);
    result.setConsumeConnection(con);
    Workflow workflow = createWorkflow(mq, destinationName);
    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 47 with TimeInterval

use of com.adaptris.util.TimeInterval 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 48 with TimeInterval

use of com.adaptris.util.TimeInterval in project interlok by adaptris.

the class WorkflowRetryAndFailTest method testFailedStart_ExceedsMax.

@Override
@Test
public void testFailedStart_ExceedsMax() throws Exception {
    WorkflowList wfl = new WorkflowList();
    WorkflowRetryAndFail strategy = new WorkflowRetryAndFail(2, new TimeInterval(10L, TimeUnit.MILLISECONDS.name()));
    FailStart workflow = new FailStart(3);
    wfl.add(workflow);
    wfl.setLifecycleStrategy(strategy);
    Channel c = createChannel(wfl);
    c.requestInit();
    try {
        c.requestStart();
    } catch (CoreException expected) {
    }
    // That's right 1 + 2 retries.
    assertEquals(3, workflow.getAttempts());
    assertEquals(InitialisedState.getInstance(), workflow.retrieveComponentState());
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) CoreException(com.adaptris.core.CoreException) WorkflowList(com.adaptris.core.WorkflowList) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 49 with TimeInterval

use of com.adaptris.util.TimeInterval in project interlok by adaptris.

the class WorkflowRetryAndFailTest method testFailedInitialise_ExceedsMax.

@Override
@Test
public void testFailedInitialise_ExceedsMax() throws Exception {
    WorkflowList wfl = new WorkflowList();
    WorkflowRetryAndFail strategy = new WorkflowRetryAndFail(2, new TimeInterval(10L, TimeUnit.MILLISECONDS.name()));
    FailInit workflow = new FailInit(3);
    wfl.add(workflow);
    wfl.setLifecycleStrategy(strategy);
    Channel c = createChannel(wfl);
    try {
        c.requestInit();
    } catch (CoreException expected) {
    }
    // That's right 1 + 2 retries.
    assertEquals(3, workflow.getAttempts());
    assertEquals(ClosedState.getInstance(), workflow.retrieveComponentState());
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) CoreException(com.adaptris.core.CoreException) WorkflowList(com.adaptris.core.WorkflowList) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 50 with TimeInterval

use of com.adaptris.util.TimeInterval in project interlok by adaptris.

the class JmxConnectionTest method testRemoteJmx_Retry.

@Test
public void testRemoteJmx_Retry() throws Exception {
    Integer port = PortManager.nextUnusedPort(23456);
    final JmxRemoteComponent jmxr = new JmxRemoteComponent();
    JmxConnection conn = new JmxConnection();
    try {
        jmxr.init(createProperties(port));
        conn.withJmxServiceUrl(JMXMP_PREFIX + port);
        conn.setConnectionRetryInterval(new TimeInterval(1L, TimeUnit.SECONDS));
        conn.setConnectionAttempts(10);
        Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() {

            @Override
            public void run() {
                try {
                    jmxr.start();
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
        }, 2, TimeUnit.SECONDS);
        LifecycleHelper.prepare(conn);
        LifecycleHelper.init(conn);
        assertNotNull(conn.mbeanServerConnection());
    } finally {
        LifecycleHelper.stopAndClose(conn);
        PortManager.release(port);
        destroy(jmxr);
    }
}
Also used : JmxRemoteComponent(com.adaptris.core.management.jmx.JmxRemoteComponent) TimeInterval(com.adaptris.util.TimeInterval) CoreException(com.adaptris.core.CoreException) Test(org.junit.Test)

Aggregations

TimeInterval (com.adaptris.util.TimeInterval)310 Test (org.junit.Test)249 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)86 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)49 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)42 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)40 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)38 Channel (com.adaptris.core.Channel)36 MockChannel (com.adaptris.core.stubs.MockChannel)32 File (java.io.File)28 StandardWorkflow (com.adaptris.core.StandardWorkflow)27 Adapter (com.adaptris.core.Adapter)26 GuidGenerator (com.adaptris.util.GuidGenerator)25 FilenameFilter (java.io.FilenameFilter)24 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)24 StandaloneProducer (com.adaptris.core.StandaloneProducer)23 CoreException (com.adaptris.core.CoreException)22 WaitService (com.adaptris.core.services.WaitService)22 RandomAccessFile (java.io.RandomAccessFile)21 ObjectName (javax.management.ObjectName)21