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

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

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

Flowable.error介绍

[英]Returns a Flowable that invokes a Subscriber's Subscriber#onError method when the Subscriber subscribes to it.

Backpressure: This source doesn't produce any elements and effectively ignores downstream backpressure. Scheduler: error does not operate by default on a particular Scheduler.
[中]返回一个Flowable,当订阅者订阅它时,它调用订阅者的订阅者#onError方法。
背压:该源不产生任何元素,有效地忽略了下游背压。计划程序:默认情况下,错误不会在特定计划程序上运行。

代码示例

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

  1. @Test
  2. public void testCountError() {
  3. Flowable<String> f = Flowable.error(new Callable<Throwable>() {
  4. @Override
  5. public Throwable call() {
  6. return new RuntimeException();
  7. }
  8. });
  9. f.count().subscribe(wo);
  10. verify(wo, never()).onSuccess(anyInt());
  11. verify(wo, times(1)).onError(any(RuntimeException.class));
  12. }

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

  1. @Test(expected = NullPointerException.class)
  2. public void testForEachWithNull() {
  3. Flowable.error(new Exception("boo"))
  4. //
  5. .forEach(null);
  6. }

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

  1. @Test(timeout = 2000)
  2. public void testRepeatError() {
  3. Subscriber<Object> subscriber = TestHelper.mockSubscriber();
  4. Flowable.error(new TestException()).repeat(10).subscribe(subscriber);
  5. verify(subscriber).onError(any(TestException.class));
  6. verify(subscriber, never()).onNext(any());
  7. verify(subscriber, never()).onComplete();
  8. }

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

  1. @Test
  2. public void testSkipError() {
  3. Exception e = new Exception();
  4. Flowable<String> ok = Flowable.just("one");
  5. Flowable<String> error = Flowable.error(e);
  6. Flowable<String> skip = Flowable.concat(ok, error).skip(100);
  7. Subscriber<String> subscriber = TestHelper.mockSubscriber();
  8. skip.subscribe(subscriber);
  9. verify(subscriber, never()).onNext(any(String.class));
  10. verify(subscriber, times(1)).onError(e);
  11. verify(subscriber, never()).onComplete();
  12. }

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

  1. @Test(/* timeout = 1000, */expected = RuntimeException.class)
  2. public void testHasNextThrows() {
  3. TestScheduler scheduler = new TestScheduler();
  4. Flowable<Long> source = Flowable.<Long> error(new RuntimeException("Forced failure!")).subscribeOn(scheduler);
  5. Iterable<Long> iter = source.blockingLatest();
  6. Iterator<Long> it = iter.iterator();
  7. scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  8. it.hasNext();
  9. }

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

  1. @Test
  2. public void testAssertError() {
  3. RuntimeException e = new RuntimeException("Oops");
  4. TestSubscriber<Object> subscriber = new TestSubscriber<Object>();
  5. Flowable.error(e).subscribe(subscriber);
  6. subscriber.assertError(e);
  7. }

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

  1. @Test(timeout = 5000, expected = TestException.class)
  2. public void concatObservableError() {
  3. Completable c = Completable.concat(Flowable.<Completable>error(new Callable<Throwable>() {
  4. @Override
  5. public Throwable call() {
  6. return new TestException();
  7. }
  8. }));
  9. c.blockingAwait();
  10. }

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

  1. @Test(timeout = 5000, expected = TestException.class)
  2. public void mergeObservableError() {
  3. Completable c = Completable.merge(Flowable.<Completable>error(new Callable<Throwable>() {
  4. @Override
  5. public Throwable call() {
  6. return new TestException();
  7. }
  8. }));
  9. c.blockingAwait();
  10. }

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

  1. @Test(timeout = 5000, expected = TestException.class)
  2. public void mergeDelayErrorObservableError() {
  3. Completable c = Completable.mergeDelayError(Flowable.<Completable>error(new Callable<Throwable>() {
  4. @Override
  5. public Throwable call() {
  6. return new TestException();
  7. }
  8. }));
  9. c.blockingAwait();
  10. }

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

  1. @Test
  2. public void flowableBoundedBlockingSubscribe1() {
  3. Flowable.error(new TestException())
  4. .blockingSubscribe(Functions.emptyConsumer(), 128);
  5. }

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

  1. @Test
  2. public void testWithError3() {
  3. Single<Boolean> single = Flowable.sequenceEqual(
  4. Flowable.concat(Flowable.just("one"),
  5. Flowable.<String> error(new TestException())),
  6. Flowable.concat(Flowable.just("one"),
  7. Flowable.<String> error(new TestException())));
  8. verifyError(single);
  9. }

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

  1. @Test
  2. public void error() {
  3. Flowable.error(new TestException())
  4. .throttleLatest(1, TimeUnit.MINUTES)
  5. .test()
  6. .assertFailure(TestException.class);
  7. }

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

  1. @Test
  2. public void error() {
  3. Flowable.error(new TestException())
  4. .takeLast(5)
  5. .test()
  6. .assertFailure(TestException.class);
  7. }

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

  1. @Test
  2. public void fromFlowableError() {
  3. Flowable.error(new TestException())
  4. .singleElement()
  5. .test()
  6. .assertFailure(TestException.class);
  7. }

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

  1. @Test
  2. public void error() {
  3. Flowable.error(new TestException())
  4. .skipWhile(Functions.alwaysFalse())
  5. .test()
  6. .assertFailure(TestException.class);
  7. }
  8. }

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

  1. @Test
  2. public void dontRetry() {
  3. Flowable.error(new TestException("Outer"))
  4. .retry(Functions.alwaysFalse())
  5. .test()
  6. .assertFailureAndMessage(TestException.class, "Outer");
  7. }

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

  1. @Test
  2. public void mainError() {
  3. Flowable.error(new TestException())
  4. .window(Functions.justCallable(Flowable.never()))
  5. .test()
  6. .assertError(TestException.class);
  7. }

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

  1. @Test
  2. public void boundaryOnError() {
  3. TestSubscriber<Object> ts = Flowable.error(new TestException())
  4. .window(Flowable.never())
  5. .flatMap(Functions.<Flowable<Object>>identity(), true)
  6. .test()
  7. .assertFailure(CompositeException.class);
  8. List<Throwable> errors = TestHelper.compositeList(ts.errors().get(0));
  9. TestHelper.assertError(errors, 0, TestException.class);
  10. }

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

  1. @Test(timeout = 5000)
  2. public void startWithFlowableError() {
  3. Flowable<Object> c = normal.completable
  4. .startWith(Flowable.error(new TestException()));
  5. TestSubscriber<Object> ts = new TestSubscriber<Object>();
  6. c.subscribe(ts);
  7. normal.assertSubscriptions(0);
  8. ts.assertNoValues();
  9. ts.assertError(TestException.class);
  10. ts.assertNotComplete();
  11. }

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

  1. @Test
  2. public void boundaryError() {
  3. BehaviorProcessor.createDefault(1)
  4. .window(Functions.justCallable(Flowable.error(new TestException())))
  5. .test()
  6. .assertValueCount(1)
  7. .assertNotComplete()
  8. .assertError(TestException.class);
  9. }

相关文章

Flowable类方法