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");
}
}
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");
}
}
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");
}
}
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);
});
}
Aggregations