use of reactor.core.Disposable in project reactor-core by reactor.
the class EmitterProcessorTest method scanMain.
@Test
public void scanMain() {
EmitterProcessor<Integer> test = EmitterProcessor.create(123);
assertThat(test.scan(BUFFERED)).isEqualTo(0);
assertThat(test.scan(CANCELLED)).isFalse();
assertThat(test.scan(PREFETCH)).isEqualTo(123);
assertThat(test.scan(CAPACITY)).isEqualTo(123);
Disposable d1 = test.subscribe();
FluxSink<Integer> sink = test.sink();
sink.next(2);
sink.next(3);
sink.next(4);
assertThat(test.scan(BUFFERED)).isEqualTo(0);
AtomicReference<Subscription> d2 = new AtomicReference<>();
test.subscribe(new CoreSubscriber<Integer>() {
@Override
public void onSubscribe(Subscription s) {
d2.set(s);
}
@Override
public void onNext(Integer integer) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onComplete() {
}
});
sink.next(5);
sink.next(6);
sink.next(7);
assertThat(test.scan(BUFFERED)).isEqualTo(3);
assertThat(test.scan(TERMINATED)).isFalse();
sink.complete();
assertThat(test.scan(TERMINATED)).isFalse();
d1.dispose();
d2.get().cancel();
assertThat(test.scan(TERMINATED)).isTrue();
// other values
assertThat(test.scan(Scannable.Attr.PARENT)).isNotNull();
assertThat(test.scan(Attr.ERROR)).isNull();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class MonoCacheTimeTest method totalCancelDoesntCancelSource.
@Test
public void totalCancelDoesntCancelSource() {
AtomicInteger cancelled = new AtomicInteger();
Mono<Object> cached = Mono.never().doOnCancel(cancelled::incrementAndGet).cache(Duration.ofMillis(200));
Disposable d1 = cached.subscribe();
Disposable d2 = cached.subscribe();
d1.dispose();
d2.dispose();
assertThat(cancelled).hasValue(0);
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class MonoCacheInvalidateWhenTest method cancellingAllSubscribersBeforeOnNextInvalidates.
@Test
void cancellingAllSubscribersBeforeOnNextInvalidates() {
TestPublisher<Integer> source = TestPublisher.create();
Mono<Integer> cached = source.mono().cacheInvalidateWhen(i -> Mono.never());
Disposable sub1 = cached.subscribe();
Disposable sub2 = cached.subscribe();
Disposable sub3 = cached.subscribe();
source.assertWasSubscribed();
source.assertNotCancelled();
sub1.dispose();
source.assertNotCancelled();
sub2.dispose();
source.assertNotCancelled();
sub3.dispose();
source.assertCancelled(1);
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class MonoCacheInvalidateIfTest method cancellingAllSubscribersBeforeOnNextInvalidates.
@Test
void cancellingAllSubscribersBeforeOnNextInvalidates() {
TestPublisher<Integer> source = TestPublisher.create();
Mono<Integer> cached = source.mono().cacheInvalidateIf(i -> false);
Disposable sub1 = cached.subscribe();
Disposable sub2 = cached.subscribe();
Disposable sub3 = cached.subscribe();
source.assertWasSubscribed();
source.assertNotCancelled();
sub1.dispose();
source.assertNotCancelled();
sub2.dispose();
source.assertNotCancelled();
sub3.dispose();
source.assertCancelled(1);
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class MonoCacheTimeTest method totalCancelCanResubscribe.
@Test
public void totalCancelCanResubscribe() {
AtomicInteger cancelled = new AtomicInteger();
AtomicInteger subscribed = new AtomicInteger();
TestPublisher<Integer> source = TestPublisher.create();
Mono<Integer> cached = source.mono().doOnSubscribe(s -> subscribed.incrementAndGet()).doOnCancel(cancelled::incrementAndGet).cache(Duration.ofMillis(200));
Disposable d1 = cached.subscribe();
Disposable d2 = cached.subscribe();
d1.dispose();
d2.dispose();
assertThat(cancelled).hasValue(0);
assertThat(subscribed).hasValue(1);
StepVerifier.create(cached).then(() -> source.emit(100)).expectNext(100).verifyComplete();
assertThat(cancelled).hasValue(0);
assertThat(subscribed).hasValue(1);
}
Aggregations