コード例 #1
0
  @Test
  public void testBackPressureWhenZippingUnevenStreams2() {

    Queue fast =
        LazyReact.parallelBuilder()
            .withExecutor(new ForkJoinPool(2))
            .reactInfinitely(() -> "100")
            .peek(System.out::println)
            .withQueueFactory(QueueFactories.boundedQueue(10))
            .toQueue();

    new Thread(
            () -> {
              LazyReact.parallelBuilder()
                  .withExecutor(new ForkJoinPool(2))
                  .range(0, 1000)
                  .peek(System.out::println)
                  .peek(c -> sleep(10))
                  .zip(fast.stream())
                  .forEach(it -> {});
            })
        .start();
    ;
    fast.setSizeSignal(Signal.queueBackedSignal());
    int max =
        fast.getSizeSignal()
            .getContinuous()
            .stream()
            .mapToInt(it -> (int) it)
            .limit(50)
            .max()
            .getAsInt();

    assertThat(max, lessThan(11));
  }
コード例 #2
0
 @Test
 public void streamFromQueue() {
   assertThat(
       LazyReact.sequentialBuilder()
           .reactInfinitely(() -> "100")
           .limit(100)
           .withQueueFactory(QueueFactories.boundedQueue(10))
           .toQueue()
           .stream()
           .collect(Collectors.toList())
           .size(),
       equalTo(100));
 }