Search in sources :

Example 41 with Subscription

use of org.reactivestreams.Subscription in project reactor-core by reactor.

the class FluxBufferWhenTest method scanStartEndMainCompleted.

@Test
public void scanStartEndMainCompleted() {
    CoreSubscriber<List<String>> actual = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    FluxBufferWhen.BufferWhenMainSubscriber<String, Integer, Long, List<String>> test = new FluxBufferWhen.BufferWhenMainSubscriber<String, Integer, Long, List<String>>(actual, ArrayList::new, Queues.small(), Mono.just(1), u -> Mono.just(1L));
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    test.onComplete();
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 42 with Subscription

use of org.reactivestreams.Subscription in project reactor-core by reactor.

the class FluxCancelOnTest method scanSubscriber.

@Test
public void scanSubscriber() {
    CoreSubscriber<String> actual = new LambdaSubscriber<>(null, null, null, null);
    FluxCancelOn.CancelSubscriber<String> test = new FluxCancelOn.CancelSubscriber<>(actual, Schedulers.single());
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.RUN_ON)).isSameAs(Schedulers.single());
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.cancel();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 43 with Subscription

use of org.reactivestreams.Subscription in project reactor-core by reactor.

the class FluxDelayUntilTest method immediateCancel.

@Test
public void immediateCancel() {
    AtomicReference<String> value = new AtomicReference<>();
    AtomicReference<Throwable> error = new AtomicReference<>();
    Disposable s = Flux.just("foo", "bar").delayUntil(v -> Mono.just(1)).subscribe(value::set, error::set, () -> {
    }, Subscription::cancel);
    assertThat(value.get()).isNull();
    // would be a NPE if trigger array wasn't pre-initialized
    assertThat(error.get()).isNull();
}
Also used : Disposable(reactor.core.Disposable) Disposable(reactor.core.Disposable) StepVerifier(reactor.test.StepVerifier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Publisher(org.reactivestreams.Publisher) Subscription(org.reactivestreams.Subscription) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) AtomicReference(java.util.concurrent.atomic.AtomicReference) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 44 with Subscription

use of org.reactivestreams.Subscription in project reactor-core by reactor.

the class FluxDematerializeTest method scanSubscriber.

@Test
public void scanSubscriber() {
    CoreSubscriber<String> actual = new LambdaSubscriber<>(null, e -> {
    }, null, sub -> sub.request(100));
    FluxDematerialize.DematerializeSubscriber<String> test = new FluxDematerialize.DematerializeSubscriber<>(actual);
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(100L);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(0);
    test.value = "foo";
    assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);
    assertThat(test.scan(Scannable.Attr.ERROR)).isNull();
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    test.onError(new IllegalStateException("boom"));
    assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.cancel();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : Subscription(org.reactivestreams.Subscription) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Example 45 with Subscription

use of org.reactivestreams.Subscription in project reactor-core by reactor.

the class FluxDistinctTest method scanSubscriber.

@Test
public void scanSubscriber() {
    CoreSubscriber<String> actual = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    FluxDistinct.DistinctSubscriber<String, Integer, Set<Integer>> test = new FluxDistinct.DistinctSubscriber<>(actual, new HashSet<>(), String::hashCode, Set::add, Set::clear);
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    test.onError(new IllegalStateException("boom"));
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Aggregations

Subscription (org.reactivestreams.Subscription)627 Test (org.junit.Test)506 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)158 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)131 ArrayList (java.util.ArrayList)117 AtomicReference (java.util.concurrent.atomic.AtomicReference)105 List (java.util.List)80 FluxOperatorTest (reactor.test.publisher.FluxOperatorTest)74 Subscriber (org.reactivestreams.Subscriber)68 AtomicLong (java.util.concurrent.atomic.AtomicLong)56 Assert (org.junit.Assert)56 Arrays (java.util.Arrays)43 BaseSequentialTest (com.oath.cyclops.streams.BaseSequentialTest)42 Vector (cyclops.data.Vector)39 ReactiveSeq (cyclops.reactive.ReactiveSeq)39 Executor (java.util.concurrent.Executor)38 Spouts (cyclops.reactive.Spouts)36 Arrays.asList (java.util.Arrays.asList)36 Executors (java.util.concurrent.Executors)35 StepVerifier (reactor.test.StepVerifier)34