use of reactor.core.Disposable in project reactor-core by reactor.
the class NextProcessorTest method shareCanDisconnectAndReconnect.
@Test
void shareCanDisconnectAndReconnect() {
AtomicInteger connectionCount = new AtomicInteger();
AtomicInteger disconnectionCount = new AtomicInteger();
Mono<Object> shared = Mono.never().doFirst(() -> connectionCount.incrementAndGet()).doOnCancel(() -> disconnectionCount.incrementAndGet()).share();
Disposable sub1 = shared.subscribe();
assertThat(connectionCount).as("sub1 connectionCount").hasValue(1);
assertThat(disconnectionCount).as("sub1 disconnectionCount before dispose").hasValue(0);
sub1.dispose();
assertThat(disconnectionCount).as("sub1 disconnectionCount after dispose").hasValue(1);
Disposable sub2 = shared.subscribe();
assertThat(connectionCount).as("sub2 connectionCount").hasValue(2);
assertThat(disconnectionCount).as("sub2 disconnectionCount before dispose").hasValue(1);
sub2.dispose();
assertThat(disconnectionCount).as("sub2 disconnectionCount after dispose").hasValue(2);
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class NextProcessorTest method monoShareSubscribeNoArgsCanBeIndividuallyDisposed.
@Test
void monoShareSubscribeNoArgsCanBeIndividuallyDisposed() {
AtomicInteger cancelledCount = new AtomicInteger();
Mono<Object> mono = Mono.never().doOnCancel(cancelledCount::incrementAndGet).share();
Disposable sub1 = mono.subscribe();
Disposable sub2 = mono.subscribe();
assertThat(sub1).as("subscription are differentiated").isNotSameAs(sub2);
sub1.dispose();
assertThat(cancelledCount).as("not cancelled when 1+ subscriber").hasValue(0);
AtomicBoolean sub3Terminated = new AtomicBoolean();
Disposable sub3 = mono.doOnTerminate(() -> sub3Terminated.set(true)).subscribe();
assertThat(sub3).as("3rd subscribe differentiated").isNotSameAs(sub2);
assertThat(sub3Terminated).as("subscription still possible once sub disposed").isFalse();
sub2.dispose();
sub3.dispose();
Scannable.from(mono).inners().forEach(System.out::println);
assertThat(cancelledCount).as("cancelled once 0 subscriber").hasValue(1);
AtomicBoolean sub4Terminated = new AtomicBoolean();
Disposable sub4 = mono.doOnTerminate(() -> sub4Terminated.set(true)).subscribe();
assertThat(sub4Terminated).as("subscription still possible once all subs disposed").isFalse();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class SinkManyBestEffortTest method innersReflectsSubscribers.
@Test
void innersReflectsSubscribers() {
SinkManyBestEffort<Integer> sink = SinkManyBestEffort.createBestEffort();
assertThat(sink.inners()).as("before subscribers").isEmpty();
Disposable sub1 = sink.subscribe();
Disposable sub2 = sink.subscribe();
assertThat(sink.inners()).hasSize(2);
assertThat(sink.inners().map(inner -> inner.scanUnsafe(Scannable.Attr.ACTUAL))).containsExactly(sub1, sub2);
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class UnicastProcessorTest method emitNextWithNoSubscriberAndBoundedQueueAndHandlerHandlesValueAndKeepsSinkOpen.
// TODO that onOverflow API isn't exposed via Sinks. But maybe it should be generalized?
@Test
public void emitNextWithNoSubscriberAndBoundedQueueAndHandlerHandlesValueAndKeepsSinkOpen() {
Disposable sinkDisposed = Disposables.single();
List<Integer> discarded = new CopyOnWriteArrayList<>();
UnicastProcessor<Integer> unicastProcessor = UnicastProcessor.create(Queues.<Integer>one().get(), discarded::add, sinkDisposed);
// fill the buffer
unicastProcessor.tryEmitNext(1);
// this "overflows" but keeps the sink open
unicastProcessor.emitNext(2, FAIL_FAST);
assertThat(discarded).containsExactly(2);
assertThat(sinkDisposed.isDisposed()).as("sinkDisposed").isFalse();
unicastProcessor.emitComplete(FAIL_FAST);
// let's verify we get the buffer's content
StepVerifier.create(unicastProcessor).expectNext(// from the buffer
1).verifyComplete();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class UnicastProcessorTest method createOverrideQueueOnTerminate.
@Test
public void createOverrideQueueOnTerminate() {
Disposable onTerminate = () -> {
};
Queue<Integer> queue = Queues.<Integer>get(10).get();
UnicastProcessor<Integer> processor = UnicastProcessor.create(queue, onTerminate);
assertProcessor(processor, queue, null, onTerminate);
}
Aggregations