Search in sources :

Example 1 with BufferAsyncSink

use of reactor.core.publisher.FluxCreate.BufferAsyncSink in project reactor-core by reactor.

the class FluxCreateTest method serializedBufferSinkRaceNextCancel.

@Test
void serializedBufferSinkRaceNextCancel() {
    AtomicInteger discarded = new AtomicInteger();
    final Context context = Operators.discardLocalAdapter(String.class, s -> discarded.incrementAndGet()).apply(Context.empty());
    BufferAsyncSink<String> baseSink = new BufferAsyncSink<>(new BaseSubscriber<String>() {

        @Override
        protected void hookOnSubscribe(Subscription subscription) {
        // do not request
        }

        @Override
        public Context currentContext() {
            return context;
        }
    }, 10);
    SerializedFluxSink<String> serializedSink = new SerializedFluxSink<>(baseSink);
    RaceTestUtils.race(baseSink::cancel, () -> serializedSink.next("foo"));
    assertThat(serializedSink.mpscQueue.poll()).as("serialized internal queue empty").isNull();
    assertThat(baseSink.queue.poll()).as("bufferAsyncSink internal queue empty").isNull();
    assertThat(discarded).as("discarded").hasValue(1);
}
Also used : Context(reactor.util.context.Context) IntStream(java.util.stream.IntStream) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SerializedFluxSink(reactor.core.publisher.FluxCreate.SerializedFluxSink) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OverflowStrategy(reactor.core.publisher.FluxSink.OverflowStrategy) EnumSource(org.junit.jupiter.params.provider.EnumSource) Scheduler(reactor.core.scheduler.Scheduler) AtomicReference(java.util.concurrent.atomic.AtomicReference) BufferAsyncSink(reactor.core.publisher.FluxCreate.BufferAsyncSink) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LatestAsyncSink(reactor.core.publisher.FluxCreate.LatestAsyncSink) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Schedulers(reactor.core.scheduler.Schedulers) RaceTestUtils(reactor.test.util.RaceTestUtils) Subscriber(org.reactivestreams.Subscriber) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) Semaphore(java.util.concurrent.Semaphore) Step(reactor.test.StepVerifier.Step) Context(reactor.util.context.Context) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) Assertions.fail(org.assertj.core.api.Assertions.fail) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Exceptions(reactor.core.Exceptions) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) SerializedFluxSink(reactor.core.publisher.FluxCreate.SerializedFluxSink) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) BufferAsyncSink(reactor.core.publisher.FluxCreate.BufferAsyncSink) Test(org.junit.jupiter.api.Test)

Example 2 with BufferAsyncSink

use of reactor.core.publisher.FluxCreate.BufferAsyncSink in project reactor-core by reactor.

the class FluxCreateTest method bufferSinkRaceNextCancel.

@Test
void bufferSinkRaceNextCancel() {
    AtomicInteger discarded = new AtomicInteger();
    final Context context = Operators.discardLocalAdapter(String.class, s -> discarded.incrementAndGet()).apply(Context.empty());
    BufferAsyncSink<String> sink = new BufferAsyncSink<>(new BaseSubscriber<String>() {

        @Override
        protected void hookOnSubscribe(Subscription subscription) {
        // do not request
        }

        @Override
        public Context currentContext() {
            return context;
        }
    }, 10);
    RaceTestUtils.race(sink::cancel, () -> sink.next("foo"));
    assertThat(sink.queue.poll()).as("internal queue empty").isNull();
    assertThat(discarded).as("discarded").hasValue(1);
}
Also used : Context(reactor.util.context.Context) IntStream(java.util.stream.IntStream) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SerializedFluxSink(reactor.core.publisher.FluxCreate.SerializedFluxSink) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OverflowStrategy(reactor.core.publisher.FluxSink.OverflowStrategy) EnumSource(org.junit.jupiter.params.provider.EnumSource) Scheduler(reactor.core.scheduler.Scheduler) AtomicReference(java.util.concurrent.atomic.AtomicReference) BufferAsyncSink(reactor.core.publisher.FluxCreate.BufferAsyncSink) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LatestAsyncSink(reactor.core.publisher.FluxCreate.LatestAsyncSink) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Schedulers(reactor.core.scheduler.Schedulers) RaceTestUtils(reactor.test.util.RaceTestUtils) Subscriber(org.reactivestreams.Subscriber) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) Semaphore(java.util.concurrent.Semaphore) Step(reactor.test.StepVerifier.Step) Context(reactor.util.context.Context) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) Assertions.fail(org.assertj.core.api.Assertions.fail) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Exceptions(reactor.core.Exceptions) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) BufferAsyncSink(reactor.core.publisher.FluxCreate.BufferAsyncSink) Test(org.junit.jupiter.api.Test)

Aggregations

ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Executors (java.util.concurrent.Executors)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 Semaphore (java.util.concurrent.Semaphore)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 IntStream (java.util.stream.IntStream)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.fail (org.assertj.core.api.Assertions.fail)2 Test (org.junit.jupiter.api.Test)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 Subscriber (org.reactivestreams.Subscriber)2 Subscription (org.reactivestreams.Subscription)2 CoreSubscriber (reactor.core.CoreSubscriber)2 Exceptions (reactor.core.Exceptions)2 Scannable (reactor.core.Scannable)2 BufferAsyncSink (reactor.core.publisher.FluxCreate.BufferAsyncSink)2