Search in sources :

Example 6 with Flow

use of org.mule.runtime.core.api.construct.Flow in project mule by mulesoft.

the class AggregatorTestCase method testMessageAggregator.

@Test
public void testMessageAggregator() throws Exception {
    Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
    MuleSession session = new DefaultMuleSession();
    TestEventAggregator router = new TestEventAggregator(3);
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    initialiseIfNeeded(router, true, muleContext);
    EventContext context = create(flow, TEST_CONNECTOR_LOCATION, "foo");
    Message message1 = Message.of("test event A");
    Message message2 = Message.of("test event B");
    Message message3 = Message.of("test event C");
    CoreEvent event1 = InternalEvent.builder(context).message(message1).session(session).build();
    CoreEvent event2 = InternalEvent.builder(context).message(message2).session(session).build();
    CoreEvent event3 = InternalEvent.builder(context).message(message3).session(session).build();
    assertNull(router.process(event1));
    assertNull(router.process(event2));
    CoreEvent result = router.process(event3);
    assertNotNull(result);
    PrivilegedEvent privilegedResult = (PrivilegedEvent) result;
    assertTrue(privilegedResult.getMessageAsString(muleContext).contains("test event A"));
    assertTrue(privilegedResult.getMessageAsString(muleContext).contains("test event B"));
    assertTrue(privilegedResult.getMessageAsString(muleContext).contains("test event C"));
    assertTrue(privilegedResult.getMessageAsString(muleContext).matches("test event [A,B,C] test event [A,B,C] test event [A,B,C] "));
}
Also used : EventContext(org.mule.runtime.api.event.EventContext) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DefaultMuleSession(org.mule.runtime.core.privileged.event.DefaultMuleSession) MuleSession(org.mule.runtime.core.privileged.event.MuleSession) DefaultMuleSession(org.mule.runtime.core.privileged.event.DefaultMuleSession) MuleTestUtils.createAndRegisterFlow(org.mule.tck.MuleTestUtils.createAndRegisterFlow) Flow(org.mule.runtime.core.api.construct.Flow) Test(org.junit.Test)

Example 7 with Flow

use of org.mule.runtime.core.api.construct.Flow in project mule by mulesoft.

the class RegistryTransformerLifecycleTestCase method testLifecycleInFlowTransientRegistry.

@Test
public void testLifecycleInFlowTransientRegistry() throws Exception {
    TransformerLifecycleTracker transformer = new TransformerLifecycleTracker();
    transformer.setProperty("foo");
    Flow flow = builder("flow", muleContext).processors(transformer).build();
    ((MuleContextWithRegistries) muleContext).getRegistry().registerFlowConstruct(flow);
    muleContext.dispose();
    assertLifecycle(transformer);
}
Also used : Flow(org.mule.runtime.core.api.construct.Flow) Test(org.junit.Test)

Example 8 with Flow

use of org.mule.runtime.core.api.construct.Flow in project mule by mulesoft.

the class MessageProcessorsTestCase method setup.

@Before
public void setup() throws MuleException {
    flow = mock(Flow.class, RETURNS_DEEP_STUBS);
    OnErrorPropagateHandler exceptionHandler = new OnErrorPropagateHandler();
    exceptionHandler.setMuleContext(muleContext);
    exceptionHandler.setNotificationFirer(((MuleContextWithRegistries) muleContext).getRegistry().lookupObject(NotificationDispatcher.class));
    exceptionHandler.initialise();
    when(flow.getExceptionListener()).thenReturn(exceptionHandler);
    eventContext = (BaseEventContext) create(flow, TEST_CONNECTOR_LOCATION);
    input = builder(eventContext).message(of(TEST_MESSAGE)).build();
    output = builder(eventContext).message(of(TEST_MESSAGE)).build();
    response = builder(eventContext).message(of(TEST_MESSAGE)).build();
    responsePublisher = eventContext.getResponsePublisher();
}
Also used : MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) OnErrorPropagateHandler(org.mule.runtime.core.internal.exception.OnErrorPropagateHandler) Flow(org.mule.runtime.core.api.construct.Flow) Before(org.junit.Before)

Example 9 with Flow

use of org.mule.runtime.core.api.construct.Flow in project mule by mulesoft.

the class ReactiveInterceptorAdapterTestCase method interceptorThrowsExceptionAroundAfterProceedInCallbackChained.

@Test
public void interceptorThrowsExceptionAroundAfterProceedInCallbackChained() throws Exception {
    RuntimeException expectedException = new RuntimeException("Some Error");
    ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {

        @Override
        public CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action) {
            return action.proceed().thenApplyAsync(e -> {
                throw expectedException;
            });
        }
    });
    startFlowWithInterceptors(interceptor);
    expected.expect(MessagingException.class);
    expected.expect(withEventThat(hasErrorType(UNKNOWN.getNamespace(), UNKNOWN.getName())));
    expected.expectCause(sameInstance(expectedException));
    try {
        process(flow, eventBuilder(muleContext).message(Message.of("")).build());
    } finally {
        if (useMockInterceptor) {
            InOrder inOrder = inOrder(processor, interceptor);
            inOrder.verify(interceptor).before(any(), any(), any());
            inOrder.verify(interceptor).around(any(), any(), any(), any());
            inOrder.verify(processor).process(any());
            inOrder.verify(interceptor).after(any(), any(), eq(of(expectedException)));
            verifyParametersResolvedAndDisposed(times(1));
        }
    }
}
Also used : Schedulers.fromExecutorService(reactor.core.scheduler.Schedulers.fromExecutorService) Message(org.mule.runtime.api.message.Message) Optional.of(java.util.Optional.of) Matchers.not(org.hamcrest.Matchers.not) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Thread.currentThread(java.lang.Thread.currentThread) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) ParametersResolverProcessor(org.mule.runtime.core.internal.processor.ParametersResolverProcessor) TypedComponentIdentifier.builder(org.mule.runtime.api.component.TypedComponentIdentifier.builder) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Matchers.any(org.mockito.Matchers.any) VerificationMode(org.mockito.verification.VerificationMode) Matchers.argThat(org.mockito.Matchers.argThat) QName(javax.xml.namespace.QName) Mockito.mock(org.mockito.Mockito.mock) Optional.empty(java.util.Optional.empty) ComponentIdentifier.buildFromStringRepresentation(org.mule.runtime.api.component.ComponentIdentifier.buildFromStringRepresentation) DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation) RunWith(org.junit.runner.RunWith) Mockito.spy(org.mockito.Mockito.spy) OPERATION(org.mule.runtime.api.component.TypedComponentIdentifier.ComponentType.OPERATION) EventMatcher.hasErrorTypeThat(org.mule.tck.junit4.matcher.EventMatcher.hasErrorTypeThat) ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingExceptionMatcher.withEventThat(org.mule.tck.junit4.matcher.MessagingExceptionMatcher.withEventThat) Component(org.mule.runtime.api.component.Component) Mono.from(reactor.core.publisher.Mono.from) BiConsumer(java.util.function.BiConsumer) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) Before(org.junit.Before) Disposable(org.mule.runtime.api.lifecycle.Disposable) ProcessorParameterValue(org.mule.runtime.api.interception.ProcessorParameterValue) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Mockito.never(org.mockito.Mockito.never) Matcher(org.hamcrest.Matcher) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) Flow.builder(org.mule.runtime.core.api.construct.Flow.builder) PollingProber(org.mule.tck.probe.PollingProber) Assert.assertThat(org.junit.Assert.assertThat) SmallTest(org.mule.tck.size.SmallTest) Scheduler(org.mule.runtime.api.scheduler.Scheduler) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) Parameterized(org.junit.runners.Parameterized) IsMapContaining.hasEntry(org.hamcrest.collection.IsMapContaining.hasEntry) TypedComponentIdentifier(org.mule.runtime.api.component.TypedComponentIdentifier) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Flow(org.mule.runtime.core.api.construct.Flow) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) Mockito.inOrder(org.mockito.Mockito.inOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ErrorType(org.mule.runtime.api.message.ErrorType) Optional(java.util.Optional) ANNOTATION_PARAMETERS(org.mule.runtime.core.internal.component.ComponentAnnotations.ANNOTATION_PARAMETERS) ProcessorInterceptor(org.mule.runtime.api.interception.ProcessorInterceptor) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) Parameters(org.junit.runners.Parameterized.Parameters) InterceptionAction(org.mule.runtime.api.interception.InterceptionAction) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Processor(org.mule.runtime.core.api.processor.Processor) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) DefaultLocationPart(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation.DefaultLocationPart) ProcessorInterceptorFactory(org.mule.runtime.api.interception.ProcessorInterceptorFactory) Inject(javax.inject.Inject) CompletableFuture.supplyAsync(java.util.concurrent.CompletableFuture.supplyAsync) ExpectedException.none(org.junit.rules.ExpectedException.none) CPU_LITE_ASYNC(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.CPU_LITE_ASYNC) Collections.singletonMap(java.util.Collections.singletonMap) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) ExpectedException(org.junit.rules.ExpectedException) EventMatcher.hasErrorType(org.mule.tck.junit4.matcher.EventMatcher.hasErrorType) SchedulerConfig(org.mule.runtime.api.scheduler.SchedulerConfig) CheckedConsumer(org.mule.runtime.core.api.util.func.CheckedConsumer) ExecutionContext(org.mule.runtime.extension.api.runtime.operation.ExecutionContext) Description(org.hamcrest.Description) InOrder(org.mockito.InOrder) Mockito.when(org.mockito.Mockito.when) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) Mockito.verify(org.mockito.Mockito.verify) UNKNOWN(org.mule.runtime.core.api.exception.Errors.ComponentIdentifiers.Handleable.UNKNOWN) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) Collectors.toList(java.util.stream.Collectors.toList) LazyValue(org.mule.runtime.api.util.LazyValue) Rule(org.junit.Rule) IsSame.sameInstance(org.hamcrest.core.IsSame.sameInstance) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) CompletableFuture(java.util.concurrent.CompletableFuture) ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) InOrder(org.mockito.InOrder) ProcessorInterceptor(org.mule.runtime.api.interception.ProcessorInterceptor) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) ProcessorParameterValue(org.mule.runtime.api.interception.ProcessorParameterValue) InterceptionAction(org.mule.runtime.api.interception.InterceptionAction) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 10 with Flow

use of org.mule.runtime.core.api.construct.Flow in project mule by mulesoft.

the class AbstractProcessingStrategyTestCase method testAsyncCpuLightNotificationThreads.

protected void testAsyncCpuLightNotificationThreads(AtomicReference<Thread> beforeThread, AtomicReference<Thread> afterThread) throws Exception {
    muleContext.getNotificationManager().addInterfaceToType(MessageProcessorNotificationListener.class, MessageProcessorNotification.class);
    muleContext.getNotificationManager().addListener((MessageProcessorNotificationListener) notification -> {
        if (new IntegerAction(MESSAGE_PROCESSOR_PRE_INVOKE).equals(notification.getAction())) {
            beforeThread.set(currentThread());
        } else if (new IntegerAction(MESSAGE_PROCESSOR_POST_INVOKE).equals(notification.getAction())) {
            afterThread.set(currentThread());
        }
    });
    flow = flowBuilder.get().processors(annotatedAsyncProcessor).build();
    flow.initialise();
    flow.start();
    processFlow(testEvent());
}
Also used : Schedulers.fromExecutorService(reactor.core.scheduler.Schedulers.fromExecutorService) Thread.currentThread(java.lang.Thread.currentThread) IO_RW(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.IO_RW) DEFAULT_TIMEOUT(org.mule.tck.probe.PollingProber.DEFAULT_TIMEOUT) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Future(java.util.concurrent.Future) LifecycleUtils.setMuleContextIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.setMuleContextIfNeeded) Arrays.asList(java.util.Arrays.asList) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) NamedThreadFactory(org.mule.runtime.core.api.util.concurrent.NamedThreadFactory) SOURCE(org.mule.runtime.core.internal.processor.strategy.AbstractProcessingStrategyTestCase.Mode.SOURCE) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Operators.requestUnbounded(org.mule.runtime.core.internal.util.rx.Operators.requestUnbounded) Builder(org.mule.runtime.core.api.construct.Flow.Builder) CountDownLatch(java.util.concurrent.CountDownLatch) Matchers.contains(org.hamcrest.Matchers.contains) DEFAULT_POLLING_INTERVAL(org.mule.tck.probe.PollingProber.DEFAULT_POLLING_INTERVAL) TriggerableMessageSource(org.mule.tck.TriggerableMessageSource) RunWith(org.junit.runner.RunWith) Callable(java.util.concurrent.Callable) Supplier(java.util.function.Supplier) MESSAGE_PROCESSOR_POST_INVOKE(org.mule.runtime.api.notification.MessageProcessorNotification.MESSAGE_PROCESSOR_POST_INVOKE) ArrayList(java.util.ArrayList) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleException(org.mule.runtime.api.exception.MuleException) Before(org.junit.Before) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) EventContextFactory.create(org.mule.runtime.core.api.event.EventContextFactory.create) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) MessageProcessorNotificationListener(org.mule.runtime.api.notification.MessageProcessorNotificationListener) SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Flux(reactor.core.publisher.Flux) IntegerAction(org.mule.runtime.api.notification.IntegerAction) Matcher(org.hamcrest.Matcher) BackPressureStrategy(org.mule.runtime.core.api.source.MessageSource.BackPressureStrategy) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Flow.builder(org.mule.runtime.core.api.construct.Flow.builder) ScheduledFuture(java.util.concurrent.ScheduledFuture) Collections.synchronizedSet(java.util.Collections.synchronizedSet) PollingProber(org.mule.tck.probe.PollingProber) Assert.assertThat(org.junit.Assert.assertThat) PROCESSOR_SCHEDULER_CONTEXT_KEY(org.mule.runtime.core.internal.processor.strategy.AbstractProcessingStrategy.PROCESSOR_SCHEDULER_CONTEXT_KEY) Scheduler(org.mule.runtime.api.scheduler.Scheduler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) Mono.just(reactor.core.publisher.Mono.just) Thread.sleep(java.lang.Thread.sleep) Exceptions.bubble(reactor.core.Exceptions.bubble) Parameterized(org.junit.runners.Parameterized) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) TimeZone(java.util.TimeZone) Collection(java.util.Collection) MessageProcessorNotification(org.mule.runtime.api.notification.MessageProcessorNotification) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Flow(org.mule.runtime.core.api.construct.Flow) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) FlowBackPressureException(org.mule.runtime.core.internal.construct.FlowBackPressureException) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) List(java.util.List) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) MESSAGE_PROCESSOR_PRE_INVOKE(org.mule.runtime.api.notification.MessageProcessorNotification.MESSAGE_PROCESSOR_PRE_INVOKE) CPU_LITE(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.CPU_LITE) FLOW_BACK_PRESSURE_ERROR_IDENTIFIER(org.mule.runtime.core.api.exception.Errors.Identifiers.FLOW_BACK_PRESSURE_ERROR_IDENTIFIER) ProcessingType(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Flux.from(reactor.core.publisher.Flux.from) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) AtomicReference(java.util.concurrent.atomic.AtomicReference) BLOCKING(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.BLOCKING) HashSet(java.util.HashSet) JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) MuleContext(org.mule.runtime.core.api.MuleContext) CPU_LITE_ASYNC(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.CPU_LITE_ASYNC) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) ExpectedException(org.junit.rules.ExpectedException) ExecutorService(java.util.concurrent.ExecutorService) AnnotatedProcessor(org.mule.runtime.core.privileged.processor.AnnotatedProcessor) Logger(org.slf4j.Logger) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) Executors.newFixedThreadPool(java.util.concurrent.Executors.newFixedThreadPool) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Latch(org.mule.runtime.api.util.concurrent.Latch) Rule(org.junit.Rule) Exceptions.rxExceptionToMuleException(org.mule.runtime.core.api.rx.Exceptions.rxExceptionToMuleException) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) IntegerAction(org.mule.runtime.api.notification.IntegerAction)

Aggregations

Flow (org.mule.runtime.core.api.construct.Flow)37 Test (org.junit.Test)25 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)19 Message (org.mule.runtime.api.message.Message)14 MuleException (org.mule.runtime.api.exception.MuleException)10 Processor (org.mule.runtime.core.api.processor.Processor)10 EventContext (org.mule.runtime.api.event.EventContext)9 ArrayList (java.util.ArrayList)8 Arrays.asList (java.util.Arrays.asList)8 List (java.util.List)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 Collectors.toList (java.util.stream.Collectors.toList)8 Assert.assertThat (org.junit.Assert.assertThat)8 Thread.currentThread (java.lang.Thread.currentThread)7 Collection (java.util.Collection)7 After (org.junit.After)7 Before (org.junit.Before)7 Rule (org.junit.Rule)7 ExpectedException (org.junit.rules.ExpectedException)7 RunWith (org.junit.runner.RunWith)7