Search in sources :

Example 36 with TimeInterval

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

the class BasicJmsProducerCase method testTimedInactivitySession.

@Test
public void testTimedInactivitySession() throws Exception {
    JmsConsumerImpl consumer = createConsumer(getName());
    consumer.setAcknowledgeMode("AUTO_ACKNOWLEDGE");
    StandaloneConsumer standaloneConsumer = new StandaloneConsumer(activeMqBroker.getJmsConnection(), consumer);
    MockMessageListener jms = new MockMessageListener();
    DefinedJmsProducer producer = createProducer(getName());
    TimedInactivityProducerSessionFactory psf = new TimedInactivityProducerSessionFactory(new TimeInterval(10L, TimeUnit.MILLISECONDS));
    producer.setSessionFactory(psf);
    standaloneConsumer.registerAdaptrisMessageListener(jms);
    StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJmsConnection(), producer);
    try {
        start(standaloneConsumer, standaloneProducer);
        standaloneProducer.doService(createMessage());
        Thread.sleep(200);
        assertTrue(psf.newSessionRequired());
        // Should create a new Session now.
        standaloneProducer.doService(createMessage());
        waitForMessages(jms, 2);
        assertMessages(jms, 2);
    } finally {
        stop(standaloneProducer, standaloneConsumer);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 37 with TimeInterval

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

the class BasicPtpConsumerActiveErorHandlerTest method retrieveObjectForSampleConfig.

@Override
protected Object retrieveObjectForSampleConfig() {
    JmsConnection p = new JmsConnection(new BasicActiveMqImplementation("tcp://localhost:61616"));
    ActiveJmsConnectionErrorHandler erHandler = new ActiveJmsConnectionErrorHandler();
    erHandler.setCheckInterval(new TimeInterval(30L, TimeUnit.SECONDS));
    p.setConnectionErrorHandler(erHandler);
    return new StandaloneConsumer(p, new PtpConsumer().withQueue("TheQueueToConsumeFrom"));
}
Also used : BasicActiveMqImplementation(com.adaptris.core.jms.activemq.BasicActiveMqImplementation) TimeInterval(com.adaptris.util.TimeInterval) StandaloneConsumer(com.adaptris.core.StandaloneConsumer)

Example 38 with TimeInterval

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

the class EmbeddedActiveMq method applyCfg.

private JmsConnection applyCfg(JmsConnection con, BasicActiveMqImplementation impl, boolean useTcp) {
    if (useTcp) {
        impl.setBrokerUrl(DEF_URL_PREFIX + port);
    } else {
        impl.setBrokerUrl("vm://" + getName());
    }
    con.setClientId(createSafeUniqueId(impl));
    con.setVendorImplementation(impl);
    con.setConnectionRetryInterval(new TimeInterval(3L, TimeUnit.SECONDS));
    con.setConnectionAttempts(1);
    return con;
}
Also used : TimeInterval(com.adaptris.util.TimeInterval)

Example 39 with TimeInterval

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

the class ActiveMqJmsTransactedWorkflowTest method testHandleChannelUnavailable_Bug2343.

@Test
public void testHandleChannelUnavailable_Bug2343() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    final Channel channel = createStartableChannel(activeMqBroker, true, "testHandleChannelUnavailable_Bug2343", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    workflow.setChannelUnavailableWaitInterval(new TimeInterval(1L, TimeUnit.SECONDS));
    try {
        channel.requestStart();
        channel.toggleAvailability(false);
        Timer t = new Timer();
        t.schedule(new TimerTask() {

            @Override
            public void run() {
                channel.toggleAvailability(true);
            }
        }, 666);
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
        send(sender, msgCount);
        waitForMessages((MockMessageProducer) workflow.getProducer(), msgCount);
        assertEquals(msgCount, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
    } finally {
        channel.requestClose();
    }
    assertEquals(0, activeMqBroker.messagesOnQueue(destination));
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) Timer(java.util.Timer) TimerTask(java.util.TimerTask) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) PtpProducer(com.adaptris.core.jms.PtpProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 40 with TimeInterval

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

the class ActiveMqJmsTransactedWorkflowTest method createWorkflow.

private JmsTransactedWorkflow createWorkflow(boolean isPtp, String threadName, String target) throws CoreException {
    JmsTransactedWorkflow workflow = new JmsTransactedWorkflow();
    workflow.setWaitPeriodAfterRollback(new TimeInterval(10L, TimeUnit.MILLISECONDS.name()));
    workflow.setProducer(new MockMessageProducer());
    JmsConsumerImpl jmsCons = isPtp ? new PtpConsumer().withQueue(target) : new PasConsumer().withTopic(target);
    jmsCons.setMessageTranslator(new TextMessageTranslator().withMoveJmsHeaders(true));
    workflow.setConsumer(jmsCons);
    return workflow;
}
Also used : PtpConsumer(com.adaptris.core.jms.PtpConsumer) TimeInterval(com.adaptris.util.TimeInterval) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) PasConsumer(com.adaptris.core.jms.PasConsumer) TextMessageTranslator(com.adaptris.core.jms.TextMessageTranslator) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) JmsConsumerImpl(com.adaptris.core.jms.JmsConsumerImpl)

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