/** * Adds a new component to the locator. * * @param component the component to be added */ public void addComponent(Component component) { this.componentsMap.put(component.getLocation().getLocation(), component); }
protected String failureMessagePrefix() { String processorPath = this.getLocation().getLocation(); return "Flow assertion '" + message + "' failed @ '" + processorPath + "'. "; }
private void configureProcessorLocation(AnnotatedProcessor mockProcessor) { when(mockProcessor.getLocation()).thenReturn(mockComponentLocation); when(mockComponentLocation.getFileName()).thenReturn(Optional.of("muleApp.xml")); when(mockComponentLocation.getLineInFile()).thenReturn(Optional.of(10)); when(mockComponentLocation.getLocation()).thenReturn("Mock@1"); }
public Processor createMockProcessor(String processorPath, boolean useLocationSettings) { ComponentLocation componentLocation = mock(ComponentLocation.class); when(componentLocation.getLocation()).thenReturn(processorPath); when(componentLocation.getFileName()).thenReturn(useLocationSettings ? of(CONFIG_FILE_NAME) : empty()); when(componentLocation.getLineInFile()).thenReturn(useLocationSettings ? of(LINE_NUMBER) : empty()); Component annotatedMessageProcessor = (Component) mock(Processor.class, withSettings().extraInterfaces(Component.class).defaultAnswer(RETURNS_DEEP_STUBS)); when(annotatedMessageProcessor.getAnnotation(any())).thenReturn(null); when(annotatedMessageProcessor.getLocation()).thenReturn(componentLocation); return (Processor) annotatedMessageProcessor; }
@Test public void withAnnotatedFailingProcessorPathResolver() { AnnotatedProcessor mockProcessor = mock(AnnotatedProcessor.class); when(mockProcessor.getAnnotation(eq(docNameAttrName))).thenReturn("Mock Component"); configureProcessorLocation(mockProcessor); when(mockComponentLocation.getLocation()).thenReturn("flow/processor"); MessagingException exception = new MessagingException(createStaticMessage(""), testEvent, mockProcessor); exception.getInfo().putAll(locationProvider.getContextInfo(createInfo(testEvent, exception, mockProcessor), mockProcessor)); assertThat(exception.getInfo().get(INFO_LOCATION_KEY).toString(), is("flow/processor @ MessagingExceptionTestCase:muleApp.xml:10 (Mock Component)")); }
@Test public void withFailingProcessorPathResolver() { AnnotatedProcessor mockProcessor = mock(AnnotatedProcessor.class); configureProcessorLocation(mockProcessor); when(mockComponentLocation.getLocation()).thenReturn("flow/processor"); MessagingException exception = new MessagingException(createStaticMessage(""), testEvent, mockProcessor); exception.getInfo() .putAll(locationProvider.getContextInfo(createInfo(testEvent, exception, mockProcessor), mockProcessor)); assertThat(exception.getInfo().get(INFO_LOCATION_KEY).toString(), is("flow/processor @ MessagingExceptionTestCase:muleApp.xml:10")); }
@Override public void initialise() throws InitialisationException { customScheduler = new LazyValue<>(() -> schedulerService.customScheduler(config() .withName("TestNonBlockingProcessor[" + getLocation().getLocation() + "]") .withWaitAllowed(true) .withMaxConcurrentTasks(MAX_THREADS))); }
@Override protected void doInitialise() throws InitialisationException { if (!initialised) { returnDelegate = createReturnDelegate(); initialiseIfNeeded(resolverSet, muleContext); componentExecutor = createComponentExecutor(); executionMediator = createExecutionMediator(); initialiseIfNeeded(componentExecutor, true, muleContext); if (getLocation() != null) { resolvedProcessorRepresentation = resolveProcessorRepresentation(muleContext.getConfiguration().getId(), getLocation().getLocation(), this); } initialised = true; } }
@Override public void onStart(SourceCallback<String, Object> sourceCallback) throws MuleException { checkArgument(heisenberg != null, "config not injected"); HeisenbergExtension.sourceTimesStarted++; configName = refName; location = componentLocation.getLocation(); if (corePoolSize < 0) { throw new RuntimeException(CORE_POOL_SIZE_ERROR_MESSAGE); } receivedDebtProperties = debtProperties; receivedUsableWeapons = usableWeapons; executor = schedulerService.cpuLightScheduler(); connection = connectionProvider.connect(); scheduledFuture = executor.scheduleAtFixedRate(() -> { final Result<String, Object> result = makeResult(sourceCallback); if (result != null) { SourceCallbackContext context = sourceCallback.createContext(); context.addVariable(BATCH_NUMBER, initialBatchNumber); context.fireOnHandle(NEW_BATCH, TypedValue.of(initialBatchNumber)); context.fireOnHandle(NEXT_BATCH, TypedValue.of(frequency)); sourceCallback.handle(result, context); } }, 0, frequency, MILLISECONDS); }
/** * Adds a new component to the locator. * * @param component the component to be added */ public void addComponent(Component component) { this.componentsMap.put(component.getLocation().getLocation(), component); }
@Override public CompletableFuture<InterceptionEvent> skip() { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Called skip() for processor {}", ((Component) processor).getLocation().getLocation()); } interceptionEvent.resolve(); return completedFuture(interceptionEvent); }
@Override public CompletableFuture<InterceptionEvent> fail(Throwable cause) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Called fail() for processor {} with cause {} ({})", ((Component) processor).getLocation().getLocation(), cause.getClass(), cause.getMessage()); } Error newError = getErrorFromFailingProcessor(null, (Component) processor, cause, errorTypeLocator); interceptionEvent.setError(newError.getErrorType(), cause); CompletableFuture<InterceptionEvent> completableFuture = new CompletableFuture<>(); completableFuture .completeExceptionally(new MessagingException(interceptionEvent.resolve(), cause, (Component) processor)); return completableFuture; }
@Override public String toString() { return getClass().getSimpleName() + " { id: " + getId() + "; correlationId: " + parent.getCorrelationId() + "; flowName: " + parent.getOriginatingLocation().getRootContainerName() + "; componentLocation: " + (componentLocation != null ? componentLocation.getLocation() : EMPTY) + ";"; }
private void configureProcessorLocation(AnnotatedProcessor mockProcessor) { when(mockProcessor.getLocation()).thenReturn(mockComponentLocation); when(mockComponentLocation.getFileName()).thenReturn(Optional.of("muleApp.xml")); when(mockComponentLocation.getLineInFile()).thenReturn(Optional.of(10)); when(mockComponentLocation.getLocation()).thenReturn("Mock@1"); }
private void configureProcessorLocation(Component component) { when(component.getLocation()).thenReturn(mockComponentLocation); when(mockComponentLocation.getFileName()).thenReturn(Optional.of("muleApp.xml")); when(mockComponentLocation.getLineInFile()).thenReturn(Optional.of(10)); when(mockComponentLocation.getLocation()).thenReturn("Mock@1"); } }
public Processor createMockProcessor(String processorPath, boolean useLocationSettings) { ComponentLocation componentLocation = mock(ComponentLocation.class); when(componentLocation.getLocation()).thenReturn(processorPath); when(componentLocation.getFileName()).thenReturn(useLocationSettings ? of(CONFIG_FILE_NAME) : empty()); when(componentLocation.getLineInFile()).thenReturn(useLocationSettings ? of(LINE_NUMBER) : empty()); Component annotatedMessageProcessor = (Component) mock(Processor.class, withSettings().extraInterfaces(Component.class).defaultAnswer(RETURNS_DEEP_STUBS)); when(annotatedMessageProcessor.getAnnotation(any())).thenReturn(null); when(annotatedMessageProcessor.getLocation()).thenReturn(componentLocation); return (Processor) annotatedMessageProcessor; }
@Override protected ReactiveProcessor doApply(Processor component, ReactiveProcessor next, ComponentLocation componentLocation, ProcessorInterceptor interceptor, Map<String, String> dslParameters) { if (implementsAround(interceptor)) { LOGGER.debug("Configuring interceptor '{}' around processor '{}'...", interceptor, componentLocation.getLocation()); return publisher -> from(publisher) .cast(InternalEvent.class) .flatMap(event -> fromFuture(doAround(event, interceptor, component, dslParameters, next)) .onErrorMap(CompletionException.class, completionException -> completionException.getCause())); } else { return next; } }
@Override public void start() throws MuleException { scheduler = schedulerService .ioScheduler(muleContext.getSchedulerBaseConfig().withName(name != null ? name : getLocation().getLocation())); reactorScheduler = fromExecutorService(scheduler); super.start(); }
@Test public void withAnnotatedFailingProcessorPathResolver() { AnnotatedProcessor mockProcessor = mock(AnnotatedProcessor.class); when(mockProcessor.getAnnotation(eq(docNameAttrName))).thenReturn("Mock Component"); configureProcessorLocation(mockProcessor); when(mockComponentLocation.getLocation()).thenReturn("flow/processor"); MessagingException exception = new MessagingException(createStaticMessage(""), testEvent, mockProcessor); exception.getInfo().putAll(locationProvider.getContextInfo(createInfo(testEvent, exception, mockProcessor), mockProcessor)); assertThat(exception.getInfo().get(INFO_LOCATION_KEY).toString(), is("flow/processor @ MessagingExceptionTestCase:muleApp.xml:10 (Mock Component)")); }
@Test public void withFailingProcessorPathResolver() { AnnotatedProcessor mockProcessor = mock(AnnotatedProcessor.class); configureProcessorLocation(mockProcessor); when(mockComponentLocation.getLocation()).thenReturn("flow/processor"); MessagingException exception = new MessagingException(createStaticMessage(""), testEvent, mockProcessor); exception.getInfo() .putAll(locationProvider.getContextInfo(createInfo(testEvent, exception, mockProcessor), mockProcessor)); assertThat(exception.getInfo().get(INFO_LOCATION_KEY).toString(), is("flow/processor @ MessagingExceptionTestCase:muleApp.xml:10")); }