use of reactor.util.context.Context in project reactor-core by reactor.
the class SignalTest method nextStateWithContext.
@Test
public void nextStateWithContext() {
Context context = Context.of("foo", "bar");
Signal<Integer> s = Signal.next(1, context);
assertThat(s.getContext().isEmpty()).as("has context").isFalse();
assertThat(s.isOnComplete()).isFalse();
assertThat(s.isOnSubscribe()).isFalse();
assertThat(s.hasError()).isFalse();
assertThat(s.hasValue()).isTrue();
assertThat(s).isEqualTo(Signal.next(1));
assertThat(s).isNotEqualTo(Signal.next(2));
assertThat(s).isNotEqualTo(Signal.error(e));
assertThat(s).isNotEqualTo(Signal.complete());
assertThat(s).isNotEqualTo(Signal.subscribe(Operators.emptySubscription()));
assertThat(s.hashCode()).isEqualTo(Signal.next(1).hashCode());
assertThat(s.hashCode()).isNotEqualTo(Signal.next(2).hashCode());
assertThat(s.hashCode()).isNotEqualTo(Signal.error(e).hashCode());
assertThat(s.hashCode()).isNotEqualTo(Signal.complete().hashCode());
assertThat(s.hashCode()).isNotEqualTo(Signal.subscribe(Operators.emptySubscription()).hashCode());
assertThat(Signal.isComplete(s)).isFalse();
assertThat(Signal.isError(s)).isFalse();
assertThat(s.get()).isEqualTo(1);
assertThat(s.getType()).isEqualTo(SignalType.ON_NEXT);
assertThat(s.toString()).contains("onNext(1)");
StepVerifier.create(Flux.<Integer>from(sub -> {
sub.onSubscribe(Operators.emptySubscription());
s.accept(sub);
})).expectNext(1).thenCancel().verify();
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class SignalTest method subscribeStateWithContext.
@Test
public void subscribeStateWithContext() {
Context context = Context.of("foo", "bar");
Signal<Integer> s = Signal.subscribe(Operators.emptySubscription(), context);
assertThat(s.getContext().isEmpty()).as("has context").isFalse();
assertThat(s.isOnComplete()).isFalse();
assertThat(s.isOnSubscribe()).isTrue();
assertThat(s.hasError()).isFalse();
assertThat(s.hasValue()).isFalse();
assertThat(s).isEqualTo(Signal.subscribe(Operators.emptySubscription()));
assertThat(s).isNotEqualTo(Signal.subscribe(Operators.cancelledSubscription()));
assertThat(s).isNotEqualTo(Signal.next(1));
assertThat(s).isNotEqualTo(Signal.error(e));
assertThat(s).isNotEqualTo(Signal.complete());
assertThat(s.hashCode()).isEqualTo(Signal.subscribe(Operators.emptySubscription()).hashCode());
assertThat(s.hashCode()).isNotEqualTo(Signal.subscribe(Operators.cancelledSubscription()).hashCode());
assertThat(s.hashCode()).isNotEqualTo(Signal.next(1).hashCode());
assertThat(s.hashCode()).isNotEqualTo(Signal.error(e).hashCode());
assertThat(s.hashCode()).isNotEqualTo(Signal.complete().hashCode());
assertThat(Signal.isComplete(s)).isFalse();
assertThat(Signal.isError(s)).isFalse();
assertThat(s.getSubscription()).isEqualTo(Operators.emptySubscription());
assertThat(s.getType()).isEqualTo(SignalType.ON_SUBSCRIBE);
assertThat(s.toString()).contains("onSubscribe");
StepVerifier.create(Flux.<Integer>from(s::accept)).expectSubscription().thenCancel().verify();
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class SignalTest method completeStateWithContext.
@Test
public void completeStateWithContext() {
Context context = Context.of("foo", "bar");
Signal<Integer> s = Signal.complete(context);
assertThat(s.getContext().isEmpty()).as("has context").isFalse();
assertThat(s.isOnComplete()).isTrue();
assertThat(s.isOnSubscribe()).isFalse();
assertThat(s.hasError()).isFalse();
assertThat(s.hasValue()).isFalse();
assertThat(s).isEqualTo(Signal.complete());
assertThat(s).isNotEqualTo(Signal.error(e));
assertThat(s).isNotEqualTo(Signal.subscribe(Operators.emptySubscription()));
assertThat(s).isNotEqualTo(Signal.next(1));
assertThat(s.hashCode()).isEqualTo(Signal.complete().hashCode());
assertThat(s.hashCode()).isNotEqualTo(Signal.error(e).hashCode());
assertThat(s.hashCode()).isNotEqualTo(Signal.next(1).hashCode());
assertThat(s.hashCode()).isNotEqualTo(Signal.subscribe(Operators.emptySubscription()).hashCode());
assertThat(Signal.isComplete(s)).isTrue();
assertThat(Signal.isError(s)).isFalse();
assertThat(s.getType()).isEqualTo(SignalType.ON_COMPLETE);
assertThat(s.toString()).contains("onComplete");
StepVerifier.create(Flux.<Integer>from(sub -> {
sub.onSubscribe(Operators.emptySubscription());
s.accept(sub);
})).verifyComplete();
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method onNextErrorModeLocalStrategy.
@Test
public void onNextErrorModeLocalStrategy() {
List<Object> nextDropped = new ArrayList<>();
List<Object> errorDropped = new ArrayList<>();
Hooks.onNextDropped(nextDropped::add);
Hooks.onErrorDropped(errorDropped::add);
Hooks.onNextError(OnNextFailureStrategy.STOP);
Context c = Context.of(OnNextFailureStrategy.KEY_ON_NEXT_ERROR_STRATEGY, OnNextFailureStrategy.RESUME_DROP);
Exception error = new IllegalStateException("boom");
DeferredSubscription s = new Operators.DeferredSubscription();
try {
assertThat(s.isCancelled()).as("s initially cancelled").isFalse();
Throwable e = Operators.onNextError("foo", error, c, s);
assertThat(e).isNull();
assertThat(nextDropped).containsExactly("foo");
assertThat(errorDropped).containsExactly(error);
assertThat(s.isCancelled()).as("s cancelled").isFalse();
} finally {
Hooks.resetOnNextDropped();
Hooks.resetOnErrorDropped();
Hooks.resetOnNextError();
}
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method onNextFailureWithStrategyMatchingButNotNullDoesCancel.
@Test
public void onNextFailureWithStrategyMatchingButNotNullDoesCancel() {
Context context = Context.of(OnNextFailureStrategy.KEY_ON_NEXT_ERROR_STRATEGY, new OnNextFailureStrategy() {
@Override
public boolean test(Throwable error, @Nullable Object value) {
return true;
}
@Override
public Throwable process(Throwable error, @Nullable Object value, Context context) {
return error;
}
});
Operators.DeferredSubscription s = new Operators.DeferredSubscription();
Throwable t = Operators.onNextError("foo", new NullPointerException("bar"), context, s);
assertThat(t).as("exception processed").isNotNull().isInstanceOf(NullPointerException.class).hasNoSuppressedExceptions().hasNoCause();
assertThat(s.isCancelled()).as("subscription cancelled").isTrue();
}
Aggregations