io.reactivex.Flowable.rangeLong()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(4.9k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中io.reactivex.Flowable.rangeLong()方法的一些代码示例,展示了Flowable.rangeLong()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.rangeLong()方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称:Flowable
方法名:rangeLong

Flowable.rangeLong介绍

[英]Returns a Flowable that emits a sequence of Longs within a specified range.

Backpressure: The operator honors backpressure from downstream and signals values on-demand (i.e., when requested). Scheduler: rangeLong does not operate by default on a particular Scheduler.
[中]返回在指定范围内发出长序列的可流动数据。
背压:操作员接受来自下游的背压,并按需(即,当要求时)发送信号。调度程序:默认情况下,rangeLong不会在特定调度程序上运行。

代码示例

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testRangeWithZero() {
  Flowable.rangeLong(1, 0);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testRangeWithOverflow2() {
  Flowable.rangeLong(Long.MAX_VALUE, 0);
}

代码示例来源:origin: ReactiveX/RxJava

@Override
  public Publisher<Long> createPublisher(long elements) {
    return
      Flowable.rangeLong(1, elements)
      .mergeWith(Completable.complete())
    ;
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Override
  public Publisher<Long> createPublisher(long elements) {
    return
      Flowable.rangeLong(1, elements)
      .mergeWith(Maybe.<Long>empty())
    ;
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testRangeStartAt2Count3() {
  Subscriber<Long> subscriber = TestHelper.mockSubscriber();
  Flowable.rangeLong(2, 3).subscribe(subscriber);
  verify(subscriber, times(1)).onNext(2L);
  verify(subscriber, times(1)).onNext(3L);
  verify(subscriber, times(1)).onNext(4L);
  verify(subscriber, never()).onNext(5L);
  verify(subscriber, never()).onError(any(Throwable.class));
  verify(subscriber, times(1)).onComplete();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void negativeCount() {
  try {
    Flowable.rangeLong(1L, -1L);
    fail("Should have thrown IllegalArgumentException");
  } catch (IllegalArgumentException ex) {
    assertEquals("count >= 0 required but it was -1", ex.getMessage());
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void badRequest() {
  TestHelper.assertBadRequestReported(Flowable.rangeLong(1L, 5L));
  TestHelper.assertBadRequestReported(Flowable.rangeLong(1L, 5L).filter(Functions.alwaysTrue()));
}

代码示例来源:origin: ReactiveX/RxJava

@Override
  public Publisher<Long> createPublisher(long elements) {
    if (elements == 0) {
      return Flowable.empty();
    }
    return
      Flowable.rangeLong(1, elements - 1)
      .mergeWith(Single.just(elements))
    ;
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void countOne() {
  Flowable.rangeLong(5495454L, 1L)
    .test()
    .assertResult(5495454L);
}

代码示例来源:origin: ReactiveX/RxJava

void testWithBackpressureAllAtOnce(long start) {
  Flowable<Long> source = Flowable.rangeLong(start, 100);
  TestSubscriber<Long> ts = new TestSubscriber<Long>(0L);
  ts.request(100);
  source.subscribe(ts);
  List<Long> list = new ArrayList<Long>(100);
  for (long i = 0; i < 100; i++) {
    list.add(i + start);
  }
  ts.assertValueSequence(list);
  ts.assertTerminated();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void slowPathRebatch() {
  Flowable.rangeLong(1L, 5L)
  .rebatchRequests(1)
  .test()
  .assertResult(1L, 2L, 3L, 4L, 5L);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void conditionalNormal() {
  Flowable.rangeLong(1L, 5L)
  .filter(Functions.alwaysTrue())
  .test()
  .assertResult(1L, 2L, 3L, 4L, 5L);
}

代码示例来源:origin: ReactiveX/RxJava

@Override
  public Publisher<Long> createPublisher(long elements) {
    if (elements == 0) {
      return Flowable.<Long>empty()
          .mergeWith(Maybe.<Long>empty());
    }
    return
      Flowable.rangeLong(1, elements - 1)
      .mergeWith(Maybe.just(elements))
    ;
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void fused() {
  TestSubscriber<Long> ts = SubscriberFusion.newTest(QueueFuseable.ANY);
  Flowable.rangeLong(1, 2).subscribe(ts);
  SubscriberFusion.assertFusion(ts, QueueFuseable.SYNC)
  .assertResult(1L, 2L);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void fusedReject() {
  TestSubscriber<Long> ts = SubscriberFusion.newTest(QueueFuseable.ASYNC);
  Flowable.rangeLong(1, 2).subscribe(ts);
  SubscriberFusion.assertFusion(ts, QueueFuseable.NONE)
  .assertResult(1L, 2L);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void conditionalNormalSlowpath() {
  Flowable.rangeLong(1L, 5L)
  .filter(Functions.alwaysTrue())
  .test(5)
  .assertResult(1L, 2L, 3L, 4L, 5L);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void conditionalSlowPathRebatch() {
  Flowable.rangeLong(1L, 5L)
  .filter(Functions.alwaysTrue())
  .rebatchRequests(1)
  .test()
  .assertResult(1L, 2L, 3L, 4L, 5L);
}

代码示例来源:origin: ReactiveX/RxJava

@Test(timeout = 1000)
public void testNearMaxValueWithBackpressure() {
  TestSubscriber<Long> ts = new TestSubscriber<Long>(3L);
  Flowable.rangeLong(Long.MAX_VALUE - 1L, 2L).subscribe(ts);
  ts.assertComplete();
  ts.assertNoErrors();
  ts.assertValues(Long.MAX_VALUE - 1L, Long.MAX_VALUE);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void slowPathTakeExact() {
  Flowable.rangeLong(1L, 5L)
  .filter(Functions.alwaysTrue())
  .take(5)
  .test()
  .assertResult(1L, 2L, 3L, 4L, 5L);
}

代码示例来源:origin: ReactiveX/RxJava

@Test(timeout = 1000)
public void testNearMaxValueWithoutBackpressure() {
  TestSubscriber<Long> ts = new TestSubscriber<Long>();
  Flowable.rangeLong(Long.MAX_VALUE - 1L, 2L).subscribe(ts);
  ts.assertComplete();
  ts.assertNoErrors();
  ts.assertValues(Long.MAX_VALUE - 1L, Long.MAX_VALUE);
}

相关文章

Flowable类方法