Search in sources :

Example 1 with SerializedFluxSink

use of reactor.core.publisher.FluxCreate.SerializedFluxSink 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)

Aggregations

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