Exemplo n.º 1
0
  @Test
  public void supplierReturnsNull() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();

    Flux.range(1, 10).<Integer>reduceWith(() -> null, (a, b) -> b).subscribe(ts);

    ts.assertNoValues().assertNotComplete().assertError(NullPointerException.class);
  }
Exemplo n.º 2
0
  @Test
  public void normal() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();

    Flux.range(1, 10).reduceWith(() -> 0, (a, b) -> b).subscribe(ts);

    ts.assertValues(10).assertComplete().assertNoError();
  }
Exemplo n.º 3
0
  @Test
  public void normal() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();

    Flux.range(1, 10).filter(v -> v % 2 == 0).subscribe(ts);

    ts.assertValues(2, 4, 6, 8, 10).assertComplete().assertNoError();
  }
Exemplo n.º 4
0
  @Test
  public void syncFusion() {
    AssertSubscriber<Object> ts = AssertSubscriber.create();

    Flux.range(1, 10).filter(v -> (v & 1) == 0).subscribe(ts);

    ts.assertValues(2, 4, 6, 8, 10).assertNoError().assertComplete();
  }
  @Test
  public void subsequentSum() {

    AssertSubscriber<Integer> ts = AssertSubscriber.create();

    range(1, 5)
        .publish(o -> zip((Object[] a) -> (Integer) a[0] + (Integer) a[1], o, o.skip(1)))
        .subscribe(ts);

    ts.assertValues(1 + 2, 2 + 3, 3 + 4, 4 + 5).assertNoError().assertComplete();
  }
Exemplo n.º 6
0
  @Test
  public void normalBackpressuredArray() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create(2);

    Flux.just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).filter(v -> v % 2 == 0).subscribe(ts);

    ts.assertValues(2, 4).assertNotComplete().assertNoError();

    ts.request(10);

    ts.assertValues(2, 4, 6, 8, 10).assertComplete().assertNoError();
  }
  @Test
  public void innerCanFuse() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    ts.requestedFusionMode(Fuseable.ANY);

    Flux.never().publish(o -> range(1, 5)).subscribe(ts);

    ts.assertFuseableSource()
        .assertFusionMode(Fuseable.SYNC)
        .assertValues(1, 2, 3, 4, 5)
        .assertComplete()
        .assertNoError();
  }
  @Test
  public void cancelComposes() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();

    EmitterProcessor<Integer> sp = EmitterProcessor.create();

    sp.publish(o -> Flux.<Integer>never()).subscribe(ts);

    Assert.assertTrue("Not subscribed?", sp.downstreamCount() != 0);

    ts.cancel();

    Assert.assertFalse("Still subscribed?", sp.downstreamCount() == 0);
  }
Exemplo n.º 9
0
  @Test
  public void asyncFusion() {
    AssertSubscriber<Object> ts = AssertSubscriber.create();

    UnicastProcessor<Integer> up = UnicastProcessor.create(new ConcurrentLinkedQueue<>());

    up.filter(v -> (v & 1) == 0).subscribe(ts);

    for (int i = 1; i < 11; i++) {
      up.onNext(i);
    }
    up.onComplete();

    ts.assertValues(2, 4, 6, 8, 10).assertNoError().assertComplete();
  }
Exemplo n.º 10
0
  @Test
  public void predicateThrows() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create(2);

    Flux.range(1, 10)
        .filter(
            v -> {
              throw new RuntimeException("forced failure");
            })
        .subscribe(ts);

    ts.assertNoValues()
        .assertNotComplete()
        .assertError(RuntimeException.class)
        .assertErrorMessage("forced failure");
  }
Exemplo n.º 11
0
  @Test
  public void accumulatorThrows() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();

    Flux.range(1, 10)
        .reduceWith(
            () -> 0,
            (a, b) -> {
              throw new RuntimeException("forced failure");
            })
        .subscribe(ts);

    ts.assertNoValues()
        .assertNotComplete()
        .assertError(RuntimeException.class)
        .assertErrorWith(e -> Assert.assertTrue(e.getMessage().contains("forced failure")));
  }
Exemplo n.º 12
0
  @Test
  public void asyncFusionBackpressured2() {
    AssertSubscriber<Object> ts = AssertSubscriber.create(1);

    UnicastProcessor<Integer> up = UnicastProcessor.create(new ConcurrentLinkedQueue<>());

    Flux.just(1).hide().flatMap(w -> up.filter(v -> (v & 1) == 0), false, 1, 1).subscribe(ts);

    up.onNext(1);
    up.onNext(2);

    ts.assertValues(2).assertNoError().assertNotComplete();

    up.onComplete();

    ts.assertValues(2).assertNoError().assertComplete();
  }
  @Test
  public void subsequentSumAsync() {

    AssertSubscriber<Integer> ts = AssertSubscriber.create();

    UnicastProcessor<Integer> up = UnicastProcessor.create(QueueSupplier.<Integer>get(16).get());

    up.publish(o -> zip((Object[] a) -> (Integer) a[0] + (Integer) a[1], o, o.skip(1)))
        .subscribe(ts);

    up.onNext(1);
    up.onNext(2);
    up.onNext(3);
    up.onNext(4);
    up.onNext(5);
    up.onComplete();

    ts.assertValues(1 + 2, 2 + 3, 3 + 4, 4 + 5).assertNoError().assertComplete();
  }
  @Test
  public void pairWise() {
    AssertSubscriber<Tuple2<Integer, Integer>> ts = AssertSubscriber.create();

    range(1, 9).transform(o -> zip(o, o.skip(1))).subscribe(ts);

    ts.assertValues(
            Tuples.of(1, 2),
            Tuples.of(2, 3),
            Tuples.of(3, 4),
            Tuples.of(4, 5),
            Tuples.of(5, 6),
            Tuples.of(6, 7),
            Tuples.of(7, 8),
            Tuples.of(8, 9))
        .assertComplete();
  }