Search in sources :

Example 31 with AssertSubscriber

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

the class FluxGroupByTest method twoGroupsConsumeWithSubscribePrefetchBigger.

@Test
public void twoGroupsConsumeWithSubscribePrefetchBigger() {
    ForkJoinPool forkJoinPool = new ForkJoinPool();
    AssertSubscriber<Integer> ts1 = AssertSubscriber.create();
    AssertSubscriber<Integer> ts2 = AssertSubscriber.create();
    AssertSubscriber<Integer> ts3 = AssertSubscriber.create();
    ts3.onSubscribe(Operators.emptySubscription());
    Flux.range(0, 1_000_000).groupBy(v -> v & 1).subscribe(new CoreSubscriber<GroupedFlux<Integer, Integer>>() {

        @Override
        public void onSubscribe(Subscription s) {
            s.request(Long.MAX_VALUE);
        }

        @Override
        public void onNext(GroupedFlux<Integer, Integer> t) {
            if (t.key() == 0) {
                t.publishOn(Schedulers.fromExecutorService(forkJoinPool), 1024).subscribe(ts1);
            } else {
                t.publishOn(Schedulers.fromExecutorService(forkJoinPool), 1024).subscribe(ts2);
            }
        }

        @Override
        public void onError(Throwable t) {
            ts3.onError(t);
        }

        @Override
        public void onComplete() {
            ts3.onComplete();
        }
    });
    if (!ts1.await(Duration.ofSeconds(5)).isTerminated()) {
        Assert.fail("main subscriber timed out");
    }
    if (!ts2.await(Duration.ofSeconds(5)).isTerminated()) {
        Assert.fail("group 0 subscriber timed out");
    }
    if (!ts3.await(Duration.ofSeconds(5)).isTerminated()) {
        Assert.fail("group 1 subscriber timed out");
    }
    ts1.assertValueCount(500_000).assertNoError().assertComplete();
    ts2.assertValueCount(500_000).assertNoError().assertComplete();
    ts3.assertNoValues().assertNoError().assertComplete();
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest) Queues(reactor.util.concurrent.Queues) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) Fuseable(reactor.core.Fuseable) Ignore(org.junit.Ignore) ForkJoinPool(java.util.concurrent.ForkJoinPool) Duration(java.time.Duration) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Assert(org.junit.Assert) Subscription(org.reactivestreams.Subscription) ForkJoinPool(java.util.concurrent.ForkJoinPool) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Example 32 with AssertSubscriber

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

the class FluxGroupByTest method twoGroupsFullAsyncFullHide.

@Test
@Ignore("temporarily disabled, see gh-1028")
public void twoGroupsFullAsyncFullHide() {
    ForkJoinPool forkJoinPool = new ForkJoinPool();
    AssertSubscriber<Integer> ts1 = AssertSubscriber.create();
    AssertSubscriber<Integer> ts2 = AssertSubscriber.create();
    AssertSubscriber<Integer> ts3 = AssertSubscriber.create();
    ts3.onSubscribe(Operators.emptySubscription());
    Flux.range(0, 1_000_000).hide().publishOn(Schedulers.fromExecutorService(forkJoinPool)).groupBy(v -> v & 1).subscribe(new CoreSubscriber<GroupedFlux<Integer, Integer>>() {

        @Override
        public void onSubscribe(Subscription s) {
            s.request(Long.MAX_VALUE);
        }

        @Override
        public void onNext(GroupedFlux<Integer, Integer> t) {
            if (t.key() == 0) {
                t.hide().publishOn(Schedulers.fromExecutorService(forkJoinPool)).subscribe(ts1);
            } else {
                t.hide().publishOn(Schedulers.fromExecutorService(forkJoinPool)).subscribe(ts2);
            }
        }

        @Override
        public void onError(Throwable t) {
            ts3.onError(t);
        }

        @Override
        public void onComplete() {
            ts3.onComplete();
        }
    });
    ts1.await(Duration.ofSeconds(5));
    ts2.await(Duration.ofSeconds(5));
    ts3.await(Duration.ofSeconds(5));
    ts1.assertValueCount(500_000).assertNoError().assertComplete();
    ts2.assertValueCount(500_000).assertNoError().assertComplete();
    ts3.assertNoValues().assertNoError().assertComplete();
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest) Queues(reactor.util.concurrent.Queues) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) Fuseable(reactor.core.Fuseable) Ignore(org.junit.Ignore) ForkJoinPool(java.util.concurrent.ForkJoinPool) Duration(java.time.Duration) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Assert(org.junit.Assert) Subscription(org.reactivestreams.Subscription) ForkJoinPool(java.util.concurrent.ForkJoinPool) Ignore(org.junit.Ignore) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Example 33 with AssertSubscriber

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

the class FluxGroupByTest method twoGroupsConsumeWithSubscribe.

@Test
public void twoGroupsConsumeWithSubscribe() {
    ForkJoinPool forkJoinPool = new ForkJoinPool();
    AssertSubscriber<Integer> ts1 = AssertSubscriber.create();
    AssertSubscriber<Integer> ts2 = AssertSubscriber.create();
    AssertSubscriber<Integer> ts3 = AssertSubscriber.create();
    ts3.onSubscribe(Operators.emptySubscription());
    Flux.range(0, 1_000_000).groupBy(v -> v & 1).subscribe(new CoreSubscriber<GroupedFlux<Integer, Integer>>() {

        @Override
        public void onSubscribe(Subscription s) {
            s.request(Long.MAX_VALUE);
        }

        @Override
        public void onNext(GroupedFlux<Integer, Integer> t) {
            if (t.key() == 0) {
                t.publishOn(Schedulers.fromExecutorService(forkJoinPool)).subscribe(ts1);
            } else {
                t.publishOn(Schedulers.fromExecutorService(forkJoinPool)).subscribe(ts2);
            }
        }

        @Override
        public void onError(Throwable t) {
            ts3.onError(t);
        }

        @Override
        public void onComplete() {
            ts3.onComplete();
        }
    });
    ts1.await(Duration.ofSeconds(5));
    ts2.await(Duration.ofSeconds(5));
    ts3.await(Duration.ofSeconds(5));
    ts1.assertValueCount(500_000).assertNoError().assertComplete();
    ts2.assertValueCount(500_000).assertNoError().assertComplete();
    ts3.assertNoValues().assertNoError().assertComplete();
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest) Queues(reactor.util.concurrent.Queues) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) Fuseable(reactor.core.Fuseable) Ignore(org.junit.Ignore) ForkJoinPool(java.util.concurrent.ForkJoinPool) Duration(java.time.Duration) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Assert(org.junit.Assert) Subscription(org.reactivestreams.Subscription) ForkJoinPool(java.util.concurrent.ForkJoinPool) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Example 34 with AssertSubscriber

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

the class FluxGroupByTest method twoGroupsConsumeWithSubscribeHide.

@Test
public void twoGroupsConsumeWithSubscribeHide() {
    ForkJoinPool forkJoinPool = new ForkJoinPool();
    AssertSubscriber<Integer> ts1 = AssertSubscriber.create();
    AssertSubscriber<Integer> ts2 = AssertSubscriber.create();
    AssertSubscriber<Integer> ts3 = AssertSubscriber.create();
    ts3.onSubscribe(Operators.emptySubscription());
    Flux.range(0, 1_000_000).groupBy(v -> v & 1).subscribe(new CoreSubscriber<GroupedFlux<Integer, Integer>>() {

        @Override
        public void onSubscribe(Subscription s) {
            s.request(Long.MAX_VALUE);
        }

        @Override
        public void onNext(GroupedFlux<Integer, Integer> t) {
            if (t.key() == 0) {
                t.hide().publishOn(Schedulers.fromExecutorService(forkJoinPool)).subscribe(ts1);
            } else {
                t.hide().publishOn(Schedulers.fromExecutorService(forkJoinPool)).subscribe(ts2);
            }
        }

        @Override
        public void onError(Throwable t) {
            ts3.onError(t);
        }

        @Override
        public void onComplete() {
            ts3.onComplete();
        }
    });
    ts1.await(Duration.ofSeconds(5));
    ts2.await(Duration.ofSeconds(5));
    ts3.await(Duration.ofSeconds(5));
    ts1.assertValueCount(500_000).assertNoError().assertComplete();
    ts2.assertValueCount(500_000).assertNoError().assertComplete();
    ts3.assertNoValues().assertNoError().assertComplete();
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest) Queues(reactor.util.concurrent.Queues) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) Fuseable(reactor.core.Fuseable) Ignore(org.junit.Ignore) ForkJoinPool(java.util.concurrent.ForkJoinPool) Duration(java.time.Duration) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Assert(org.junit.Assert) Subscription(org.reactivestreams.Subscription) ForkJoinPool(java.util.concurrent.ForkJoinPool) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Example 35 with AssertSubscriber

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

the class FluxGroupByTest method twoGroupsLongAsyncMergeHidden.

@Test
public void twoGroupsLongAsyncMergeHidden() {
    ForkJoinPool forkJoinPool = new ForkJoinPool();
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    Flux.range(1, 1_000_000).groupBy(v -> (v & 1)).flatMap(g -> g.hide()).publishOn(Schedulers.fromExecutorService(forkJoinPool)).subscribe(ts);
    ts.await(Duration.ofSeconds(5));
    ts.assertValueCount(1_000_000).assertNoError().assertComplete();
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest) Queues(reactor.util.concurrent.Queues) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) Fuseable(reactor.core.Fuseable) Ignore(org.junit.Ignore) ForkJoinPool(java.util.concurrent.ForkJoinPool) Duration(java.time.Duration) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Assert(org.junit.Assert) ForkJoinPool(java.util.concurrent.ForkJoinPool) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

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