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();
}
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();
}
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);
}
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();
}
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();
}
Aggregations