Search in sources :

Example 11 with AssertSubscriber

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

the class ParallelReduceSeedTest method collectAsync3.

@Test
public void collectAsync3() {
    Scheduler s = Schedulers.newParallel("test", 3);
    Supplier<List<Integer>> as = () -> new ArrayList<>();
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    Flux.range(1, 100000).hide().publishOn(s).parallel(3).runOn(s).filter(t -> true).collect(as, (a, b) -> a.add(b)).doOnNext(v -> System.out.println(v.size())).groups().flatMap(v -> v).reduce(0, (a, b) -> b.size() + a).subscribe(ts);
    ts.await(Duration.ofSeconds(5));
    ts.assertValues(100_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) Scheduler(reactor.core.scheduler.Scheduler) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest) Duration(java.time.Duration) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Scheduler(reactor.core.scheduler.Scheduler) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest)

Example 12 with AssertSubscriber

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

the class ParallelReduceSeedTest method collectAsyncFused.

@Test
public void collectAsyncFused() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    Scheduler scheduler = Schedulers.newParallel("test", 3);
    Flux.range(1, 100000).parallel(3).runOn(scheduler).collect(ArrayList::new, ArrayList::add).sequential().reduce(0, (a, b) -> a + b.size()).subscribe(ts);
    ts.await(Duration.ofSeconds(5));
    ts.assertValues(100_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) Scheduler(reactor.core.scheduler.Scheduler) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest) Duration(java.time.Duration) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Scheduler(reactor.core.scheduler.Scheduler) Test(org.junit.Test) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest)

Example 13 with AssertSubscriber

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

the class ParallelReduceSeedTest method collectAsync3Fused.

@Test
public void collectAsync3Fused() {
    Scheduler s = Schedulers.newParallel("test", 3);
    Supplier<List<Integer>> as = () -> new ArrayList<>();
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    Flux.range(1, 100000).publishOn(s).parallel(3).runOn(s).collect(as, (a, b) -> a.add(b)).doOnNext(v -> System.out.println(v.size())).groups().flatMap(v -> v).reduce(0, (a, b) -> b.size() + a).subscribe(ts);
    ts.await(Duration.ofSeconds(5));
    ts.assertValues(100_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) Scheduler(reactor.core.scheduler.Scheduler) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest) Duration(java.time.Duration) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Scheduler(reactor.core.scheduler.Scheduler) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest)

Example 14 with AssertSubscriber

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

the class ParallelReduceSeedTest method collectAsync.

@Test
public void collectAsync() {
    Scheduler s = Schedulers.newParallel("test", 3);
    Supplier<List<Integer>> as = () -> new ArrayList<>();
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    Flux.range(1, 100000).hide().parallel(3).runOn(s).collect(as, (a, b) -> a.add(b)).doOnNext(v -> System.out.println(v.size())).sequential().reduce(0, (a, b) -> a + b.size()).subscribe(ts);
    ts.await(Duration.ofSeconds(5));
    ts.assertValues(100_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) Scheduler(reactor.core.scheduler.Scheduler) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest) Duration(java.time.Duration) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Scheduler(reactor.core.scheduler.Scheduler) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest)

Example 15 with AssertSubscriber

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

the class ParallelReduceSeedTest method collectAsync2.

@Test
public void collectAsync2() {
    Scheduler s = Schedulers.newParallel("test", 3);
    Supplier<List<Integer>> as = () -> new ArrayList<>();
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    Flux.range(1, 100000).hide().publishOn(s).parallel(3).runOn(s).hide().collect(as, (a, b) -> a.add(b)).doOnNext(v -> System.out.println(v.size())).sequential().reduce(0, (a, b) -> a + b.size()).subscribe(ts);
    ts.await(Duration.ofSeconds(5));
    ts.assertValues(100_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) Scheduler(reactor.core.scheduler.Scheduler) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest) Duration(java.time.Duration) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Scheduler(reactor.core.scheduler.Scheduler) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest)

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