Search in sources :

Example 11 with Flow

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

the class RuntimeMetadataTestCase method injectComposedMetadataKeyIdInstanceInSource.

@Test
public void injectComposedMetadataKeyIdInstanceInSource() throws Exception {
    Flow flow = (Flow) getFlowConstruct(SOURCE_METADATA_WITH_MULTILEVEL);
    flow.start();
    flow.stop();
}
Also used : Flow(org.mule.runtime.core.api.construct.Flow) Test(org.junit.Test)

Example 12 with Flow

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

the class ExtensionNotificationsTestCase method sourceFiresNotificationsOnBackPressure.

@Test
public void sourceFiresNotificationsOnBackPressure() throws Exception {
    Latch latch = new Latch();
    String batchFailed = "BATCH_FAILED";
    setUpListener(notification -> {
        if (batchFailed.equals(notification.getAction().getIdentifier())) {
            latch.release();
        }
    });
    Flow flow = (Flow) getFlowConstruct("sourceNotificationsBackPressure");
    flow.start();
    latch.await(10000, MILLISECONDS);
    flow.stop();
    assertThat(listener.getNotifications(), hasSize(greaterThan(3)));
    // Find first BATCH_FAILED
    ExtensionNotification backPressureNotification = listener.getNotifications().stream().filter(n -> batchFailed.equals(n.getAction().getIdentifier())).findFirst().get();
    // Find matching event notifications
    List<ExtensionNotification> notifications = listener.getNotifications().stream().filter(n -> backPressureNotification.getEvent().getCorrelationId().equals(n.getEvent().getCorrelationId())).collect(toList());
    assertThat(notifications, hasSize(4));
    int batchNumber = (Integer) backPressureNotification.getData().getValue();
    ExtensionNotification notification1 = notifications.get(0);
    verifyNewBatch(notification1, batchNumber);
    ExtensionNotification notification2 = notifications.get(1);
    verifyNextBatch(notification2, 10L);
    ExtensionNotification notification3 = notifications.get(2);
    verifyNotificationAndValue(notification3, batchFailed, batchNumber);
    ExtensionNotification notification4 = notifications.get(3);
    verifyBatchTerminated(notification4, batchNumber);
}
Also used : PersonalInfo(org.mule.test.heisenberg.extension.model.PersonalInfo) AbstractExtensionFunctionalTestCase(org.mule.test.module.extension.AbstractExtensionFunctionalTestCase) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) ExtensionNotificationListener(org.mule.runtime.api.notification.ExtensionNotificationListener) ExtensionNotification(org.mule.runtime.api.notification.ExtensionNotification) Flow(org.mule.runtime.core.api.construct.Flow) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) Consumer(java.util.function.Consumer) Inject(javax.inject.Inject) NotificationListenerRegistry(org.mule.runtime.api.notification.NotificationListenerRegistry) CountDownLatch(java.util.concurrent.CountDownLatch) Collectors.toList(java.util.stream.Collectors.toList) Latch(org.mule.runtime.api.util.concurrent.Latch) List(java.util.List) SimpleKnockeableDoor(org.mule.test.heisenberg.extension.model.SimpleKnockeableDoor) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) LinkedList(java.util.LinkedList) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) ExtensionNotification(org.mule.runtime.api.notification.ExtensionNotification) CountDownLatch(java.util.concurrent.CountDownLatch) Latch(org.mule.runtime.api.util.concurrent.Latch) Flow(org.mule.runtime.core.api.construct.Flow) Test(org.junit.Test)

Example 13 with Flow

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

the class ExtensionNotificationsTestCase method sourceFiresNotificationsOnSuccess.

@Test
public void sourceFiresNotificationsOnSuccess() throws Exception {
    CountDownLatch latch = new CountDownLatch(4);
    setUpListener(notification -> latch.countDown());
    Flow flow = (Flow) getFlowConstruct("sourceNotifications");
    flow.start();
    latch.await(4000, MILLISECONDS);
    assertThat(listener.getNotifications(), hasSize(4));
    ExtensionNotification notification1 = listener.getNotifications().get(0);
    verifyNewBatch(notification1, 1);
    String correlationId = notification1.getEvent().getCorrelationId();
    ExtensionNotification notification2 = listener.getNotifications().get(1);
    verifyNextBatch(notification2, 100000L);
    assertThat(notification2.getEvent().getCorrelationId(), is(correlationId));
    ExtensionNotification notification3 = listener.getNotifications().get(2);
    verifyNotificationAndValue(notification3, "BATCH_DELIVERED", 100L);
    assertThat(notification3.getEvent().getCorrelationId(), is(correlationId));
    ExtensionNotification notification4 = listener.getNotifications().get(3);
    verifyBatchTerminated(notification4, 1);
    assertThat(notification4.getEvent().getCorrelationId(), is(correlationId));
}
Also used : ExtensionNotification(org.mule.runtime.api.notification.ExtensionNotification) CountDownLatch(java.util.concurrent.CountDownLatch) Flow(org.mule.runtime.core.api.construct.Flow) Test(org.junit.Test)

Example 14 with Flow

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

the class FlowRefFactoryBean method getReferencedFlow.

protected Processor getReferencedFlow(String name, FlowRefMessageProcessor flowRefMessageProcessor) throws MuleException {
    if (name == null) {
        throw new RoutePathNotFoundException(createStaticMessage("flow-ref name expression returned 'null'"), flowRefMessageProcessor);
    }
    Component referencedFlow = getReferencedProcessor(name);
    if (referencedFlow == null) {
        throw new RoutePathNotFoundException(createStaticMessage("No flow/sub-flow with name '%s' found", name), flowRefMessageProcessor);
    }
    // for subflows, we create a new one so it must be initialised manually
    if (!(referencedFlow instanceof Flow)) {
        if (referencedFlow instanceof SubflowMessageProcessorChainBuilder) {
            MessageProcessorChainBuilder chainBuilder = (MessageProcessorChainBuilder) referencedFlow;
            locator.find(flowRefMessageProcessor.getRootContainerLocation()).filter(c -> c instanceof Flow).map(c -> (Flow) c).ifPresent(f -> chainBuilder.setProcessingStrategy(f.getProcessingStrategy()));
            referencedFlow = chainBuilder.build();
        }
        initialiseIfNeeded(referencedFlow, muleContext);
        Map<QName, Object> annotations = new HashMap<>(referencedFlow.getAnnotations());
        annotations.put(ROOT_CONTAINER_NAME_KEY, getRootContainerLocation().toString());
        referencedFlow.setAnnotations(annotations);
        startIfNeeded(referencedFlow);
    }
    return (Processor) referencedFlow;
}
Also used : Flux.just(reactor.core.publisher.Flux.just) LoadingCache(com.google.common.cache.LoadingCache) Map(java.util.Map) LifecycleUtils.stopIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Operators.outputToTarget(org.mule.runtime.core.internal.util.rx.Operators.outputToTarget) Flow(org.mule.runtime.core.api.construct.Flow) CacheLoader(com.google.common.cache.CacheLoader) MessageProcessors.processWithChildContext(org.mule.runtime.core.privileged.processor.MessageProcessors.processWithChildContext) MessageProcessors(org.mule.runtime.core.privileged.processor.MessageProcessors) MessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChainBuilder) CacheBuilder(com.google.common.cache.CacheBuilder) QName(javax.xml.namespace.QName) ExtendedExpressionManager(org.mule.runtime.core.api.el.ExtendedExpressionManager) ApplicationContextAware(org.springframework.context.ApplicationContextAware) Flux.from(reactor.core.publisher.Flux.from) HashMap(java.util.HashMap) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) Processor(org.mule.runtime.core.api.processor.Processor) Inject(javax.inject.Inject) ConfigurationComponentLocator(org.mule.runtime.api.component.location.ConfigurationComponentLocator) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Component(org.mule.runtime.api.component.Component) Flux.error(reactor.core.publisher.Flux.error) Disposable(org.mule.runtime.api.lifecycle.Disposable) AnnotatedProcessor(org.mule.runtime.core.privileged.processor.AnnotatedProcessor) AbstractComponentFactory(org.mule.runtime.dsl.api.component.AbstractComponentFactory) Logger(org.slf4j.Logger) MessageProcessors.processToApply(org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply) SubflowMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.SubflowMessageProcessorChainBuilder) Optional.ofNullable(java.util.Optional.ofNullable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) RoutePathNotFoundException(org.mule.runtime.core.privileged.routing.RoutePathNotFoundException) LifecycleUtils.startIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.startIfNeeded) BeansException(org.springframework.beans.BeansException) Mono(reactor.core.publisher.Mono) ApplicationContext(org.springframework.context.ApplicationContext) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) LifecycleUtils.disposeIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.disposeIfNeeded) Flux(reactor.core.publisher.Flux) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) MuleArtifactContext(org.mule.runtime.config.internal.MuleArtifactContext) RoutePathNotFoundException(org.mule.runtime.core.privileged.routing.RoutePathNotFoundException) Processor(org.mule.runtime.core.api.processor.Processor) AnnotatedProcessor(org.mule.runtime.core.privileged.processor.AnnotatedProcessor) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) MessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChainBuilder) SubflowMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.SubflowMessageProcessorChainBuilder) Component(org.mule.runtime.api.component.Component) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) SubflowMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.SubflowMessageProcessorChainBuilder) Flow(org.mule.runtime.core.api.construct.Flow)

Example 15 with Flow

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

the class FlowRunner method runAndVerify.

/**
 * Runs the specified flow with the provided event and configuration, and performs a {@link FlowAssert#verify(String))} for each
 * {@code flowNamesToVerify} afterwards.
 * <p>
 * If this is called multiple times, the <b>same</b> event will be sent. To force the creation of a new event, use
 * {@link #reset()}.
 *
 * @param flowNamesToVerify the names of the flows to {@link FlowAssert#verify(String))} afterwards.
 * @return the resulting <code>MuleEvent</code>
 * @throws Exception
 */
public CoreEvent runAndVerify(String... flowNamesToVerify) throws Exception {
    Flow flow = (Flow) getFlowConstruct();
    CoreEvent response;
    if (scheduler == null) {
        response = txExecutionTemplate.execute(getFlowRunCallback(flow));
    } else {
        try {
            response = scheduler.submit(() -> txExecutionTemplate.execute(getFlowRunCallback(flow))).get();
        } catch (ExecutionException executionException) {
            Throwable cause = executionException.getCause();
            throw cause instanceof Exception ? (Exception) cause : new RuntimeException(cause);
        }
    }
    verify(flowNamesToVerify);
    return responseEventTransformer.apply(response);
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ExecutionException(java.util.concurrent.ExecutionException) EventProcessingException(org.mule.runtime.core.privileged.exception.EventProcessingException) ExecutionException(java.util.concurrent.ExecutionException) Flow(org.mule.runtime.core.api.construct.Flow)

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