Search in sources :

Example 11 with FlowConstruct

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

the class MessageProcessingFlowTraceManagerTestCase method splitStack.

@Test
public void splitStack() {
    CoreEvent event = buildEvent("newAnnotatedComponentCall");
    PipelineMessageNotification pipelineNotification = buildPipelineNotification(event, rootFlowConstruct.getName());
    assertThat(getContextInfo(event, rootFlowConstruct), is(""));
    manager.onPipelineNotificationStart(pipelineNotification);
    assertThat(getContextInfo(event, rootFlowConstruct), is("at " + rootFlowConstruct.getName()));
    manager.onMessageProcessorNotificationPreInvoke(buildProcessorNotification(event, createMockProcessor("/comp", false)));
    assertThat(getContextInfo(event, rootFlowConstruct), is("at " + rootFlowConstruct.getName() + "(/comp @ " + APP_ID + ":unknown:-1)"));
    CoreEvent eventCopy = buildEvent("newAnnotatedComponentCall", event.getFlowCallStack().clone());
    assertThat(getContextInfo(eventCopy, rootFlowConstruct), is("at " + rootFlowConstruct.getName() + "(/comp @ " + APP_ID + ":unknown:-1)"));
    manager.onPipelineNotificationComplete(pipelineNotification);
    assertThat(getContextInfo(event, rootFlowConstruct), is(""));
    final FlowConstruct asyncFlowConstruct = mock(FlowConstruct.class);
    when(asyncFlowConstruct.getName()).thenReturn("asyncFlow");
    manager.onPipelineNotificationStart(buildPipelineNotification(eventCopy, asyncFlowConstruct.getName()));
    manager.onMessageProcessorNotificationPreInvoke(buildProcessorNotification(eventCopy, createMockProcessor("/asyncComp", false)));
    assertThat(getContextInfo(eventCopy, asyncFlowConstruct), is("at " + asyncFlowConstruct.getName() + "(/asyncComp @ " + APP_ID + ":unknown:-1)" + lineSeparator() + "at " + rootFlowConstruct.getName() + "(/comp @ " + APP_ID + ":unknown:-1)"));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) PipelineMessageNotification(org.mule.runtime.api.notification.PipelineMessageNotification) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 12 with FlowConstruct

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

the class DefaultExpressionManagerTestCase method flowName.

@Test
@Description("Verifies that the flow variable exposing it's name works.")
public void flowName() throws MuleException {
    FlowConstruct mockFlowConstruct = mock(FlowConstruct.class);
    when(mockFlowConstruct.getName()).thenReturn("myFlowName");
    String result = (String) expressionManager.evaluate("#[flow.name]", testEvent(), fromSingleComponent(mockFlowConstruct.getName())).getValue();
    assertThat(result, is(mockFlowConstruct.getName()));
}
Also used : FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 13 with FlowConstruct

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

the class QueueManagerLifecycleOrderTestCase method testStartupOrder.

@Test
public void testStartupOrder() throws Exception {
    ((MuleContextWithRegistries) muleContext).getRegistry().registerObject(OBJECT_NOTIFICATION_DISPATCHER, mock(NotificationDispatcher.class));
    FlowConstruct fc = new RecordingFlow("dummy", muleContext);
    ((MuleContextWithRegistries) muleContext).getRegistry().registerFlowConstruct(fc);
    muleContext.start();
    muleContext.stop();
    assertEquals(4, startStopOrder.size());
    assertSame(rtqm, startStopOrder.get(0));
    assertSame(fc, startStopOrder.get(1));
    assertSame(fc, startStopOrder.get(2));
    assertSame(rtqm, startStopOrder.get(3));
}
Also used : NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 14 with FlowConstruct

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

the class AsyncDelegateMessageProcessor method initialise.

@Override
public void initialise() throws InitialisationException {
    Object rootContainer = getFromAnnotatedObject(componentLocator, this).orElse(null);
    if (rootContainer instanceof FlowConstruct) {
        if (maxConcurrency != null && rootContainer instanceof Pipeline) {
            ProcessingStrategyFactory flowPsFactory = ((Pipeline) rootContainer).getProcessingStrategyFactory();
            if (flowPsFactory instanceof AsyncProcessingStrategyFactory) {
                ((AsyncProcessingStrategyFactory) flowPsFactory).setMaxConcurrency(maxConcurrency);
            } else {
                logger.warn("{} does not support 'maxConcurrency'. Ignoring the value.", flowPsFactory.getClass().getSimpleName());
            }
            processingStrategy = flowPsFactory.create(muleContext, getLocation().getLocation());
            ownProcessingStrategy = true;
        } else {
            processingStrategy = ((FlowConstruct) rootContainer).getProcessingStrategy();
        }
    } else {
        processingStrategy = DIRECT_PROCESSING_STRATEGY_INSTANCE;
    }
    if (delegateBuilder == null) {
        throw new InitialisationException(objectIsNull("delegate message processor"), this);
    }
    delegateBuilder.setProcessingStrategy(processingStrategy);
    delegate = delegateBuilder.build();
    initialiseIfNeeded(delegate, muleContext);
    super.initialise();
}
Also used : FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) ProcessingStrategyFactory(org.mule.runtime.core.api.processor.strategy.ProcessingStrategyFactory) AsyncProcessingStrategyFactory(org.mule.runtime.core.api.processor.strategy.AsyncProcessingStrategyFactory) ComponentUtils.getFromAnnotatedObject(org.mule.runtime.core.internal.component.ComponentUtils.getFromAnnotatedObject) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) AsyncProcessingStrategyFactory(org.mule.runtime.core.api.processor.strategy.AsyncProcessingStrategyFactory) Pipeline(org.mule.runtime.core.api.construct.Pipeline)

Example 15 with FlowConstruct

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

the class UntilSuccessful method initialise.

@Override
public void initialise() throws InitialisationException {
    if (processors == null) {
        throw new InitialisationException(createStaticMessage("One message processor must be configured within 'until-successful'."), this);
    }
    this.nestedChain = newChain(getProcessingStrategy(locator, getRootContainerLocation()), processors);
    super.initialise();
    timer = muleContext.getSchedulerService().cpuLightScheduler();
    policyTemplate = new SimpleRetryPolicyTemplate(millisBetweenRetries, maxRetries);
    shouldRetry = event -> event.getError().isPresent();
    Object rootContainer = getFromAnnotatedObject(componentLocator, this).orElse(null);
    if (rootContainer instanceof FlowConstruct) {
        processingStrategy = ((FlowConstruct) rootContainer).getProcessingStrategy();
    } else {
        processingStrategy = DIRECT_PROCESSING_STRATEGY_INSTANCE;
    }
}
Also used : SimpleRetryPolicyTemplate(org.mule.runtime.core.api.retry.policy.SimpleRetryPolicyTemplate) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) ComponentUtils.getFromAnnotatedObject(org.mule.runtime.core.internal.component.ComponentUtils.getFromAnnotatedObject) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException)

Aggregations

FlowConstruct (org.mule.runtime.core.api.construct.FlowConstruct)17 Test (org.junit.Test)9 SmallTest (org.mule.tck.size.SmallTest)6 Component (org.mule.runtime.api.component.Component)4 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)3 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)3 Description (io.qameta.allure.Description)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)2 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)2 MuleException (org.mule.runtime.api.exception.MuleException)2 ComponentUtils.getFromAnnotatedObject (org.mule.runtime.core.internal.component.ComponentUtils.getFromAnnotatedObject)2 DefaultExpressionManager (org.mule.runtime.core.internal.el.DefaultExpressionManager)2 MVELExpressionLanguage (org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage)2 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)2 WeaveDefaultExpressionLanguageFactoryService (org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService)2 Collection (java.util.Collection)1 Map (java.util.Map)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1