Search in sources :

Example 26 with ParameterizedTestWithName

use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.

the class FluxOnAssemblyTest method checkpointDescriptionAndForceStack.

@ParameterizedTestWithName
@ValueSource(booleans = { false, true })
void checkpointDescriptionAndForceStack(boolean debugModeOn) {
    if (debugModeOn) {
        Hooks.onOperatorDebug();
    }
    StringWriter sw = new StringWriter();
    Flux<Integer> tested = Flux.range(1, 10).map(i -> i < 3 ? i : null).filter(i -> i % 2 == 0).checkpoint("heavy", true).doOnError(t -> t.printStackTrace(new PrintWriter(sw)));
    StepVerifier.create(tested).expectNext(2).verifyError();
    String debugStack = sw.toString();
    if (debugModeOn) {
        // the traceback "error has been observed" contains both individual ops and checkpoint with description,
        // assembly points to map, with no description
        assertThat(debugStack).contains("Assembly trace from producer [reactor.core.publisher.FluxMapFuseable] :").contains("Flux.filter ⇢ at reactor.core.publisher.FluxOnAssemblyTest.checkpointDescriptionAndForceStack(").contains("checkpoint(heavy) ⇢ at reactor.core.publisher.FluxOnAssemblyTest.checkpointDescriptionAndForceStack(");
    } else {
        // the traceback "error has been observed" only contains the checkpoint, with callsite and description,
        // assembly points to filter and reflects description
        assertThat(debugStack).contains("Assembly trace from producer [reactor.core.publisher.FluxFilterFuseable], described as [heavy] :").contains("checkpoint(heavy) ⇢ at reactor.core.publisher.FluxOnAssemblyTest.checkpointDescriptionAndForceStack(").doesNotContain("Flux.filter ⇢ at");
    }
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Retry(reactor.util.retry.Retry) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AssemblySnapshot(reactor.core.publisher.FluxOnAssembly.AssemblySnapshot) CoreSubscriber(reactor.core.CoreSubscriber) Duration(java.time.Duration) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) PrintWriter(java.io.PrintWriter) ValueSource(org.junit.jupiter.params.provider.ValueSource) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) Iterator(java.util.Iterator) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) StringWriter(java.io.StringWriter) Publisher(org.reactivestreams.Publisher) IOException(java.io.IOException) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) Stream(java.util.stream.Stream) Subscription(org.reactivestreams.Subscription) Exceptions(reactor.core.Exceptions) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName)

Example 27 with ParameterizedTestWithName

use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.

the class FluxOnAssemblyTest method checkpointWithDescriptionIsLight.

@ParameterizedTestWithName
@ValueSource(booleans = { false, true })
void checkpointWithDescriptionIsLight(boolean debugModeOn) {
    if (debugModeOn) {
        Hooks.onOperatorDebug();
    }
    StringWriter sw = new StringWriter();
    Flux<Integer> tested = Flux.range(1, 10).map(i -> i < 3 ? i : null).filter(i -> i % 2 == 0).checkpoint("light").doOnError(t -> t.printStackTrace(new PrintWriter(sw)));
    StepVerifier.create(tested).expectNext(2).verifyError();
    String debugStack = sw.toString();
    if (debugModeOn) {
        // the traceback "error has been observed" contains both individual ops and light checkpoint,
        // assembly points to map, with no description
        assertThat(debugStack).contains("Assembly trace from producer [reactor.core.publisher.FluxMapFuseable] :").contains("Flux.filter ⇢ at reactor.core.publisher.FluxOnAssemblyTest.checkpointWithDescriptionIsLight(").contains("checkpoint ⇢ light");
    } else {
        // the traceback "error has been observed" only contains the light checkpoint,
        // assembly is not present
        assertThat(debugStack).doesNotContain("Assembly trace from producer").contains("checkpoint ⇢ light").doesNotContain("Flux.filter ⇢ at");
    }
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Retry(reactor.util.retry.Retry) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AssemblySnapshot(reactor.core.publisher.FluxOnAssembly.AssemblySnapshot) CoreSubscriber(reactor.core.CoreSubscriber) Duration(java.time.Duration) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) PrintWriter(java.io.PrintWriter) ValueSource(org.junit.jupiter.params.provider.ValueSource) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) Iterator(java.util.Iterator) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) StringWriter(java.io.StringWriter) Publisher(org.reactivestreams.Publisher) IOException(java.io.IOException) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) Stream(java.util.stream.Stream) Subscription(org.reactivestreams.Subscription) Exceptions(reactor.core.Exceptions) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName)

Example 28 with ParameterizedTestWithName

use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.

the class FluxOnAssemblyTest method checkpointDescriptionAndForceStackForMono.

@ParameterizedTestWithName
@ValueSource(booleans = { false, true })
void checkpointDescriptionAndForceStackForMono(boolean debugModeOn) {
    if (debugModeOn) {
        Hooks.onOperatorDebug();
    }
    StringWriter sw = new StringWriter();
    Mono<Object> tested = Mono.just(1).map(i -> null).filter(Objects::nonNull).checkpoint("heavy", true).doOnError(t -> t.printStackTrace(new PrintWriter(sw)));
    StepVerifier.create(tested).verifyError();
    String debugStack = sw.toString();
    if (debugModeOn) {
        // the traceback "error has been observed" contains both individual ops and checkpoint with description,
        // assembly points to map, with no description
        assertThat(debugStack).contains("Assembly trace from producer [reactor.core.publisher.MonoMap] :").contains("Mono.filter ⇢ at reactor.core.publisher.FluxOnAssemblyTest.checkpointDescriptionAndForceStackForMono(").contains("checkpoint(heavy) ⇢ at reactor.core.publisher.FluxOnAssemblyTest.checkpointDescriptionAndForceStackForMono(");
    } else {
        // the traceback "error has been observed" only contains the checkpoint, with callsite and description,
        // assembly points to filter and reflects description
        assertThat(debugStack).contains("Assembly trace from producer [reactor.core.publisher.MonoFilterFuseable], described as [heavy] :").contains("checkpoint(heavy) ⇢ at reactor.core.publisher.FluxOnAssemblyTest.checkpointDescriptionAndForceStackForMono(").doesNotContain("Mono.filter ⇢ at");
    }
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Retry(reactor.util.retry.Retry) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AssemblySnapshot(reactor.core.publisher.FluxOnAssembly.AssemblySnapshot) CoreSubscriber(reactor.core.CoreSubscriber) Duration(java.time.Duration) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) PrintWriter(java.io.PrintWriter) ValueSource(org.junit.jupiter.params.provider.ValueSource) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) Iterator(java.util.Iterator) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) StringWriter(java.io.StringWriter) Publisher(org.reactivestreams.Publisher) IOException(java.io.IOException) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) Stream(java.util.stream.Stream) Subscription(org.reactivestreams.Subscription) Exceptions(reactor.core.Exceptions) StringWriter(java.io.StringWriter) Objects(java.util.Objects) PrintWriter(java.io.PrintWriter) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName)

Example 29 with ParameterizedTestWithName

use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.

the class SchedulersMetricsTest method shouldReportExecutionTimes.

@ParameterizedTestWithName
@MethodSource("metricsSchedulers")
@Timeout(10)
void shouldReportExecutionTimes(Supplier<Scheduler> schedulerType) {
    Scheduler scheduler = afterTest.autoDispose(schedulerType.get());
    final int taskCount = 3;
    Phaser phaser = new Phaser(1);
    for (int i = 1; i <= taskCount; i++) {
        phaser.register();
        // bumped delay from 20ms to make actual scheduling times more precise
        int delay = i * 200;
        scheduler.schedule(() -> {
            try {
                Thread.sleep(delay);
                phaser.arriveAndDeregister();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
    }
    phaser.arriveAndAwaitAdvance();
    Collection<Timer> timers = registry.find("executor").tag(TAG_SCHEDULER_ID, scheduler.toString()).timers();
    // Use Awaitility because "count" is reported "eventually"
    await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
        assertThat(timers.stream().reduce(0d, (time, timer) -> time + timer.totalTime(TimeUnit.MILLISECONDS), Double::sum)).as("total durations").isEqualTo(600 + 400 + 200, offset(50d));
        assertThat(timers.stream().mapToLong(Timer::count).sum()).as("count").isEqualTo(taskCount);
    });
}
Also used : Metrics(reactor.util.Metrics) TAG_SCHEDULER_ID(reactor.core.scheduler.SchedulerMetricDecorator.TAG_SCHEDULER_ID) BeforeEach(org.junit.jupiter.api.BeforeEach) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Supplier(java.util.function.Supplier) Timer(io.micrometer.core.instrument.Timer) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Assertions.offset(org.assertj.core.api.Assertions.offset) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) MethodSource(org.junit.jupiter.params.provider.MethodSource) Counter(io.micrometer.core.instrument.Counter) AutoDisposingExtension(reactor.test.AutoDisposingExtension) Awaitility.await(org.awaitility.Awaitility.await) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Meter(io.micrometer.core.instrument.Meter) Arguments(org.junit.jupiter.params.provider.Arguments) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Stream(java.util.stream.Stream) Named(org.junit.jupiter.api.Named) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Phaser(java.util.concurrent.Phaser) FunctionCounter(io.micrometer.core.instrument.FunctionCounter) Timeout(org.junit.jupiter.api.Timeout) Timer(io.micrometer.core.instrument.Timer) Phaser(java.util.concurrent.Phaser) Timeout(org.junit.jupiter.api.Timeout) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName)

Aggregations

ParameterizedTestWithName (reactor.test.ParameterizedTestWithName)29 Test (org.junit.jupiter.api.Test)28 Subscription (org.reactivestreams.Subscription)25 StepVerifier (reactor.test.StepVerifier)25 Stream (java.util.stream.Stream)24 CoreSubscriber (reactor.core.CoreSubscriber)24 Exceptions (reactor.core.Exceptions)21 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)20 Scannable (reactor.core.Scannable)20 Arrays (java.util.Arrays)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)17 Context (reactor.util.context.Context)17 Duration (java.time.Duration)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 Function (java.util.function.Function)14 Arguments (org.junit.jupiter.params.provider.Arguments)14 Arguments.arguments (org.junit.jupiter.params.provider.Arguments.arguments)14 MethodSource (org.junit.jupiter.params.provider.MethodSource)14 Publisher (org.reactivestreams.Publisher)14