@Benchmark public EventContext createEventContextWithFlow() { return create(flow, CONNECTOR_LOCATION); }
/** * Creates a basic event builder with its context built from the provided {@code muleContext}. */ public static <B extends CoreEvent.Builder> B eventBuilder(MuleContext muleContext) throws MuleException { FlowConstruct flowConstruct = getTestFlow(muleContext); return (B) InternalEvent.builder(create(flowConstruct, TEST_CONNECTOR_LOCATION)); }
@Benchmark public EventContext createEventContext() { return create(id, severId, CONNECTOR_LOCATION, getInstance()); }
@Benchmark public Object[] createEventContextWithFlowAndCompleteWithExternalCompletion() { CompletableFuture<Void> completableFuture = new CompletableFuture<>(); AtomicReference<CoreEvent> result = new AtomicReference<>(); AtomicBoolean complete = new AtomicBoolean(); BaseEventContext eventContext = (BaseEventContext) create(flow, CONNECTOR_LOCATION, null, of(completableFuture)); from(from(eventContext.getResponsePublisher())).doOnSuccess(response -> result.set(response)).subscribe(); eventContext.onTerminated((response, throwable) -> complete.set(true)); eventContext.success(event); completableFuture.complete(null); return new Object[] {result, complete}; }
public CoreEvent createEvent(Flow flow, Object payload) { try { return CoreEvent.builder(create(flow, CONNECTOR_LOCATION)).message(of(payload)).build(); } catch (Exception e) { throw new RuntimeException(e); } } }
private CoreEvent createMuleEvent(Message message, int numProperties) { final Builder builder; try { builder = CoreEvent.builder(create(flow, CONNECTOR_LOCATION)).message(message); } catch (Exception e) { throw new RuntimeException(e); } for (int i = 1; i <= numProperties; i++) { builder.addVariable("FlOwVaRiAbLeKeY" + i, "val"); } return builder.build(); }
@Before public void setupMessageContext() throws Exception { context = create(flowConstruct, TEST_CONNECTOR_LOCATION); }
@Override protected InternalEvent.Builder getEventBuilder() throws MuleException { return InternalEvent.builder(create(flow, TEST_CONNECTOR_LOCATION)); }
public void createTestPipeline(List<Processor> processors, ErrorHandler errorHandler) { pipeline = new TestPipeline(pipelineName, muleContext, null, processors, errorHandler); context = create(pipeline, TEST_CONNECTOR_LOCATION); }
private Object[] createEventContextTerminateAllAtOnce(int childrenCount) { AtomicReference<CoreEvent> result = new AtomicReference<>(); AtomicBoolean complete = new AtomicBoolean(); BaseEventContext eventContext = (BaseEventContext) create(flow, CONNECTOR_LOCATION); List<BaseEventContext> children = new ArrayList<>(childrenCount); for (int i = 0; i < childrenCount; ++i) { children.add(child(eventContext, empty())); } from(from(eventContext.getResponsePublisher())).doOnSuccess(response -> result.set(response)).subscribe(); eventContext.onTerminated((response, throwable) -> complete.set(true)); eventContext.success(event); for (BaseEventContext child : children) { child.success(); } return new Object[] {result, complete}; }
@Benchmark public Object[] createEventContextWithFlowAndComplete() { AtomicReference<CoreEvent> result = new AtomicReference<>(); AtomicBoolean complete = new AtomicBoolean(); BaseEventContext eventContext = (BaseEventContext) create(flow, CONNECTOR_LOCATION); from(from(eventContext.getResponsePublisher())).doOnSuccess(response -> result.set(response)).subscribe(); eventContext.onTerminated((response, throwable) -> complete.set(true)); eventContext.success(event); return new Object[] {result, complete}; }
private Object[] childEventContextForEach(int childrenCount) { AtomicReference<CoreEvent> result = new AtomicReference<>(); AtomicBoolean complete = new AtomicBoolean(); BaseEventContext eventContext = (BaseEventContext) create(flow, CONNECTOR_LOCATION); for (int i = 0; i < childrenCount; ++i) { BaseEventContext child = child(eventContext, empty()); child.success(); } from(from(eventContext.getResponsePublisher())).doOnSuccess(response -> result.set(response)).subscribe(); eventContext.onTerminated((response, throwable) -> complete.set(true)); eventContext.success(event); return new Object[] {result, complete}; }
@Before public void before() { when(flow.getMuleContext()).thenReturn(muleContext); when(flow.getUniqueIdString()).thenReturn(GENERATED_CORRELATION_ID); when(flow.getServerId()).thenReturn(SERVER_ID); executionContext = create(flow, TEST_CONNECTOR_LOCATION); executionContextWithCorrelation = create(flow, TEST_CONNECTOR_LOCATION, CUSTOM_CORRELATION_ID); }
@Before public void setupMocks() throws Exception { when(flow.getMuleContext()).thenReturn(muleContext); when(muleContext.getConfiguration()).thenReturn(mock(MuleConfiguration.class)); context = create(flow, TEST_CONNECTOR_LOCATION); }
@Benchmark @Threads(Threads.MAX) public CoreEvent source() { CoreEvent event; Message.Builder messageBuilder = Message.builder().value(PAYLOAD); CoreEvent.Builder eventBuilder = CoreEvent.builder(create("", "", CONNECTOR_LOCATION, NullExceptionHandler.getInstance())).message(messageBuilder.build()); event = eventBuilder.build(); return from(handler.process(event, (params, e) -> just(e), () -> emptyMap(), CONNECTOR_LOCATION)).block(); }
@Parameters public static List<Object[]> data() { return asList(new Object[][] { { (CheckedSupplier<EventContext>) () -> create(getTestFlow(muleContext), TEST_CONNECTOR_LOCATION), (CheckedFunction<CompletableFuture<Void>, EventContext>) externalCompletion -> create(getTestFlow(muleContext), TEST_CONNECTOR_LOCATION, null, of(externalCompletion)), (CheckedFunction<ComponentLocation, EventContext>) location -> create(getTestFlow(muleContext), location) }, { (CheckedSupplier<EventContext>) () -> create("id", DefaultEventContextTestCase.class.getName(), TEST_CONNECTOR_LOCATION, NullExceptionHandler.getInstance()), (CheckedFunction<CompletableFuture<Void>, EventContext>) externalCompletion -> create("id", DefaultEventContextTestCase.class .getName(), TEST_CONNECTOR_LOCATION, null, of(externalCompletion), NullExceptionHandler .getInstance()), (CheckedFunction<ComponentLocation, EventContext>) location -> create("id", DefaultEventContextTestCase.class .getName(), location, NullExceptionHandler.getInstance()) } }); }
@Benchmark public CoreEvent createEvent() { return CoreEvent.builder(create(flow, CONNECTOR_LOCATION)).message(of(PAYLOAD)).build(); }
private CoreEvent baseEvent() throws MuleException { FlowConstruct flowConstruct = getTestFlow(muleContext); return CoreEvent.builder(create(flowConstruct, TEST_CONNECTOR_LOCATION)).message(Message.of(TEST_PAYLOAD)).build(); }
@Before public void before() { manager = new MessageProcessingFlowTraceManager(); MuleContext context = mock(MuleContext.class); MuleConfiguration config = mock(MuleConfiguration.class); when(config.getId()).thenReturn(APP_ID); when(context.getConfiguration()).thenReturn(config); manager.setMuleContext(context); rootFlowConstruct = mock(FlowConstruct.class); ComponentLocation mockComponentLocation = mock(ComponentLocation.class); when(mockComponentLocation.getFileName()).thenReturn(of(CONFIG_FILE_NAME)); when(mockComponentLocation.getLineInFile()).thenReturn(of(LINE_NUMBER)); when(rootFlowConstruct.getLocation()).thenReturn(mockComponentLocation); when(rootFlowConstruct.getName()).thenReturn(ROOT_FLOW_NAME); when(rootFlowConstruct.getMuleContext()).thenReturn(context); nestedFlowConstruct = mock(FlowConstruct.class); when(nestedFlowConstruct.getLocation()).thenReturn(mockComponentLocation); when(nestedFlowConstruct.getName()).thenReturn(NESTED_FLOW_NAME); when(nestedFlowConstruct.getMuleContext()).thenReturn(context); messageContext = create(rootFlowConstruct, TEST_CONNECTOR_LOCATION); }
@Benchmark @Threads(Threads.MAX) public Either<SourcePolicyFailureResult, SourcePolicySuccessResult> source() { CoreEvent event; Message.Builder messageBuilder = Message.builder().value(PAYLOAD); CoreEvent.Builder eventBuilder = CoreEvent.builder(create("", "", CONNECTOR_LOCATION, NullExceptionHandler.getInstance())).message(messageBuilder.build()); event = eventBuilder.build(); return from(handler.process(event, sourceRpp)).block(); }