Search in sources :

Example 1 with MonoCollectListSubscriber

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());
}
Also used : Context(reactor.util.context.Context) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MonoCollectListSubscriber(reactor.core.publisher.MonoCollectList.MonoCollectListSubscriber) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) List(java.util.List) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 2 with MonoCollectListSubscriber

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();
}
Also used : MonoCollectListSubscriber(reactor.core.publisher.MonoCollectList.MonoCollectListSubscriber) List(java.util.List) Subscription(org.reactivestreams.Subscription) Test(org.junit.jupiter.api.Test)

Example 3 with MonoCollectListSubscriber

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());
}
Also used : Context(reactor.util.context.Context) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MonoCollectListSubscriber(reactor.core.publisher.MonoCollectList.MonoCollectListSubscriber) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) List(java.util.List) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Aggregations

List (java.util.List)3 Test (org.junit.jupiter.api.Test)3 MonoCollectListSubscriber (reactor.core.publisher.MonoCollectList.MonoCollectListSubscriber)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Tag (org.junit.jupiter.api.Tag)2 AssertSubscriber (reactor.test.subscriber.AssertSubscriber)2 Context (reactor.util.context.Context)2 Subscription (org.reactivestreams.Subscription)1