use of reactor.core.publisher.MonoCollect.CollectSubscriber in project reactor-core by reactor.
the class MonoCollectTest method discardCancelNextRace.
@Test
public void discardCancelNextRace() {
lessVerboseLogs(Operators.class);
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);
CollectSubscriber<AtomicBoolean, List<AtomicBoolean>> subscriber = new CollectSubscriber<>(testSubscriber, List::add, new ArrayList<>());
subscriber.onSubscribe(Operators.emptySubscription());
AtomicBoolean extraneous = new AtomicBoolean(false);
RaceTestUtils.race(subscriber::cancel, () -> subscriber.onNext(extraneous));
testSubscriber.assertNoValues();
if (!extraneous.get()) {
LOGGER.info("" + subscriber.container);
}
assertThat(extraneous).as("released %d", i).isTrue();
}
LOGGER.info("discarded twice or more: {}", doubleDiscardCounter.get());
}
use of reactor.core.publisher.MonoCollect.CollectSubscriber in project reactor-core by reactor.
the class MonoCollectTest method scanSubscriber.
@Test
public void scanSubscriber() {
CoreSubscriber<List<String>> actual = new LambdaMonoSubscriber<>(null, e -> {
}, null, null);
CollectSubscriber<String, List<String>> test = new CollectSubscriber<>(actual, (l, v) -> l.add(v), new ArrayList<>());
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.MonoCollect.CollectSubscriber in project reactor-core by reactor.
the class MonoCollectTest method discardCancelCompleteRace.
@Test
public void discardCancelCompleteRace() {
lessVerboseLogs(Operators.class);
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);
CollectSubscriber<AtomicBoolean, List<AtomicBoolean>> subscriber = new CollectSubscriber<>(testSubscriber, List::add, new ArrayList<>());
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: {}", doubleDiscardCounter.get());
}
Aggregations