use of reactor.util.context.Context in project reactor-core by reactor.
the class SignalLoggerTests method currentContextLogWhenDebug.
@Test
public void currentContextLogWhenDebug() {
TestLogger logger = new TestLogger();
SignalLogger<?> signalLogger = new SignalLogger<>(Mono.empty(), null, Level.FINE, false, name -> logger);
assertThat(logger.getOutContent()).as("before currentContext()").isEmpty();
Context context = Context.of("foo", "bar");
signalLogger.onCurrentContextCall().accept(context);
assertThat(logger.getOutContent()).startsWith("[DEBUG] (").endsWith(") currentContext(Context1{foo=bar})\n");
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class DirectProcessorTest method currentContextDelegatesToFirstSubscriber.
@Test
public void currentContextDelegatesToFirstSubscriber() {
AssertSubscriber<Object> testSubscriber1 = new AssertSubscriber<>(Context.of("key", "value1"));
AssertSubscriber<Object> testSubscriber2 = new AssertSubscriber<>(Context.of("key", "value2"));
DirectProcessor<Object> directProcessor = new DirectProcessor<>();
directProcessor.subscribe(testSubscriber1);
directProcessor.subscribe(testSubscriber2);
Context processorContext = directProcessor.currentContext();
assertThat(processorContext.getOrDefault("key", "EMPTY")).isEqualTo("value1");
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class MonoCollectListTest method discardCancelNextRace.
@Test
@Tag("slow")
public void discardCancelNextRace() {
AtomicInteger doubleDiscardCounter = new AtomicInteger();
Context discardingContext = Operators.enableOnDiscard(null, o -> {
AtomicBoolean ab = (AtomicBoolean) o;
if (ab.getAndSet(true)) {
doubleDiscardCounter.incrementAndGet();
}
});
for (int i = 0; i < 100_000; i++) {
AssertSubscriber<List<AtomicBoolean>> testSubscriber = new AssertSubscriber<>(discardingContext);
MonoCollectListSubscriber<AtomicBoolean> subscriber = new MonoCollectListSubscriber<>(testSubscriber);
subscriber.onSubscribe(Operators.emptySubscription());
AtomicBoolean extraneous = new AtomicBoolean(false);
RaceTestUtils.race(subscriber::cancel, () -> subscriber.onNext(extraneous));
testSubscriber.assertNoValues();
if (!extraneous.get()) {
LOGGER.info("" + subscriber.list);
}
assertThat(extraneous).as("released %d", i).isTrue();
}
LOGGER.info("{} discarded twice or more in discardCancelNextRace", doubleDiscardCounter.get());
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class MonoCollectTest method discardCancelNextRace.
@Test
public void discardCancelNextRace() {
lessVerboseLogs(Operators.class);
AtomicInteger doubleDiscardCounter = new AtomicInteger();
Context discardingContext = Operators.enableOnDiscard(null, o -> {
AtomicBoolean ab = (AtomicBoolean) o;
if (ab.getAndSet(true)) {
doubleDiscardCounter.incrementAndGet();
}
});
for (int i = 0; i < 100_000; i++) {
AssertSubscriber<List<AtomicBoolean>> testSubscriber = new AssertSubscriber<>(discardingContext);
CollectSubscriber<AtomicBoolean, List<AtomicBoolean>> subscriber = new CollectSubscriber<>(testSubscriber, List::add, new ArrayList<>());
subscriber.onSubscribe(Operators.emptySubscription());
AtomicBoolean extraneous = new AtomicBoolean(false);
RaceTestUtils.race(subscriber::cancel, () -> subscriber.onNext(extraneous));
testSubscriber.assertNoValues();
if (!extraneous.get()) {
LOGGER.info("" + subscriber.container);
}
assertThat(extraneous).as("released %d", i).isTrue();
}
LOGGER.info("discarded twice or more: {}", doubleDiscardCounter.get());
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class LambdaMonoSubscriberTest method initialContextIsUsedForOnErrorDropped.
@Test
public void initialContextIsUsedForOnErrorDropped() {
AtomicReference<Throwable> droppedRef = new AtomicReference<>();
Context ctx = Context.of(Hooks.KEY_ON_ERROR_DROPPED, (Consumer<Throwable>) droppedRef::set);
IllegalStateException expectDropped = new IllegalStateException("boom2");
LambdaMonoSubscriber<Object> sub = new LambdaMonoSubscriber<>(null, e -> {
}, null, null, ctx);
sub.onError(new IllegalStateException("boom1"));
// now trigger drop
sub.onError(expectDropped);
assertThat(droppedRef).hasValue(expectDropped);
}
Aggregations