Search in sources :

Example 21 with Context

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());
}
Also used : Context(reactor.util.context.Context) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 22 with Context

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);
}
Also used : Context(reactor.util.context.Context) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExpandDepthSubscriber(reactor.core.publisher.FluxExpand.ExpandDepthSubscriber) ExpandDepthSubscription(reactor.core.publisher.FluxExpand.ExpandDepthSubscription) Test(org.junit.Test)

Example 23 with 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);
}
Also used : Context(reactor.util.context.Context) PeekConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekConditionalSubscriber) CoreMatchers(org.hamcrest.CoreMatchers) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Queues(reactor.util.concurrent.Queues) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Schedulers(reactor.core.scheduler.Schedulers) Thread.sleep(java.lang.Thread.sleep) MockUtils(reactor.test.MockUtils) Nullable(javax.annotation.Nullable) PeekFuseableSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableSubscriber) Context(reactor.util.context.Context) Test(org.junit.Test) Schedulers.parallel(reactor.core.scheduler.Schedulers.parallel) LongConsumer(java.util.function.LongConsumer) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Mockito(org.mockito.Mockito) List(java.util.List) Fuseable(reactor.core.Fuseable) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Queue(java.util.Queue) Assert(org.junit.Assert) Exceptions(reactor.core.Exceptions) Collections(java.util.Collections) PeekFuseableConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableConditionalSubscriber) PeekConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekConditionalSubscriber) ArrayList(java.util.ArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 24 with Context

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);
}
Also used : Context(reactor.util.context.Context) PeekConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekConditionalSubscriber) CoreMatchers(org.hamcrest.CoreMatchers) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Queues(reactor.util.concurrent.Queues) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Schedulers(reactor.core.scheduler.Schedulers) Thread.sleep(java.lang.Thread.sleep) MockUtils(reactor.test.MockUtils) Nullable(javax.annotation.Nullable) PeekFuseableSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableSubscriber) Context(reactor.util.context.Context) Test(org.junit.Test) Schedulers.parallel(reactor.core.scheduler.Schedulers.parallel) LongConsumer(java.util.function.LongConsumer) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Mockito(org.mockito.Mockito) List(java.util.List) Fuseable(reactor.core.Fuseable) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Queue(java.util.Queue) Assert(org.junit.Assert) Exceptions(reactor.core.Exceptions) Collections(java.util.Collections) PeekFuseableConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableConditionalSubscriber) ArrayList(java.util.ArrayList) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PeekFuseableSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableSubscriber) Test(org.junit.Test)

Example 25 with Context

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);
}
Also used : Context(reactor.util.context.Context) PeekConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekConditionalSubscriber) CoreMatchers(org.hamcrest.CoreMatchers) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Queues(reactor.util.concurrent.Queues) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Schedulers(reactor.core.scheduler.Schedulers) Thread.sleep(java.lang.Thread.sleep) MockUtils(reactor.test.MockUtils) Nullable(javax.annotation.Nullable) PeekFuseableSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableSubscriber) Context(reactor.util.context.Context) Test(org.junit.Test) Schedulers.parallel(reactor.core.scheduler.Schedulers.parallel) LongConsumer(java.util.function.LongConsumer) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Mockito(org.mockito.Mockito) List(java.util.List) Fuseable(reactor.core.Fuseable) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Queue(java.util.Queue) Assert(org.junit.Assert) Exceptions(reactor.core.Exceptions) Collections(java.util.Collections) PeekFuseableConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableConditionalSubscriber) PeekFuseableConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableConditionalSubscriber) ArrayList(java.util.ArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

Context (reactor.util.context.Context)35 Test (org.junit.Test)28 AtomicReference (java.util.concurrent.atomic.AtomicReference)14 Consumer (java.util.function.Consumer)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 ArrayList (java.util.ArrayList)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Nullable (javax.annotation.Nullable)8 Scannable (reactor.core.Scannable)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 Function (java.util.function.Function)7 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)7 Flux (reactor.core.publisher.Flux)7 Mono (reactor.core.publisher.Mono)7 StepVerifier (reactor.test.StepVerifier)7 List (java.util.List)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Subscription (org.reactivestreams.Subscription)6 CoreSubscriber (reactor.core.CoreSubscriber)6 Exceptions (reactor.core.Exceptions)6