Search in sources :

Example 51 with PollingProber

use of org.mule.tck.probe.PollingProber in project mule by mulesoft.

the class PetStoreDefaultEncodingTestCase method listen.

private Message listen() {
    PollingProber prober = new PollingProber(TIMEOUT_MILLIS, POLL_DELAY_MILLIS);
    prober.check(new JUnitLambdaProbe(() -> messageHolder.get() != null));
    return messageHolder.get();
}
Also used : JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber)

Example 52 with PollingProber

use of org.mule.tck.probe.PollingProber in project mule by mulesoft.

the class MuleLoggerContextTestCase method assertLogged.

private void assertLogged() {
    PollingProber pollingProber = new PollingProber(5000, 500);
    pollingProber.check(new JUnitProbe() {

        @Override
        protected boolean test() throws Exception {
            testAppender.ensure(new TestAppender.Expectation(LEVEL.name(), CATEGORY, MESSAGE));
            return true;
        }

        @Override
        public String describeFailure() {
            return "message was not logged";
        }
    });
}
Also used : JUnitProbe(org.mule.tck.probe.JUnitProbe) PollingProber(org.mule.tck.probe.PollingProber)

Example 53 with PollingProber

use of org.mule.tck.probe.PollingProber in project mule by mulesoft.

the class NonBlockingOperationsTestCase method voidNonBlockingOperation.

@Test
public void voidNonBlockingOperation() throws Exception {
    IronMan ironMan = getIronMan("ironMan");
    final String payload = "take me to the avengers tower";
    Event event = flowRunner("computeFlightPlan").withPayload(payload).run();
    assertThat(event.getMessage().getPayload().getValue().toString(), equalTo(payload));
    new PollingProber().probe(1000, 1000, () -> FLIGHT_PLAN.equals(ironMan.getFlightPlan()));
}
Also used : PollingProber(org.mule.tck.probe.PollingProber) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Event(org.mule.runtime.api.event.Event) MuleExtensionUtils.getInitialiserEvent(org.mule.runtime.module.extension.api.util.MuleExtensionUtils.getInitialiserEvent) IronMan(org.mule.test.marvel.ironman.IronMan) Test(org.junit.Test)

Example 54 with PollingProber

use of org.mule.tck.probe.PollingProber in project mule by mulesoft.

the class ReactiveInterceptorAdapterTestCase method interceptorErrorResumeAround.

@Test
@io.qameta.allure.Description("Simulates the error handling scenario for XML SDK operations")
public void interceptorErrorResumeAround() throws Exception {
    Exception thrown = new Exception();
    ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {

        @Override
        public CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action) {
            Mono<InterceptionEvent> errorMono = Mono.error(thrown);
            return Mono.from(((BaseEventContext) event.getContext()).error(thrown)).then(errorMono).toFuture();
        }

        @Override
        public void after(ComponentLocation location, InterceptionEvent event, Optional<Throwable> thrown) {
        }
    });
    startFlowWithInterceptors(interceptor);
    expected.expectCause(sameInstance(thrown));
    try {
        process(flow, eventBuilder(muleContext).message(Message.of("")).build());
    } finally {
        if (useMockInterceptor) {
            new PollingProber().probe(() -> {
                verify(interceptor).after(any(), any(), eq(Optional.of(thrown)));
                return true;
            });
        }
    }
}
Also used : Mono(reactor.core.publisher.Mono) PollingProber(org.mule.tck.probe.PollingProber) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) InterceptionAction(org.mule.runtime.api.interception.InterceptionAction) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException) ExpectedException(org.junit.rules.ExpectedException) DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) CompletableFuture(java.util.concurrent.CompletableFuture) ProcessorInterceptor(org.mule.runtime.api.interception.ProcessorInterceptor) ProcessorParameterValue(org.mule.runtime.api.interception.ProcessorParameterValue) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 55 with PollingProber

use of org.mule.tck.probe.PollingProber in project mule by mulesoft.

the class AbstractProcessingStrategyTestCase method testBackPressure.

protected void testBackPressure(BackPressureStrategy backPressureStrategy, Matcher<Integer> processedAssertion, Matcher<Integer> rejectedAssertion, Matcher<Integer> totalAssertion) throws MuleException {
    if (mode.equals(SOURCE)) {
        triggerableMessageSource = new TriggerableMessageSource(backPressureStrategy);
        flow = flowBuilder.get().source(triggerableMessageSource).processors(asList(cpuLightProcessor, new ThreadTrackingProcessor() {

            @Override
            public CoreEvent process(CoreEvent event) throws MuleException {
                try {
                    sleep(3);
                } catch (InterruptedException e) {
                    currentThread().interrupt();
                    throw new RuntimeException(e);
                }
                return super.process(event);
            }

            @Override
            public ProcessingType getProcessingType() {
                return BLOCKING;
            }
        })).maxConcurrency(2).build();
        flow.initialise();
        flow.start();
        AtomicInteger rejected = new AtomicInteger();
        AtomicInteger processed = new AtomicInteger();
        for (int i = 0; i < STREAM_ITERATIONS; i++) {
            cachedThreadPool.submit(() -> Flux.just(newEvent()).cast(CoreEvent.class).transform(triggerableMessageSource.getListener()).doOnNext(event -> processed.getAndIncrement()).doOnError(e -> rejected.getAndIncrement()).subscribe());
        }
        new PollingProber(DEFAULT_TIMEOUT * 10, DEFAULT_POLLING_INTERVAL).check(new JUnitLambdaProbe(() -> {
            LOGGER.info("DONE " + processed.get() + " , REJECTED " + rejected.get() + ", ");
            assertThat(rejected.get() + processed.get(), totalAssertion);
            assertThat(processed.get(), processedAssertion);
            assertThat(rejected.get(), rejectedAssertion);
            return true;
        }));
    }
}
Also used : Schedulers.fromExecutorService(reactor.core.scheduler.Schedulers.fromExecutorService) Thread.currentThread(java.lang.Thread.currentThread) IO_RW(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.IO_RW) DEFAULT_TIMEOUT(org.mule.tck.probe.PollingProber.DEFAULT_TIMEOUT) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Future(java.util.concurrent.Future) LifecycleUtils.setMuleContextIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.setMuleContextIfNeeded) Arrays.asList(java.util.Arrays.asList) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) NamedThreadFactory(org.mule.runtime.core.api.util.concurrent.NamedThreadFactory) SOURCE(org.mule.runtime.core.internal.processor.strategy.AbstractProcessingStrategyTestCase.Mode.SOURCE) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Operators.requestUnbounded(org.mule.runtime.core.internal.util.rx.Operators.requestUnbounded) Builder(org.mule.runtime.core.api.construct.Flow.Builder) CountDownLatch(java.util.concurrent.CountDownLatch) Matchers.contains(org.hamcrest.Matchers.contains) DEFAULT_POLLING_INTERVAL(org.mule.tck.probe.PollingProber.DEFAULT_POLLING_INTERVAL) TriggerableMessageSource(org.mule.tck.TriggerableMessageSource) RunWith(org.junit.runner.RunWith) Callable(java.util.concurrent.Callable) Supplier(java.util.function.Supplier) MESSAGE_PROCESSOR_POST_INVOKE(org.mule.runtime.api.notification.MessageProcessorNotification.MESSAGE_PROCESSOR_POST_INVOKE) ArrayList(java.util.ArrayList) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleException(org.mule.runtime.api.exception.MuleException) Before(org.junit.Before) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) EventContextFactory.create(org.mule.runtime.core.api.event.EventContextFactory.create) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) MessageProcessorNotificationListener(org.mule.runtime.api.notification.MessageProcessorNotificationListener) SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Flux(reactor.core.publisher.Flux) IntegerAction(org.mule.runtime.api.notification.IntegerAction) Matcher(org.hamcrest.Matcher) BackPressureStrategy(org.mule.runtime.core.api.source.MessageSource.BackPressureStrategy) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Flow.builder(org.mule.runtime.core.api.construct.Flow.builder) ScheduledFuture(java.util.concurrent.ScheduledFuture) Collections.synchronizedSet(java.util.Collections.synchronizedSet) PollingProber(org.mule.tck.probe.PollingProber) Assert.assertThat(org.junit.Assert.assertThat) PROCESSOR_SCHEDULER_CONTEXT_KEY(org.mule.runtime.core.internal.processor.strategy.AbstractProcessingStrategy.PROCESSOR_SCHEDULER_CONTEXT_KEY) Scheduler(org.mule.runtime.api.scheduler.Scheduler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) Mono.just(reactor.core.publisher.Mono.just) Thread.sleep(java.lang.Thread.sleep) Exceptions.bubble(reactor.core.Exceptions.bubble) Parameterized(org.junit.runners.Parameterized) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) TimeZone(java.util.TimeZone) Collection(java.util.Collection) MessageProcessorNotification(org.mule.runtime.api.notification.MessageProcessorNotification) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Flow(org.mule.runtime.core.api.construct.Flow) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) FlowBackPressureException(org.mule.runtime.core.internal.construct.FlowBackPressureException) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) List(java.util.List) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) MESSAGE_PROCESSOR_PRE_INVOKE(org.mule.runtime.api.notification.MessageProcessorNotification.MESSAGE_PROCESSOR_PRE_INVOKE) CPU_LITE(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.CPU_LITE) FLOW_BACK_PRESSURE_ERROR_IDENTIFIER(org.mule.runtime.core.api.exception.Errors.Identifiers.FLOW_BACK_PRESSURE_ERROR_IDENTIFIER) ProcessingType(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Flux.from(reactor.core.publisher.Flux.from) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) AtomicReference(java.util.concurrent.atomic.AtomicReference) BLOCKING(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.BLOCKING) HashSet(java.util.HashSet) JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) MuleContext(org.mule.runtime.core.api.MuleContext) CPU_LITE_ASYNC(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.CPU_LITE_ASYNC) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) ExpectedException(org.junit.rules.ExpectedException) ExecutorService(java.util.concurrent.ExecutorService) AnnotatedProcessor(org.mule.runtime.core.privileged.processor.AnnotatedProcessor) Logger(org.slf4j.Logger) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) Executors.newFixedThreadPool(java.util.concurrent.Executors.newFixedThreadPool) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Latch(org.mule.runtime.api.util.concurrent.Latch) Rule(org.junit.Rule) Exceptions.rxExceptionToMuleException(org.mule.runtime.core.api.rx.Exceptions.rxExceptionToMuleException) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) PollingProber(org.mule.tck.probe.PollingProber) TriggerableMessageSource(org.mule.tck.TriggerableMessageSource) JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProcessingType(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType) MuleException(org.mule.runtime.api.exception.MuleException) Exceptions.rxExceptionToMuleException(org.mule.runtime.core.api.rx.Exceptions.rxExceptionToMuleException)

Aggregations

PollingProber (org.mule.tck.probe.PollingProber)55 Test (org.junit.Test)24 JUnitProbe (org.mule.tck.probe.JUnitProbe)22 JUnitLambdaProbe (org.mule.tck.probe.JUnitLambdaProbe)21 Prober (org.mule.tck.probe.Prober)19 Probe (org.mule.tck.probe.Probe)8 MuleException (org.mule.runtime.api.exception.MuleException)7 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)6 URISyntaxException (java.net.URISyntaxException)5 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)5 File (java.io.File)4 IOException (java.io.IOException)4 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)4 Matchers.greaterThanOrEqualTo (org.hamcrest.Matchers.greaterThanOrEqualTo)4 After (org.junit.After)4 Assert.assertThat (org.junit.Assert.assertThat)4 Before (org.junit.Before)4 System.currentTimeMillis (java.lang.System.currentTimeMillis)3 ArrayList (java.util.ArrayList)3 Matchers.is (org.hamcrest.Matchers.is)3