use of reactor.util.context.Context in project reactor-core by reactor.
the class FluxDoOnEachTest method nextCompleteAndErrorHaveContext.
@Test
public void nextCompleteAndErrorHaveContext() {
Context context = Context.of("foo", "bar");
List<Signal> signals = new ArrayList<>();
StepVerifier.create(Flux.just("hello").doOnEach(signals::add), StepVerifierOptions.create().withInitialContext(context)).expectNext("hello").verifyComplete();
assertThat(signals).allSatisfy(signal -> assertThat(signal.getContext().hasKey("foo")).as("has Context value").isTrue());
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class FluxExpandTest method currentContextForExpandDepthSubscriber.
@Test
public void currentContextForExpandDepthSubscriber() {
final Context context = Context.of("foo", "bar");
CoreSubscriber<Integer> parentActual = new BaseSubscriber<Integer>() {
@Override
public Context currentContext() {
return context;
}
};
ExpandDepthSubscription<Integer> expandDepthSubscription = new ExpandDepthSubscription<>(parentActual, i -> i > 5 ? Mono.empty() : Mono.just(i + 1), 123);
ExpandDepthSubscriber<Integer> test = new ExpandDepthSubscriber<>(expandDepthSubscription);
assertThat(test.currentContext()).isSameAs(context);
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class FluxPeekFuseableTest method resumeConditional.
@Test
public void resumeConditional() {
RuntimeException nextError = new IllegalStateException("next");
List<Throwable> resumedErrors = new ArrayList<>();
List<Object> resumedValues = new ArrayList<>();
Context context = Context.of(OnNextFailureStrategy.KEY_ON_NEXT_ERROR_STRATEGY, OnNextFailureStrategy.resume((t, s) -> {
resumedErrors.add(t);
resumedValues.add(s);
}));
ConditionalAssertSubscriber<Integer> actual = new ConditionalAssertSubscriber<>(context);
SignalPeekThrowNext<Integer> peekParent = new SignalPeekThrowNext<>(nextError);
AssertQueueSubscription<Integer> qs = new AssertQueueSubscription<>();
PeekConditionalSubscriber<Integer> test = new PeekConditionalSubscriber<>(actual, peekParent);
test.onSubscribe(qs);
test.onNext(1);
assertThat(actual.next).as("onNext skips").isEmpty();
assertThat(qs.requested).as("onNext requested more").isEqualTo(1);
boolean tryOnNext = test.tryOnNext(2);
assertThat(tryOnNext).as("tryOnNext skips").isFalse();
test.onComplete();
assertThat(actual.error).isNull();
assertThat(actual.completed).isTrue();
assertThat(resumedErrors).containsExactly(nextError, nextError);
assertThat(resumedValues).containsExactly(1, 2);
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class FluxPeekFuseableTest method resumeFuseable.
@Test
public void resumeFuseable() {
RuntimeException nextError = new IllegalStateException("next");
List<Throwable> resumedErrors = new ArrayList<>();
List<Object> resumedValues = new ArrayList<>();
Context context = Context.of(OnNextFailureStrategy.KEY_ON_NEXT_ERROR_STRATEGY, OnNextFailureStrategy.resume((t, s) -> {
resumedErrors.add(t);
resumedValues.add(s);
}));
AssertSubscriber<Integer> actual = new AssertSubscriber<>(context, 0);
SignalPeekThrowNext<Integer> peekParent = new SignalPeekThrowNext<>(nextError);
AssertQueueSubscription<Integer> qs = new AssertQueueSubscription<>();
PeekFuseableSubscriber<Integer> test = new PeekFuseableSubscriber<>(actual, peekParent);
test.onSubscribe(qs);
test.onNext(1);
actual.assertNoValues();
assertThat(qs.requested).as("onNext requested more").isEqualTo(1);
qs.offer(3);
Integer polled = test.poll();
assertThat(polled).as("poll skips").isNull();
test.onComplete();
actual.assertNoValues();
actual.assertNoError();
actual.assertComplete();
assertThat(resumedErrors).containsExactly(nextError, nextError);
assertThat(resumedValues).containsExactly(1, 3);
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class FluxPeekFuseableTest method resumeFuseableConditional.
@Test
public void resumeFuseableConditional() {
RuntimeException nextError = new IllegalStateException("next");
List<Throwable> resumedErrors = new ArrayList<>();
List<Object> resumedValues = new ArrayList<>();
Context context = Context.of(OnNextFailureStrategy.KEY_ON_NEXT_ERROR_STRATEGY, OnNextFailureStrategy.resume((t, s) -> {
resumedErrors.add(t);
resumedValues.add(s);
}));
ConditionalAssertSubscriber<Integer> actual = new ConditionalAssertSubscriber<>(context);
SignalPeekThrowNext<Integer> peekParent = new SignalPeekThrowNext<>(nextError);
AssertQueueSubscription<Integer> qs = new AssertQueueSubscription<>();
PeekFuseableConditionalSubscriber<Integer> test = new PeekFuseableConditionalSubscriber<>(actual, peekParent);
test.onSubscribe(qs);
test.onNext(1);
assertThat(actual.next).as("onNext skips").isEmpty();
assertThat(qs.requested).as("onNext requested more").isEqualTo(1);
boolean tryOnNext = test.tryOnNext(2);
assertThat(tryOnNext).as("tryOnNext skips").isFalse();
qs.offer(3);
Integer polled = test.poll();
assertThat(polled).as("poll skips").isNull();
test.onComplete();
assertThat(actual.error).isNull();
assertThat(actual.completed).isTrue();
assertThat(resumedErrors).containsExactly(nextError, nextError, nextError);
assertThat(resumedValues).containsExactly(1, 2, 3);
}
Aggregations