Search in sources :

Example 61 with Channel

use of com.adaptris.core.Channel 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 62 with Channel

use of com.adaptris.core.Channel 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 63 with Channel

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

the class BasicActiveMqConsumerTest method testQueue_ProduceWhenConsumerStopped.

@Test
public void testQueue_ProduceWhenConsumerStopped() throws Exception {
    PtpConsumer consumer = new PtpConsumer().withQueue(getName());
    consumer.setAcknowledgeMode("AUTO_ACKNOWLEDGE");
    StandardWorkflow workflow = new StandardWorkflow();
    MockMessageProducer producer = new MockMessageProducer();
    workflow.setConsumer(consumer);
    workflow.setProducer(producer);
    Channel channel = createChannel(activeMqBroker.getJmsConnection(createVendorImpl()), workflow);
    try {
        StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJmsConnection(createVendorImpl()), new PtpProducer().withQueue((getName())));
        channel.requestStart();
        workflow.requestStop();
        start(standaloneProducer);
        AdaptrisMessage msg = createMessage(null);
        standaloneProducer.produce(msg);
        Thread.sleep(250);
        assertEquals(0, producer.messageCount());
        stop(standaloneProducer);
    } finally {
        channel.requestClose();
    }
}
Also used : PtpConsumer(com.adaptris.core.jms.PtpConsumer) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) PtpProducer(com.adaptris.core.jms.PtpProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 64 with Channel

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

the class ActiveMqJmsTransactedWorkflowTest method testMessagesRolledBackUsingQueue.

@Test
public void testMessagesRolledBackUsingQueue() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    Channel channel = createStartableChannel(activeMqBroker, true, "testMessagesRolledBackUsingQueue", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    workflow.getServiceCollection().addService(new ThrowExceptionService(new ConfiguredException("Fail")));
    try {
        channel.requestStart();
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
        send(sender, msgCount);
    } finally {
        channel.requestClose();
    }
    assertEquals(msgCount, activeMqBroker.messagesOnQueue(destination));
}
Also used : ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) PtpProducer(com.adaptris.core.jms.PtpProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 65 with Channel

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

the class ActiveMqJmsTransactedWorkflowTest method testMessagesCommittedUsingQueue.

@Test
public void testMessagesCommittedUsingQueue() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    Channel channel = createStartableChannel(activeMqBroker, true, "testMessagesCommittedUsingQueue", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    try {
        channel.requestStart();
        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 : 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)

Aggregations

Channel (com.adaptris.core.Channel)322 Test (org.junit.Test)276 Adapter (com.adaptris.core.Adapter)136 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)125 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)122 StandardWorkflow (com.adaptris.core.StandardWorkflow)111 ObjectName (javax.management.ObjectName)97 ArrayList (java.util.ArrayList)74 StandaloneProducer (com.adaptris.core.StandaloneProducer)64 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)57 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)52 Workflow (com.adaptris.core.Workflow)44 MockChannel (com.adaptris.core.stubs.MockChannel)43 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)37 TimeInterval (com.adaptris.util.TimeInterval)36 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)35 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)35 ServiceList (com.adaptris.core.ServiceList)31 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)30 CoreException (com.adaptris.core.CoreException)29