Search in sources :

Example 36 with AssertSubscriber

use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.

the class FluxRepeatWhenTest method repeatAlwaysScalar.

@Test
public void repeatAlwaysScalar() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create(0);
    AtomicInteger count = new AtomicInteger();
    Flux.just(1).map(d -> count.incrementAndGet()).repeatWhen(v -> v).subscribe(ts);
    ts.request(8);
    ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8).assertNoError().assertNotComplete();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Context(reactor.util.context.Context) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Tuples(reactor.util.function.Tuples) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Collections(java.util.Collections) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 37 with AssertSubscriber

use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.

the class FluxMergeSequentialTest method testPrefetchIsBounded.

@Test
public void testPrefetchIsBounded() {
    final AtomicInteger count = new AtomicInteger();
    AssertSubscriber<Object> ts = AssertSubscriber.create(0);
    Flux.just(1).hide().flatMapSequential(t -> Flux.range(1, Queues.SMALL_BUFFER_SIZE * 2).doOnNext(t1 -> count.getAndIncrement()).hide()).subscribe(ts);
    ts.assertNoError();
    ts.assertNoValues();
    ts.assertNotComplete();
    Assert.assertEquals(Queues.XS_BUFFER_SIZE, count.get());
}
Also used : ErrorMode(reactor.core.publisher.FluxConcatMap.ErrorMode) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Scheduler(reactor.core.scheduler.Scheduler) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Queues(reactor.util.concurrent.Queues) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Schedulers(reactor.core.scheduler.Schedulers) Before(org.junit.Before) Test(org.junit.Test) Objects(java.util.Objects) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Queue(java.util.Queue) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 38 with AssertSubscriber

use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.

the class FluxExpandTest method depthCancelRace2.

@Test
public void depthCancelRace2() throws Exception {
    for (int i = 0; i < 1000; i++) {
        final TestPublisher<Integer> pp = TestPublisher.create();
        Flux<Integer> source = Flux.just(0).expandDeep(it -> pp);
        final CountDownLatch cdl = new CountDownLatch(1);
        AssertSubscriber<Integer> ts = new AssertSubscriber<Integer>() {

            final AtomicInteger sync = new AtomicInteger(2);

            @Override
            public void onNext(Integer t) {
                super.onNext(t);
                Schedulers.single().schedule(() -> {
                    if (sync.decrementAndGet() != 0) {
                        while (sync.get() != 0) {
                        }
                    }
                    cancel();
                    cdl.countDown();
                });
                if (sync.decrementAndGet() != 0) {
                    while (sync.get() != 0) {
                    }
                }
            }
        };
        source.subscribe(ts);
        assertThat(cdl.await(5, TimeUnit.SECONDS)).as("runs under 5s").isTrue();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 39 with AssertSubscriber

use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.

the class FluxUsingTest method resourceThrowsEager.

@Test
public void resourceThrowsEager() {
    AssertSubscriber<Object> ts = AssertSubscriber.create();
    AtomicInteger cleanup = new AtomicInteger();
    Flux.using(() -> {
        throw new RuntimeException("forced failure");
    }, r -> Flux.range(1, 10), cleanup::set, false).subscribe(ts);
    ts.assertNoValues().assertNotComplete().assertError(RuntimeException.class).assertErrorMessage("forced failure");
    Assert.assertEquals(0, cleanup.get());
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest) Mockito(org.mockito.Mockito) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) Fuseable(reactor.core.Fuseable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Condition(org.assertj.core.api.Condition) Assertions(org.assertj.core.api.Assertions) MockUtils(reactor.test.MockUtils) Assert(org.junit.Assert) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Example 40 with AssertSubscriber

use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.

the class FluxUsingTest method checkCleanupExecutionTime.

void checkCleanupExecutionTime(boolean eager, boolean fail) {
    AtomicInteger cleanup = new AtomicInteger();
    AtomicBoolean before = new AtomicBoolean();
    AssertSubscriber<Integer> ts = new AssertSubscriber<Integer>() {

        @Override
        public void onError(Throwable t) {
            super.onError(t);
            before.set(cleanup.get() != 0);
        }

        @Override
        public void onComplete() {
            super.onComplete();
            before.set(cleanup.get() != 0);
        }
    };
    Flux.using(() -> 1, r -> {
        if (fail) {
            return Flux.error(new RuntimeException("forced failure"));
        }
        return Flux.range(r, 10);
    }, cleanup::set, eager).subscribe(ts);
    if (fail) {
        ts.assertNoValues().assertError(RuntimeException.class).assertNotComplete().assertErrorMessage("forced failure");
    } else {
        ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).assertComplete().assertNoError();
    }
    Assert.assertEquals(1, cleanup.get());
    Assert.assertEquals(eager, before.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest) Mockito(org.mockito.Mockito) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) Fuseable(reactor.core.Fuseable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Condition(org.assertj.core.api.Condition) Assertions(org.assertj.core.api.Assertions) MockUtils(reactor.test.MockUtils) Assert(org.junit.Assert) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertSubscriber(reactor.test.subscriber.AssertSubscriber)

Aggregations

Test (org.junit.Test)65 AssertSubscriber (reactor.test.subscriber.AssertSubscriber)65 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)52 StepVerifier (reactor.test.StepVerifier)51 List (java.util.List)49 CoreSubscriber (reactor.core.CoreSubscriber)46 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)44 Assert (org.junit.Assert)43 Scannable (reactor.core.Scannable)41 Arrays (java.util.Arrays)40 Subscription (org.reactivestreams.Subscription)37 ArrayList (java.util.ArrayList)33 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)33 Schedulers (reactor.core.scheduler.Schedulers)32 AtomicReference (java.util.concurrent.atomic.AtomicReference)27 Duration (java.time.Duration)21 Fuseable (reactor.core.Fuseable)21 FluxOperatorTest (reactor.test.publisher.FluxOperatorTest)20 Exceptions (reactor.core.Exceptions)19 Queues (reactor.util.concurrent.Queues)19