Search in sources :

Example 6 with SensingNullMessageProcessor

use of org.mule.tck.SensingNullMessageProcessor in project mule by mulesoft.

the class AsyncRequestReplyRequesterTestCase method testResponseEventsCleanedUp.

@Test
public void testResponseEventsCleanedUp() throws Exception {
    RelaxedAsyncReplyMP mp = new RelaxedAsyncReplyMP(muleContext);
    try {
        CoreEvent event = eventBuilder(muleContext).message(of("message1")).groupCorrelation(Optional.of(GroupCorrelation.of(0, 3))).build();
        SensingNullMessageProcessor listener = getSensingNullMessageProcessor();
        mp.setListener(listener);
        mp.setReplySource(listener.getMessageSource());
        mp.process(event);
        Map<String, PrivilegedEvent> responseEvents = mp.getResponseEvents();
        assertThat(responseEvents.entrySet(), empty());
    } finally {
        mp.stop();
    }
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Test(org.junit.Test)

Example 7 with SensingNullMessageProcessor

use of org.mule.tck.SensingNullMessageProcessor in project mule by mulesoft.

the class AsyncRequestReplyRequesterTestCase method testSingleEventTimeout.

@Test
public void testSingleEventTimeout() throws Exception {
    asyncReplyMP = new TestAsyncRequestReplyRequester(muleContext);
    asyncReplyMP.setTimeout(1);
    SensingNullMessageProcessor target = getSensingNullMessageProcessor();
    target.setWaitTime(30000);
    AsyncDelegateMessageProcessor asyncMP = createAsyncMessageProcessor(target);
    initialiseIfNeeded(asyncMP, true, muleContext);
    asyncMP.start();
    asyncReplyMP.setListener(asyncMP);
    asyncReplyMP.setReplySource(target.getMessageSource());
    asyncReplyMP.setMuleContext(muleContext);
    CoreEvent event = eventBuilder(muleContext).message(of(TEST_MESSAGE)).build();
    try {
        asyncReplyMP.process(event);
        fail("ResponseTimeoutException expected");
    } catch (Exception e) {
        assertThat(e, instanceOf(ResponseTimeoutException.class));
    }
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) AsyncDelegateMessageProcessor(org.mule.runtime.core.internal.processor.AsyncDelegateMessageProcessor) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ResponseTimeoutException(org.mule.runtime.core.privileged.routing.ResponseTimeoutException) MuleException(org.mule.runtime.api.exception.MuleException) Test(org.junit.Test)

Example 8 with SensingNullMessageProcessor

use of org.mule.tck.SensingNullMessageProcessor in project mule by mulesoft.

the class AsyncRequestReplyRequesterTestCase method testSingleEventNoTimeoutAsync.

@Test
public void testSingleEventNoTimeoutAsync() throws Exception {
    asyncReplyMP = new TestAsyncRequestReplyRequester(muleContext);
    SensingNullMessageProcessor target = getSensingNullMessageProcessor();
    AsyncDelegateMessageProcessor asyncMP = createAsyncMessageProcessor(target);
    initialiseIfNeeded(asyncMP, true, muleContext);
    asyncMP.start();
    asyncReplyMP.setListener(asyncMP);
    asyncReplyMP.setReplySource(target.getMessageSource());
    asyncReplyMP.setMuleContext(muleContext);
    CoreEvent resultEvent = asyncReplyMP.process(testEvent());
    // Can't assert same because we copy event for async and also on async reply currently
    assertEquals(((PrivilegedEvent) testEvent()).getMessageAsString(muleContext), ((PrivilegedEvent) resultEvent).getMessageAsString(muleContext));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) AsyncDelegateMessageProcessor(org.mule.runtime.core.internal.processor.AsyncDelegateMessageProcessor) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Test(org.junit.Test)

Example 9 with SensingNullMessageProcessor

use of org.mule.tck.SensingNullMessageProcessor in project mule by mulesoft.

the class DefaultSchedulerMessageSourceTestCase method simplePoll.

@Test
public void simplePoll() throws Exception {
    DefaultSchedulerMessageSource schedulerMessageSource = createMessageSource();
    SensingNullMessageProcessor flow = getSensingNullMessageProcessor();
    schedulerMessageSource.setListener(flow);
    schedulerMessageSource.setAnnotations(singletonMap(LOCATION_KEY, TEST_CONNECTOR_LOCATION));
    schedulerMessageSource.trigger();
    new PollingProber(RECEIVE_TIMEOUT, 100).check(new Probe() {

        @Override
        public boolean isSatisfied() {
            return flow.event != null;
        }

        @Override
        public String describeFailure() {
            return "flow event never set by the source flow";
        }
    });
}
Also used : DefaultSchedulerMessageSource(org.mule.runtime.core.internal.source.scheduler.DefaultSchedulerMessageSource) PollingProber(org.mule.tck.probe.PollingProber) Probe(org.mule.tck.probe.Probe) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Test(org.junit.Test)

Example 10 with SensingNullMessageProcessor

use of org.mule.tck.SensingNullMessageProcessor in project mule by mulesoft.

the class ForeachTestCase method failingNestedProcessorInChain.

@Test
public void failingNestedProcessorInChain() throws Exception {
    RuntimeException throwable = new BufferOverflowException();
    Foreach foreach = createForeach();
    SensingNullMessageProcessor firstProcessor = new SensingNullMessageProcessor();
    InternalTestProcessor failingProcessor = event -> {
        throw throwable;
    };
    foreach.setMessageProcessors(asList(firstProcessor, failingProcessor));
    initialiseIfNeeded(foreach, muleContext);
    try {
        expectNestedProessorException(throwable, failingProcessor);
        processInChain(foreach, eventBuilder(muleContext).message(of(new DummyNestedIterableClass().iterator())).build());
    } finally {
        assertThat(firstProcessor.invocations, equalTo(1));
    }
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) MessageProcessors.newChain(org.mule.runtime.core.privileged.processor.MessageProcessors.newChain) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Message(org.mule.runtime.api.message.Message) BufferOverflowException(java.nio.BufferOverflowException) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) Matchers.hasItems(org.hamcrest.Matchers.hasItems) Processor(org.mule.runtime.core.api.processor.Processor) DEFAULT_COUNTER_VARIABLE(org.mule.runtime.core.internal.routing.Foreach.DEFAULT_COUNTER_VARIABLE) ArrayList(java.util.ArrayList) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) BaseMatcher(org.hamcrest.BaseMatcher) ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ExpectedException.none(org.junit.rules.ExpectedException.none) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MULE_MESSAGE(org.mule.runtime.api.metadata.DataType.MULE_MESSAGE) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Collections.singletonMap(java.util.Collections.singletonMap) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) Description(org.hamcrest.Description) Iterator(java.util.Iterator) DataType(org.mule.runtime.api.metadata.DataType) Collections.emptyList(java.util.Collections.emptyList) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Message.of(org.mule.runtime.api.message.Message.of) DataTypeCompatibilityMatcher.assignableTo(org.mule.tck.junit4.matcher.DataTypeCompatibilityMatcher.assignableTo) TypedValue(org.mule.runtime.api.metadata.TypedValue) Collectors.toList(java.util.stream.Collectors.toList) DEFAULT_ROOT_MESSAGE_VARIABLE(org.mule.runtime.core.internal.routing.Foreach.DEFAULT_ROOT_MESSAGE_VARIABLE) List(java.util.List) AbstractReactiveProcessorTestCase(org.mule.tck.junit4.AbstractReactiveProcessorTestCase) Rule(org.junit.Rule) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) TestMessageProcessor(org.mule.tck.testmodels.mule.TestMessageProcessor) Assert.assertEquals(org.junit.Assert.assertEquals) ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) BufferOverflowException(java.nio.BufferOverflowException) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Test(org.junit.Test)

Aggregations

SensingNullMessageProcessor (org.mule.tck.SensingNullMessageProcessor)14 Test (org.junit.Test)13 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)9 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Collectors.toList (java.util.stream.Collectors.toList)4 MuleException (org.mule.runtime.api.exception.MuleException)4 Message (org.mule.runtime.api.message.Message)4 Processor (org.mule.runtime.core.api.processor.Processor)4 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)4 ExpressionRuntimeException (org.mule.runtime.core.api.expression.ExpressionRuntimeException)3 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)3 BufferOverflowException (java.nio.BufferOverflowException)2 Arrays.asList (java.util.Arrays.asList)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonMap (java.util.Collections.singletonMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Optional (java.util.Optional)2 BaseMatcher (org.hamcrest.BaseMatcher)2