use of org.mule.runtime.api.util.Reference in project mule by mulesoft.
the class DefaultExtensionModelFactoryTestCase method blockingExecutionTypes.
@Test
public void blockingExecutionTypes() {
final List<String> nonBlockingOperations = Arrays.asList("killMany", "executeAnything", "alwaysFailsWrapper", "getChain", "exceptionOnCallbacks", "neverFailsWrapper", "payloadModifier");
ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
Reference<Boolean> cpuIntensive = new Reference<>(false);
Reference<Boolean> blocking = new Reference<>(false);
new IdempotentExtensionWalker() {
@Override
protected void onOperation(OperationModel operation) {
String operationName = operation.getName();
assertThat(operation.isBlocking(), is(!nonBlockingOperations.contains(operationName)));
if (operationName.equals("approve")) {
assertThat(operation.getExecutionType(), is(CPU_INTENSIVE));
cpuIntensive.set(true);
} else if (operation.requiresConnection()) {
assertThat(operation.getExecutionType(), is(BLOCKING));
blocking.set(true);
} else {
assertThat(operation.getExecutionType(), is(CPU_LITE));
}
}
}.walk(extensionModel);
assertThat(cpuIntensive.get(), is(true));
assertThat(blocking.get(), is(true));
}
use of org.mule.runtime.api.util.Reference in project mule by mulesoft.
the class ProcessorChainBenchmark method stream.
@Benchmark
public CountDownLatch stream() throws MuleException, InterruptedException {
CountDownLatch latch = new CountDownLatch(STREAM_SIZE);
Reference<FluxSink<CoreEvent>> sinkReference = new Reference<>();
FluxProcessor.create(sinkReference::set).transform(chain).doOnNext(event -> latch.countDown()).subscribe();
for (int i = 0; i < STREAM_SIZE; i++) {
sinkReference.get().next(event);
}
sinkReference.get().complete();
latch.await();
return latch;
}
use of org.mule.runtime.api.util.Reference in project mule by mulesoft.
the class RoutersExecutionTestCase method concurrentRouterExecution.
/**
* Executes the same flow concurrently to check that no race condition exists because
* two different instances of Chain are being used
*/
@Test
public void concurrentRouterExecution() throws Exception {
executor = newFixedThreadPool(2);
final Latch beginLatch = new Latch();
final CountDownLatch assertLatch = new CountDownLatch(2);
final Consumer<Reference<CoreEvent>> runner = reference -> {
try {
beginLatch.await(10000, MILLISECONDS);
reference.set(flowRunner("singleRouteRouter").withPayload("CustomPayload").run());
assertLatch.countDown();
} catch (Exception e) {
fail(e.getMessage());
}
};
final Reference<CoreEvent> first = new Reference<>();
final Reference<CoreEvent> second = new Reference<>();
executor.submit(() -> runner.accept(first));
executor.submit(() -> runner.accept(second));
beginLatch.release();
assertLatch.await(10000, MILLISECONDS);
CoreEvent firstResult = first.get();
assertThat(firstResult, is(notNullValue()));
CoreEvent secondResult = second.get();
assertThat(secondResult, is(notNullValue()));
assertThat(secondResult, is(not(sameInstance(firstResult))));
assertThat(firstResult.getMessage().getPayload().getValue(), is("CustomPayload"));
assertThat(secondResult.getMessage().getPayload().getValue(), is("CustomPayload"));
}
use of org.mule.runtime.api.util.Reference in project mule by mulesoft.
the class MetadataMediator method getTypedModel.
/**
* Returns a {@link ComponentModel} with its types resolved.
*
* @param inputMetadataDescriptor {@link InputMetadataDescriptor} describes the input parameters of the component
* @param outputMetadataDescriptor {@link OutputMetadataDescriptor} describes the component output
* @return model with its types resolved by the metadata resolution process
*/
private T getTypedModel(InputMetadataDescriptor inputMetadataDescriptor, OutputMetadataDescriptor outputMetadataDescriptor) {
Reference<T> typedModel = new Reference<>();
component.accept(new ComponentModelVisitor() {
@Override
public void visit(ConstructModel constructModel) {
typedModel.set((T) new ImmutableConstructModel(constructModel.getName(), constructModel.getDescription(), resolveParameterGroupModelType(constructModel.getParameterGroupModels(), inputMetadataDescriptor.getAllParameters()), constructModel.getNestedComponents(), constructModel.allowsTopLevelDeclaration(), constructModel.getDisplayModel().orElse(null), constructModel.getErrorModels(), constructModel.getStereotype(), constructModel.getModelProperties()));
}
@Override
public void visit(OperationModel operationModel) {
OutputModel typedOutputModel = resolveOutputModelType(operationModel.getOutput(), outputMetadataDescriptor.getPayloadMetadata());
OutputModel typedAttributesModel = resolveOutputModelType(operationModel.getOutputAttributes(), outputMetadataDescriptor.getAttributesMetadata());
typedModel.set((T) new ImmutableOperationModel(operationModel.getName(), operationModel.getDescription(), resolveParameterGroupModelType(operationModel.getParameterGroupModels(), inputMetadataDescriptor.getAllParameters()), operationModel.getNestedComponents(), typedOutputModel, typedAttributesModel, operationModel.isBlocking(), operationModel.getExecutionType(), operationModel.requiresConnection(), operationModel.isTransactional(), operationModel.supportsStreaming(), operationModel.getDisplayModel().orElse(null), operationModel.getErrorModels(), operationModel.getStereotype(), operationModel.getModelProperties(), operationModel.getNotificationModels()));
}
@Override
public void visit(SourceModel sourceModel) {
OutputModel typedOutputModel = resolveOutputModelType(sourceModel.getOutput(), outputMetadataDescriptor.getPayloadMetadata());
OutputModel typedAttributesModel = resolveOutputModelType(sourceModel.getOutputAttributes(), outputMetadataDescriptor.getAttributesMetadata());
typedModel.set((T) new ImmutableSourceModel(sourceModel.getName(), sourceModel.getDescription(), sourceModel.hasResponse(), true, resolveParameterGroupModelType(sourceModel.getParameterGroupModels(), inputMetadataDescriptor.getAllParameters()), sourceModel.getNestedComponents(), typedOutputModel, typedAttributesModel, resolveSourceCallbackType(sourceModel.getSuccessCallback(), inputMetadataDescriptor.getAllParameters()), resolveSourceCallbackType(sourceModel.getErrorCallback(), inputMetadataDescriptor.getAllParameters()), resolveSourceCallbackType(sourceModel.getTerminateCallback(), inputMetadataDescriptor.getAllParameters()), sourceModel.requiresConnection(), sourceModel.isTransactional(), sourceModel.supportsStreaming(), sourceModel.getDisplayModel().orElse(null), sourceModel.getStereotype(), sourceModel.getErrorModels(), sourceModel.getModelProperties(), sourceModel.getNotificationModels()));
}
});
return typedModel.get();
}
use of org.mule.runtime.api.util.Reference in project mule by mulesoft.
the class ProcessorChainExecutorTestCase method testDoProcessOnErrorGenericException.
@Test
public void testDoProcessOnErrorGenericException() throws InterruptedException {
when(chain.apply(any())).thenReturn(error(new RuntimeException()));
ImmutableProcessorChainExecutor chainExecutor = new ImmutableProcessorChainExecutor(coreEvent, chain);
AtomicInteger successCalls = new AtomicInteger(0);
AtomicInteger errorCalls = new AtomicInteger(0);
Reference<Event> errorEvent = new Reference<>();
doProcessAndWait(chainExecutor, r -> successCalls.incrementAndGet(), (t, r) -> {
errorCalls.incrementAndGet();
errorEvent.set(((EventedResult) r).getEvent());
});
assertThat(successCalls.get(), is(0));
assertThat(errorCalls.get(), is(1));
assertThat(errorEvent.get().getMessage().getPayload().getValue(), is(TEST_PAYLOAD));
}
Aggregations