use of reactor.util.context.Context in project reactor-core by reactor.
the class FluxIterableTest method smokeTestIterableConditionalSubscriptionWithInfiniteIterable.
@Test
@Timeout(5)
void smokeTestIterableConditionalSubscriptionWithInfiniteIterable() {
// this test is simulating a poll() loop over an infinite iterable with conditional fusion enabled
AtomicInteger backingAtomic = new AtomicInteger();
Context discardingContext = Operators.enableOnDiscard(Context.empty(), v -> {
});
@SuppressWarnings("unchecked") Fuseable.ConditionalSubscriber<Integer> testSubscriber = Mockito.mock(Fuseable.ConditionalSubscriber.class);
Iterator<Integer> iterator = new Iterator<Integer>() {
@Override
public boolean hasNext() {
// approximate infinite source with a large upper bound instead
return backingAtomic.get() < 10_000;
}
@Override
public Integer next() {
return backingAtomic.incrementAndGet();
}
};
FluxIterable.IterableSubscriptionConditional<Integer> subscription = new FluxIterable.IterableSubscriptionConditional<>(testSubscriber, iterator, false);
subscription.cancel();
// protected by @Timeout(5)
Operators.onDiscardQueueWithClear(subscription, discardingContext, null);
assertThat(backingAtomic).hasValue(0);
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class DefaultContextExpectationsTest method notContextAccessibleDueToPublisher.
@Test
public void notContextAccessibleDueToPublisher() {
Publisher<Integer> publisher = subscriber -> subscriber.onSubscribe(new Subscription() {
@Override
public void request(long l) {
subscriber.onComplete();
}
@Override
public void cancel() {
// NO-OP
}
});
Step<Integer> step = StepVerifier.create(publisher);
DefaultContextExpectations<Integer> expectations = new DefaultContextExpectations<>(step, new MessageFormatter(null, null, null));
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> expectations.then().verifyComplete()).withMessage("No propagated Context");
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class DefaultContextExpectationsTest method notContainsOnlyOfContextSize.
@Test
public void notContainsOnlyOfContextSize() throws Exception {
Context expected = Context.of("foo", "bar", "other", "stuff");
assertContextExpectationFails(s -> s.contextWrite(Context.of("foo", "bar")), e -> e.containsOnly(expected)).withMessageStartingWith("" + "Expected Context to contain same values as Context2{foo=bar, other=stuff}, but they differ in size\n" + "Context: Context1{foo=bar}");
}
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);
}
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);
}
Aggregations