コード例 #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 zipFastSlow() {
   Queue q = new Queue();
   LazyReact.parallelBuilder()
       .reactInfinitely(() -> sleep(100))
       .then(it -> q.add("100"))
       .runThread(new Thread());
   parallel(1, 2, 3, 4, 5, 6)
       .zip(q.stream())
       .peek(it -> System.out.println(it))
       .collect(Collectors.toList());
 }
コード例 #3
0
 @Test
 public void streamFromQueue() {
   assertThat(
       LazyReact.sequentialBuilder()
           .reactInfinitely(() -> "100")
           .limit(100)
           .withQueueFactory(QueueFactories.boundedQueue(10))
           .toQueue()
           .stream()
           .collect(Collectors.toList())
           .size(),
       equalTo(100));
 }
コード例 #4
0
 @Test
 public void reactInfinitely() {
   assertThat(
       LazyReact.sequentialBuilder().reactInfinitely(() -> "100").limit(100).toList().size(),
       equalTo(100));
 }