Search in sources :

Example 56 with MockMessageProducer

use of com.adaptris.core.stubs.MockMessageProducer 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)

Example 57 with MockMessageProducer

use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.

the class ActiveMqJmsTransactedWorkflowTest method testWorkflow_SkipProducer.

@Test
public void testWorkflow_SkipProducer() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    Channel channel = createStartableChannel(activeMqBroker, true, "testWorkflow_SkipProducer", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    MockMessageProducer serviceProducer = new MockMessageProducer();
    workflow.getServiceCollection().addAll(Arrays.asList(new Service[] { new StandaloneProducer(serviceProducer), new MockSkipProducerService() }));
    MockMessageProducer workflowProducer = (MockMessageProducer) workflow.getProducer();
    try {
        channel.requestStart();
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
        send(sender, msgCount);
        waitForMessages(serviceProducer, msgCount);
        assertEquals(msgCount, serviceProducer.messageCount());
        assertEquals(0, workflowProducer.messageCount());
    } finally {
        channel.requestClose();
    }
    assertEquals(0, activeMqBroker.messagesOnQueue(destination));
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) Service(com.adaptris.core.Service) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) PtpProducer(com.adaptris.core.jms.PtpProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 58 with MockMessageProducer

use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.

the class ActiveMqJmsTransactedWorkflowTest method testMessagesOrderedUsingQueue.

@Test
public void testMessagesOrderedUsingQueue() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    Channel channel = createStartableChannel(activeMqBroker, true, "testMessagesOrderedUsingQueue", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    workflow.getServiceCollection().addService(new RandomlyFail());
    try {
        channel.requestStart();
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
        start(sender);
        for (int i = 0; i < msgCount; i++) {
            sender.doService(AdaptrisMessageFactory.getDefaultInstance().newMessage("" + i));
        }
        stop(sender);
        waitForMessages((MockMessageProducer) workflow.getProducer(), msgCount);
        List<AdaptrisMessage> receivedList = ((MockMessageProducer) workflow.getProducer()).getMessages();
        assertEquals(msgCount, receivedList.size());
        for (int i = 0; i < msgCount; i++) {
            assertEquals(String.valueOf(i), receivedList.get(i).getContent());
        }
    } finally {
        channel.requestClose();
    }
    assertEquals(0, activeMqBroker.messagesOnQueue(destination));
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) 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 59 with MockMessageProducer

use of com.adaptris.core.stubs.MockMessageProducer 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 60 with MockMessageProducer

use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.

the class LargeMessageWorkflowTest method testServiceException.

@Override
@Test
public void testServiceException() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    MockMessageProducer meh = new MockMessageProducer();
    MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2), new ThrowExceptionService(new ConfiguredException("Fail")) }));
    try {
        LargeMessageWorkflow workflow = (LargeMessageWorkflow) channel.getWorkflowList().get(0);
        channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
        channel.prepare();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
        start(channel);
        workflow.onAdaptrisMessage(msg);
        assertEquals("Make none produced", 0, producer.getMessages().size());
        assertEquals(1, meh.getMessages().size());
        for (AdaptrisMessage m : meh.getMessages()) {
            assertEquals(PAYLOAD_2, m.getContent());
            assertTrue("Contains correct metadata key", m.containsKey(METADATA_KEY));
            assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
            assertNotNull(m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION));
            assertNotNull(m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE));
            assertEquals(ThrowExceptionService.class.getSimpleName(), m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE));
        }
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ServiceList(com.adaptris.core.ServiceList) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) Service(com.adaptris.core.Service) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test) StandardWorkflowTest(com.adaptris.core.StandardWorkflowTest)

Aggregations

MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)321 Test (org.junit.Test)306 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)156 MockChannel (com.adaptris.core.stubs.MockChannel)126 Channel (com.adaptris.core.Channel)125 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)73 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)69 StandaloneProducer (com.adaptris.core.StandaloneProducer)68 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)65 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)56 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)52 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)50 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)44 StandardWorkflow (com.adaptris.core.StandardWorkflow)40 TimeInterval (com.adaptris.util.TimeInterval)40 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)36 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)35 ServiceList (com.adaptris.core.ServiceList)33 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)33 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)27