use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class ForeachTestCase method failingExpressionInChain.
@Test
public void failingExpressionInChain() throws Exception {
Foreach foreach = createForeach();
foreach.setCollectionExpression("!@INVALID");
SensingNullMessageProcessor firstProcessor = new SensingNullMessageProcessor();
List<Processor> processors = getSimpleMessageProcessors(new TestMessageProcessor("zas"));
processors.add(0, firstProcessor);
foreach.setMessageProcessors(processors);
initialiseIfNeeded(foreach, muleContext);
try {
expectExpressionException(foreach);
processInChain(foreach, eventBuilder(muleContext).message(of(new DummyNestedIterableClass().iterator())).build());
} finally {
assertThat(firstProcessor.invocations, equalTo(0));
}
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class ForeachTestCase method failingExpression.
@Test
public void failingExpression() throws Exception {
Foreach foreach = createForeach();
foreach.setCollectionExpression("!@INVALID");
SensingNullMessageProcessor firstProcessor = new SensingNullMessageProcessor();
List<Processor> processors = getSimpleMessageProcessors(new TestMessageProcessor("zas"));
processors.add(0, firstProcessor);
foreach.setMessageProcessors(processors);
initialiseIfNeeded(foreach, muleContext);
try {
expectExpressionException(foreach);
process(foreach, eventBuilder(muleContext).message(of(new DummyNestedIterableClass().iterator())).build(), false);
} finally {
assertThat(firstProcessor.invocations, equalTo(0));
}
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class RoundRobinTestCase method testRoundRobin.
@Test
public void testRoundRobin() throws Exception {
RoundRobin rr = new RoundRobin();
rr.setAnnotations(getAppleFlowComponentLocationAnnotations());
MuleSession session = new DefaultMuleSession();
List<TestProcessor> routes = new ArrayList<>(NUMBER_OF_ROUTES);
for (int i = 0; i < NUMBER_OF_ROUTES; i++) {
routes.add(new TestProcessor());
}
rr.setRoutes(new ArrayList<Processor>(routes));
initialiseIfNeeded(rr, muleContext);
List<Thread> threads = new ArrayList<>(NUMBER_OF_ROUTES);
for (int i = 0; i < NUMBER_OF_ROUTES; i++) {
threads.add(new Thread(new TestDriver(session, rr, NUMBER_OF_MESSAGES, getTestFlow(muleContext))));
}
for (Thread t : threads) {
t.start();
}
for (Thread t : threads) {
t.join();
}
for (TestProcessor route : routes) {
assertEquals(NUMBER_OF_MESSAGES, route.getCount());
}
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class FirstSuccessfulTestCase method testRouteReturnsNullEvent.
@Test
public void testRouteReturnsNullEvent() throws Exception {
Processor nullReturningMp = event -> null;
FirstSuccessful fs = createFirstSuccessfulRouter(nullReturningMp);
fs.setAnnotations(getAppleFlowComponentLocationAnnotations());
fs.initialise();
assertThat(fs.process(testEvent()), nullValue());
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class OperationPolicyProcessor method apply.
@Override
public Publisher<CoreEvent> apply(Publisher<CoreEvent> publisher) {
return from(publisher).cast(PrivilegedEvent.class).flatMap(operationEvent -> {
PolicyStateId policyStateId = new PolicyStateId(operationEvent.getContext().getCorrelationId(), policy.getPolicyId());
Optional<CoreEvent> latestPolicyState = policyStateHandler.getLatestState(policyStateId);
PrivilegedEvent variablesProviderEvent = (PrivilegedEvent) latestPolicyState.orElseGet(() -> PrivilegedEvent.builder(operationEvent.getContext()).message(of(null)).build());
policyStateHandler.updateState(policyStateId, variablesProviderEvent);
PrivilegedEvent policyEvent = policyEventConverter.createEvent(operationEvent, variablesProviderEvent);
Processor operationCall = buildOperationExecutionWithPolicyFunction(nextProcessor, operationEvent, policyStateId);
policyStateHandler.updateNextOperation(policyStateId.getExecutionIdentifier(), operationCall);
return executePolicyChain(operationEvent, policyStateId, policyEvent);
});
}
Aggregations