use of reactor.core.publisher.MonoCollectList.MonoCollectListSubscriber in project reactor-core by reactor.
the class MonoCollectListTest method discardCancelNextRace.
@Test
@Tag("slow")
public void discardCancelNextRace() {
AtomicInteger doubleDiscardCounter = new AtomicInteger();
Context discardingContext = Operators.enableOnDiscard(null, o -> {
AtomicBoolean ab = (AtomicBoolean) o;
if (ab.getAndSet(true)) {
doubleDiscardCounter.incrementAndGet();
}
});
for (int i = 0; i < 100_000; i++) {
AssertSubscriber<List<AtomicBoolean>> testSubscriber = new AssertSubscriber<>(discardingContext);
MonoCollectListSubscriber<AtomicBoolean> subscriber = new MonoCollectListSubscriber<>(testSubscriber);
subscriber.onSubscribe(Operators.emptySubscription());
AtomicBoolean extraneous = new AtomicBoolean(false);
RaceTestUtils.race(subscriber::cancel, () -> subscriber.onNext(extraneous));
testSubscriber.assertNoValues();
if (!extraneous.get()) {
LOGGER.info("" + subscriber.list);
}
assertThat(extraneous).as("released %d", i).isTrue();
}
LOGGER.info("{} discarded twice or more in discardCancelNextRace", doubleDiscardCounter.get());
}
use of reactor.core.publisher.MonoCollectList.MonoCollectListSubscriber in project reactor-core by reactor.
the class MonoCollectListTest method scanBufferAllSubscriber.
@Test
public void scanBufferAllSubscriber() {
CoreSubscriber<List<String>> actual = new LambdaMonoSubscriber<>(null, e -> {
}, null, null);
MonoCollectListSubscriber<String> test = new MonoCollectListSubscriber<>(actual);
Subscription parent = Operators.emptySubscription();
test.onSubscribe(parent);
assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
assertThat(test.scan(Scannable.Attr.RUN_STYLE)).isSameAs(Scannable.Attr.RunStyle.SYNC);
assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
test.onError(new IllegalStateException("boom"));
assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
test.cancel();
assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
use of reactor.core.publisher.MonoCollectList.MonoCollectListSubscriber in project reactor-core by reactor.
the class MonoCollectListTest method discardCancelCompleteRace.
@Test
@Tag("slow")
public void discardCancelCompleteRace() {
AtomicInteger doubleDiscardCounter = new AtomicInteger();
Context discardingContext = Operators.enableOnDiscard(null, o -> {
AtomicBoolean ab = (AtomicBoolean) o;
if (ab.getAndSet(true)) {
doubleDiscardCounter.incrementAndGet();
}
});
for (int i = 0; i < 100_000; i++) {
AssertSubscriber<List<AtomicBoolean>> testSubscriber = new AssertSubscriber<>(discardingContext);
MonoCollectListSubscriber<AtomicBoolean> subscriber = new MonoCollectListSubscriber<>(testSubscriber);
subscriber.onSubscribe(Operators.emptySubscription());
AtomicBoolean resource = new AtomicBoolean(false);
subscriber.onNext(resource);
RaceTestUtils.race(subscriber::cancel, subscriber::onComplete);
if (testSubscriber.values().isEmpty()) {
assertThat(resource).as("not completed and released %d", i).isTrue();
}
}
LOGGER.info("{} discarded twice or more in discardCancelCompleteRace", doubleDiscardCounter.get());
}
Aggregations