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();
}
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);
}
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));
}
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;
}
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);
}
Aggregations