Search in sources :

Example 36 with Subscription

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

the class FluxBufferTest method scanOverlappingSubscriber.

@Test
public void scanOverlappingSubscriber() {
    CoreSubscriber<? super List> actual = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    FluxBuffer.BufferOverlappingSubscriber<String, List<String>> test = new FluxBuffer.BufferOverlappingSubscriber<>(actual, 23, 2, ArrayList::new);
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    test.onNext("foo");
    test.onNext("bar");
    assertThat(test.scan(Scannable.Attr.CAPACITY)).isEqualTo(23);
    assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(2);
    test.onNext("baz");
    // 2 buffers
    assertThat(test.scan(Scannable.Attr.CAPACITY)).isEqualTo(46);
    // buffered foo bar baz then baz
    assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(4);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(Long.MAX_VALUE);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.onError(new IllegalStateException("boom"));
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Example 37 with Subscription

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

the class FluxBufferTest method scanExactSubscriber.

@Test
public void scanExactSubscriber() {
    CoreSubscriber<? super List> actual = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    FluxBuffer.BufferExactSubscriber<String, List<String>> test = new FluxBuffer.BufferExactSubscriber<>(actual, 23, ArrayList::new);
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    test.onNext("foo");
    assertThat(test.scan(Scannable.Attr.CAPACITY)).isEqualTo(23);
    assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(23);
    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 : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Example 38 with Subscription

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

the class FluxBufferTimeoutTest method downstreamDemandShouldBeAbleToDecreaseOnTimeSpan.

@Test
public void downstreamDemandShouldBeAbleToDecreaseOnTimeSpan() {
    Subscription[] subscriptionsHolder = new Subscription[1];
    CoreSubscriber<List<String>> actual = new LambdaSubscriber<>(null, e -> {
    }, null, s -> subscriptionsHolder[0] = s);
    VirtualTimeScheduler timeScheduler = VirtualTimeScheduler.getOrSet();
    FluxBufferTimeout.BufferTimeoutSubscriber<String, List<String>> test = new FluxBufferTimeout.BufferTimeoutSubscriber<String, List<String>>(actual, 5, 100, timeScheduler.createWorker(), ArrayList::new);
    Subscription subscription = Operators.emptySubscription();
    test.onSubscribe(subscription);
    subscriptionsHolder[0].request(1);
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(1L);
    timeScheduler.advanceTimeBy(Duration.ofMillis(100));
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(1L);
    test.onNext(String.valueOf("0"));
    timeScheduler.advanceTimeBy(Duration.ofMillis(100));
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(0L);
}
Also used : VirtualTimeScheduler(reactor.test.scheduler.VirtualTimeScheduler) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 39 with Subscription

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

the class FluxBufferWhenTest method scanStartEndMain.

@Test
public void scanStartEndMain() {
    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);
    test.request(100L);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
    // TODO
    assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(0);
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(100L);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    test.onError(new IllegalStateException("boom"));
    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 40 with Subscription

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

the class FluxBufferWhenTest method scanWhenOpenSubscriber.

@Test
public void scanWhenOpenSubscriber() {
    // noinspection ConstantConditions
    FluxBufferWhen.BufferWhenMainSubscriber<String, Integer, Long, List<String>> main = new FluxBufferWhen.BufferWhenMainSubscriber<>(null, ArrayList::new, Queues.small(), Mono.just(1), u -> Mono.just(1L));
    FluxBufferWhen.BufferWhenOpenSubscriber test = new FluxBufferWhen.BufferWhenOpenSubscriber<>(main);
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(Long.MAX_VALUE);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(main);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.dispose();
    assertThat(test.isDisposed()).isTrue();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

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