use of reactor.core.Disposable 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();
}
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 EmitterProcessorTest method state.
@Test
public void state() {
EmitterProcessor<Integer> tp = EmitterProcessor.create();
assertThat(tp.getPending()).isEqualTo(0);
assertThat(tp.getBufferSize()).isEqualTo(Queues.SMALL_BUFFER_SIZE);
assertThat(tp.isCancelled()).isFalse();
assertThat(tp.inners()).isEmpty();
Disposable d1 = tp.subscribe();
assertThat(tp.inners()).hasSize(1);
FluxSink<Integer> s = tp.sink();
s.next(2);
s.next(3);
s.next(4);
assertThat(tp.getPending()).isEqualTo(0);
AtomicReference<Subscription> d2 = new AtomicReference<>();
tp.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() {
}
});
s.next(5);
s.next(6);
s.next(7);
assertThat(tp.scan(BUFFERED)).isEqualTo(3);
assertThat(tp.isTerminated()).isFalse();
s.complete();
assertThat(tp.isTerminated()).isFalse();
d1.dispose();
d2.get().cancel();
assertThat(tp.isTerminated()).isTrue();
StepVerifier.create(tp).verifyComplete();
// noop
tp.onNext(8);
EmitterProcessor<Void> empty = EmitterProcessor.create();
empty.onComplete();
assertThat(empty.isTerminated()).isTrue();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class PublisherProbeTest method assertWasNotCancelledMono.
@Test
public void assertWasNotCancelledMono() {
PublisherProbe<Void> probe = PublisherProbe.of(Mono.never());
Disposable d = probe.mono().subscribe();
probe.assertWasNotCancelled();
d.dispose();
assertThatExceptionOfType(AssertionError.class).isThrownBy(probe::assertWasNotCancelled).withMessage("PublisherProbe should not have been cancelled but it was");
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class PublisherProbeTest method wasCancelledMono.
@Test
public void wasCancelledMono() {
PublisherProbe<Void> probe = PublisherProbe.of(Mono.never());
Disposable d = probe.mono().subscribe();
assertThat(probe.wasCancelled()).isFalse();
d.dispose();
assertThat(probe.wasCancelled()).isTrue();
}
Aggregations