Search in sources :

Example 41 with TimeInterval

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

the class ActiveMqPasPollingConsumerTest method createStandalone.

private StandaloneConsumer createStandalone(EmbeddedActiveMq mq, String threadName, String destinationName) throws Exception {
    PasPollingConsumer consumer = new PasPollingConsumer().withTopic(destinationName);
    consumer.setPoller(new Sometime());
    JmsConnection c = mq.getJmsConnection();
    consumer.setVendorImplementation(c.getVendorImplementation());
    consumer.setClientId(c.getClientId());
    consumer.setSubscriptionId(MY_SUBSCRIPTION_ID);
    consumer.setReacquireLockBetweenMessages(true);
    consumer.setAdditionalDebug(true);
    consumer.setReceiveTimeout(new TimeInterval(Integer.valueOf(new Random().nextInt(100) + 100).longValue(), TimeUnit.MILLISECONDS));
    StandaloneConsumer sc = new StandaloneConsumer(consumer);
    return sc;
}
Also used : PasPollingConsumer(com.adaptris.core.jms.PasPollingConsumer) TimeInterval(com.adaptris.util.TimeInterval) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) JmsConnection(com.adaptris.core.jms.JmsConnection) StandaloneConsumer(com.adaptris.core.StandaloneConsumer)

Example 42 with TimeInterval

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

the class ActiveJmsConnectionErrorHandlerTest method createErrorHandler.

private ActiveJmsConnectionErrorHandler createErrorHandler() {
    ActiveJmsConnectionErrorHandler handler = new ActiveJmsConnectionErrorHandler();
    handler.setAdditionalLogging(true);
    handler.setCheckInterval(new TimeInterval(500L, TimeUnit.MILLISECONDS));
    return handler;
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) ActiveJmsConnectionErrorHandler(com.adaptris.core.jms.ActiveJmsConnectionErrorHandler)

Example 43 with TimeInterval

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

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

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

the class ActiveJmsConnectionErrorHandlerTest method testConnectionErrorHandlerWhileConnectionIsClosed.

@Test
public void testConnectionErrorHandlerWhileConnectionIsClosed() 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 {
        ActiveJmsConnectionErrorHandler handler = new ActiveJmsConnectionErrorHandler();
        handler.setCheckInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS));
        handler.setAdditionalLogging(Boolean.TRUE);
        channel.getConsumeConnection().setConnectionErrorHandler(handler);
        channel.requestStart();
        assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
        channel.requestClose();
        activeMqBroker.stop();
        activeMqBroker.start();
        assertEquals(ClosedState.getInstance(), channel.retrieveComponentState());
    } finally {
        channel.requestClose();
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) TimeInterval(com.adaptris.util.TimeInterval) StandardJndiImplementation(com.adaptris.core.jms.jndi.StandardJndiImplementation) JmsConnection(com.adaptris.core.jms.JmsConnection) ActiveJmsConnectionErrorHandler(com.adaptris.core.jms.ActiveJmsConnectionErrorHandler) 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