Search in sources :

Example 1 with PtpProducer

use of com.adaptris.core.jms.PtpProducer in project interlok by adaptris.

the class DestinationCacheJndiPtpProducerTest method testProduceWithCache.

@Test
public void testProduceWithCache() throws Exception {
    DestinationCachingJndiVendorImpl sendVendorImp = new DestinationCachingJndiVendorImpl();
    sendVendorImp.setUseJndiForQueues(true);
    String queueName = testName.getMethodName() + "_queue";
    String topicName = testName.getMethodName() + "_topic";
    StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJndiPtpConnection(sendVendorImp, false, queueName, topicName), new PtpProducer().withQueue((queueName)));
    try {
        start(standaloneProducer);
        standaloneProducer.doService(createMessage(null));
        standaloneProducer.doService(createMessage(null));
        assertEquals(1, sendVendorImp.queueCacheSize());
        assertTrue(sendVendorImp.queueCache().containsKey(queueName));
    } finally {
        stop(standaloneProducer);
    }
}
Also used : PtpProducer(com.adaptris.core.jms.PtpProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 2 with PtpProducer

use of com.adaptris.core.jms.PtpProducer 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 3 with PtpProducer

use of com.adaptris.core.jms.PtpProducer in project interlok by adaptris.

the class ActiveMqJmsTransactedWorkflowTest method testServiceExceptionNonStrictWithErrorHandler.

// In Non-Strict Mode, if you have configured an error handler, then
// the transaction is successful.
@Test
public void testServiceExceptionNonStrictWithErrorHandler() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    MockMessageProducer meh = new MockMessageProducer();
    Channel channel = createStartableChannel(activeMqBroker, true, "testServiceExceptionNonStrictWithErrorHandler", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    workflow.setStrict(Boolean.FALSE);
    workflow.getServiceCollection().addService(new ThrowExceptionService(new ConfiguredException("Fail")));
    channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
    channel.prepare();
    try {
        channel.requestStart();
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
        send(sender, msgCount);
        waitForMessages(meh, msgCount);
        assertEquals(0, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
    } finally {
        channel.requestClose();
    }
    assertEquals(0, activeMqBroker.messagesOnQueue(destination));
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ServiceList(com.adaptris.core.ServiceList) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Service(com.adaptris.core.Service) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) PtpProducer(com.adaptris.core.jms.PtpProducer) StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 4 with PtpProducer

use of com.adaptris.core.jms.PtpProducer in project interlok by adaptris.

the class AdvancedActiveMqProducerTest method retrieveObjectForSampleConfig.

@Override
protected Object retrieveObjectForSampleConfig() {
    JmsConnection connection = new JmsConnection();
    PtpProducer producer = new PtpProducer();
    producer.setQueue("destination");
    UrlVendorImplementation vendorImpl = createImpl();
    vendorImpl.setBrokerUrl(BasicActiveMqImplementationTest.PRIMARY);
    connection.setUserName("BrokerUsername");
    connection.setPassword("BrokerPassword");
    connection.setVendorImplementation(vendorImpl);
    StandaloneProducer result = new StandaloneProducer();
    result.setConnection(connection);
    result.setProducer(producer);
    return result;
}
Also used : UrlVendorImplementation(com.adaptris.core.jms.UrlVendorImplementation) JmsConnection(com.adaptris.core.jms.JmsConnection) PtpProducer(com.adaptris.core.jms.PtpProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer)

Example 5 with PtpProducer

use of com.adaptris.core.jms.PtpProducer in project interlok by adaptris.

the class AdvancedActiveMqProducerTest method testQueueProduceAndConsumeWithPrefetch.

@Test
public void testQueueProduceAndConsumeWithPrefetch() throws Exception {
    PtpConsumer consumer = new PtpConsumer().withQueue(getName());
    consumer.setAcknowledgeMode("AUTO_ACKNOWLEDGE");
    StandaloneConsumer standaloneConsumer = new StandaloneConsumer(activeMqBroker.getJmsConnection(createVendorImpl(null, createPrefetch())), consumer);
    MockMessageListener jms = new MockMessageListener();
    standaloneConsumer.registerAdaptrisMessageListener(jms);
    StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJmsConnection(createVendorImpl(null, createPrefetch())), new PtpProducer().withQueue((getName())));
    execute(standaloneConsumer, standaloneProducer, createMessage(), jms);
    assertMessages(jms, 1);
}
Also used : PtpConsumer(com.adaptris.core.jms.PtpConsumer) PtpProducer(com.adaptris.core.jms.PtpProducer) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Aggregations

PtpProducer (com.adaptris.core.jms.PtpProducer)52 StandaloneProducer (com.adaptris.core.StandaloneProducer)46 Test (org.junit.Test)46 PtpConsumer (com.adaptris.core.jms.PtpConsumer)24 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)23 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)23 MockChannel (com.adaptris.core.stubs.MockChannel)14 Channel (com.adaptris.core.Channel)13 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)12 JmsTransactedWorkflow (com.adaptris.core.jms.JmsTransactedWorkflow)12 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)10 JmsConnection (com.adaptris.core.jms.JmsConnection)8 StandardJndiImplementation (com.adaptris.core.jms.jndi.StandardJndiImplementation)6 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)6 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)5 BytesMessageTranslator (com.adaptris.core.jms.BytesMessageTranslator)4 TimeInterval (com.adaptris.util.TimeInterval)4 ProduceException (com.adaptris.core.ProduceException)3 Service (com.adaptris.core.Service)3 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)3