java类io.reactivex.plugins.RxJavaPlugins的实例源码

ObservableTaskCallback.java 文件源码 项目:RxTask 阅读 30 收藏 0 点赞 0 评论 0
@Override
public void onComplete(@NonNull Task<Void> task) {
    if (isDisposed()) return;
    if (!task.isSuccessful()) {
        Exception exception = task.getException();
        if (terminated) {
            RxJavaPlugins.onError(exception);
        } else {
            try {
                terminated = true;
                observer.onError(exception);
            } catch (Throwable t) {
                Exceptions.throwIfFatal(t);
                RxJavaPlugins.onError(new CompositeException(task.getException(), t));
            }
        }
    }
}
HandlerScheduler.java 文件源码 项目:GitHub 阅读 29 收藏 0 点赞 0 评论 0
@Override
public Disposable schedule(Runnable run, long delay, TimeUnit unit) {
    if (run == null) throw new NullPointerException("run == null");
    if (unit == null) throw new NullPointerException("unit == null");

    if (disposed) {
        return Disposables.disposed();
    }

    run = RxJavaPlugins.onSchedule(run);

    ScheduledRunnable scheduled = new ScheduledRunnable(handler, run);

    Message message = Message.obtain(handler, scheduled);
    message.obj = this; // Used as token for batch disposal of this worker's runnables.

    handler.sendMessageDelayed(message, Math.max(0L, unit.toMillis(delay)));

    // Re-check disposed state for removing in case we were racing a call to dispose().
    if (disposed) {
        handler.removeCallbacks(scheduled);
        return Disposables.disposed();
    }

    return scheduled;
}
HandlerSchedulerTest.java 文件源码 项目:GitHub 阅读 29 收藏 0 点赞 0 评论 0
@Test
public void directScheduleOnceWithDelayUsesHook() {
    final CountingRunnable newCounter = new CountingRunnable();
    final AtomicReference<Runnable> runnableRef = new AtomicReference<>();
    RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {
        @Override public Runnable apply(Runnable runnable) {
            runnableRef.set(runnable);
            return newCounter;
        }
    });

    CountingRunnable counter = new CountingRunnable();
    scheduler.scheduleDirect(counter, 1, MINUTES);

    // Verify our runnable was passed to the schedulers hook.
    assertSame(counter, runnableRef.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    // Verify the scheduled runnable was the one returned from the hook.
    assertEquals(1, newCounter.get());
    assertEquals(0, counter.get());
}
HandlerSchedulerTest.java 文件源码 项目:GitHub 阅读 29 收藏 0 点赞 0 评论 0
@Test
public void workerScheduleOnceUsesHook() {
    final CountingRunnable newCounter = new CountingRunnable();
    final AtomicReference<Runnable> runnableRef = new AtomicReference<>();
    RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {
        @Override public Runnable apply(Runnable runnable) {
            runnableRef.set(runnable);
            return newCounter;
        }
    });

    Worker worker = scheduler.createWorker();

    CountingRunnable counter = new CountingRunnable();
    worker.schedule(counter);

    // Verify our runnable was passed to the schedulers hook.
    assertSame(counter, runnableRef.get());

    runUiThreadTasks();
    // Verify the scheduled runnable was the one returned from the hook.
    assertEquals(1, newCounter.get());
    assertEquals(0, counter.get());
}
HandlerSchedulerTest.java 文件源码 项目:GitHub 阅读 30 收藏 0 点赞 0 评论 0
@Test
public void workerScheduleOnceWithDelayUsesHook() {
    final CountingRunnable newCounter = new CountingRunnable();
    final AtomicReference<Runnable> runnableRef = new AtomicReference<>();
    RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {
        @Override public Runnable apply(Runnable runnable) {
            runnableRef.set(runnable);
            return newCounter;
        }
    });

    Worker worker = scheduler.createWorker();

    CountingRunnable counter = new CountingRunnable();
    worker.schedule(counter, 1, MINUTES);

    // Verify our runnable was passed to the schedulers hook.
    assertSame(counter, runnableRef.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    // Verify the scheduled runnable was the one returned from the hook.
    assertEquals(1, newCounter.get());
    assertEquals(0, counter.get());
}
AsyncSwingScheduler.java 文件源码 项目:RxJava2Swing 阅读 34 收藏 0 点赞 0 评论 0
@Override
public void run() {
    Runnable r = get();
    if (r != null && compareAndSet(r, null)) {
        try {
            try {
                r.run();
            } catch (Throwable ex) {
                Exceptions.throwIfFatal(ex);
                RxJavaPlugins.onError(ex);
            }
        } finally {
            remove(this);
        }
    }
}
CallEnqueueObservable.java 文件源码 项目:GitHub 阅读 37 收藏 0 点赞 0 评论 0
@Override public void onResponse(Call<T> call, Response<T> response) {
  if (call.isCanceled()) return;

  try {
    observer.onNext(response);

    if (!call.isCanceled()) {
      terminated = true;
      observer.onComplete();
    }
  } catch (Throwable t) {
    if (terminated) {
      RxJavaPlugins.onError(t);
    } else if (!call.isCanceled()) {
      try {
        observer.onError(t);
      } catch (Throwable inner) {
        Exceptions.throwIfFatal(inner);
        RxJavaPlugins.onError(new CompositeException(t, inner));
      }
    }
  }
}
AttachDisposableMaybe.java 文件源码 项目:DisposableAttach 阅读 35 收藏 0 点赞 0 评论 0
@Override
protected void subscribeActual(MaybeObserver<? super T> s) {
    MaybeObserver<? super T> observer;
    try {
        observer = ObjectHelper.requireNonNull(s, "Null Observer");
    } catch (Throwable e) {
        Exceptions.throwIfFatal(e);
        // can't call onError because no way to know if a Disposable has been set or not
        // can't call onSubscribe because the call might have set a Disposable already
        RxJavaPlugins.onError(e);

        NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");
        npe.initCause(e);
        throw npe;
    }

    source.subscribe(new AttachMaybeObserver<>(observer, this.compositeDisposable));
}
AttachDisposableSingle.java 文件源码 项目:DisposableAttach 阅读 29 收藏 0 点赞 0 评论 0
@Override
protected void subscribeActual(SingleObserver<? super T> s) {
    SingleObserver<? super T> observer;
    try {
        observer = ObjectHelper.requireNonNull(s, "Null Observer");
    } catch (Throwable e) {
        Exceptions.throwIfFatal(e);
        // can't call onError because no way to know if a Disposable has been set or not
        // can't call onSubscribe because the call might have set a Disposable already
        RxJavaPlugins.onError(e);

        NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");
        npe.initCause(e);
        throw npe;
    }

    source.subscribe(new AttachSingleObserver<>(observer, this.compositeDisposable));
}
MaybeThrowingTest.java 文件源码 项目:GitHub 阅读 40 收藏 0 点赞 0 评论 0
@Test public void responseThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingMaybeObserver<Response<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.response().subscribe(new ForwardingObserver<Response<String>>(observer) {
    @Override public void onSuccess(Response<String> value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
MaybeThrowingTest.java 文件源码 项目:GitHub 阅读 32 收藏 0 点赞 0 评论 0
@Test public void resultThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingMaybeObserver<Result<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.result().subscribe(new ForwardingObserver<Result<String>>(observer) {
    @Override public void onSuccess(Result<String> value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
CompletableThrowingTest.java 文件源码 项目:GitHub 阅读 27 收藏 0 点赞 0 评论 0
@Test public void throwingInOnCompleteDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> errorRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!errorRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable); // Don't swallow secondary errors!
      }
    }
  });

  RecordingCompletableObserver observer = observerRule.create();
  final RuntimeException e = new RuntimeException();
  service.completable().subscribe(new ForwardingCompletableObserver(observer) {
    @Override public void onComplete() {
      throw e;
    }
  });

  assertThat(errorRef.get()).isSameAs(e);
}
ObservableThrowingTest.java 文件源码 项目:GitHub 阅读 45 收藏 0 点赞 0 评论 0
@Test public void bodyThrowingInOnCompleteDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingObserver<String> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.body().subscribe(new ForwardingObserver<String>(observer) {
    @Override public void onComplete() {
      throw e;
    }
  });

  observer.assertAnyValue();
  assertThat(throwableRef.get()).isSameAs(e);

}
SingleThrowingTest.java 文件源码 项目:GitHub 阅读 41 收藏 0 点赞 0 评论 0
@Test public void bodyThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingSingleObserver<String> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.body().subscribe(new ForwardingObserver<String>(observer) {
    @Override public void onSuccess(String value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
SingleThrowingTest.java 文件源码 项目:GitHub 阅读 31 收藏 0 点赞 0 评论 0
@Test public void responseThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingSingleObserver<Response<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.response().subscribe(new ForwardingObserver<Response<String>>(observer) {
    @Override public void onSuccess(Response<String> value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
SingleThrowingTest.java 文件源码 项目:GitHub 阅读 32 收藏 0 点赞 0 评论 0
@Test public void resultThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingSingleObserver<Result<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.result().subscribe(new ForwardingObserver<Result<String>>(observer) {
    @Override public void onSuccess(Result<String> value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
FlowableThrowingTest.java 文件源码 项目:GitHub 阅读 28 收藏 0 点赞 0 评论 0
@Test public void bodyThrowingInOnCompleteDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingSubscriber<String> subscriber = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.body().subscribe(new ForwardingSubscriber<String>(subscriber) {
    @Override public void onComplete() {
      throw e;
    }
  });

  subscriber.assertAnyValue();
  assertThat(throwableRef.get()).isSameAs(e);

}
FlowableThrowingTest.java 文件源码 项目:GitHub 阅读 35 收藏 0 点赞 0 评论 0
@Test public void responseThrowingInOnCompleteDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingSubscriber<Response<String>> subscriber = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.response().subscribe(new ForwardingSubscriber<Response<String>>(subscriber) {
    @Override public void onComplete() {
      throw e;
    }
  });

  subscriber.assertAnyValue();
  assertThat(throwableRef.get()).isSameAs(e);
}
MaybeTaskCallback.java 文件源码 项目:RxTask 阅读 30 收藏 0 点赞 0 评论 0
@Override
public void onComplete(@NonNull Task<T> task) {
    if (isDisposed()) return;
    if (task.isSuccessful()) {
        T result = task.getResult();
        if (result == null) {
            observer.onComplete();
        } else {
            observer.onSuccess(result);
        }
    } else {
        try {
            observer.onError(task.getException());
        } catch (Throwable t) {
            Exceptions.throwIfFatal(t);
            RxJavaPlugins.onError(new CompositeException(task.getException(), t));
        }
    }
}
MaybeThrowingTest.java 文件源码 项目:GitHub 阅读 39 收藏 0 点赞 0 评论 0
@Test public void bodyThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingMaybeObserver<String> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.body().subscribe(new ForwardingObserver<String>(observer) {
    @Override public void onSuccess(String value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
MaybeThrowingTest.java 文件源码 项目:GitHub 阅读 35 收藏 0 点赞 0 评论 0
@Test public void responseThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingMaybeObserver<Response<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.response().subscribe(new ForwardingObserver<Response<String>>(observer) {
    @Override public void onSuccess(Response<String> value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
MaybeThrowingTest.java 文件源码 项目:GitHub 阅读 30 收藏 0 点赞 0 评论 0
@Test public void resultThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingMaybeObserver<Result<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.result().subscribe(new ForwardingObserver<Result<String>>(observer) {
    @Override public void onSuccess(Result<String> value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
CompletableThrowingTest.java 文件源码 项目:GitHub 阅读 25 收藏 0 点赞 0 评论 0
@Test public void throwingInOnCompleteDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> errorRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!errorRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable); // Don't swallow secondary errors!
      }
    }
  });

  RecordingCompletableObserver observer = observerRule.create();
  final RuntimeException e = new RuntimeException();
  service.completable().subscribe(new ForwardingCompletableObserver(observer) {
    @Override public void onComplete() {
      throw e;
    }
  });

  assertThat(errorRef.get()).isSameAs(e);
}
EclipseScheduler.java 文件源码 项目:RxSWT 阅读 31 收藏 0 点赞 0 评论 0
@Override
public Disposable schedule(Runnable run, long delay, TimeUnit unit) {
    if (run == null)
        throw new NullPointerException("run == null");
    if (unit == null)
        throw new NullPointerException("unit == null");

    if (disposed) {
        return Disposables.disposed();
    }

    run = RxJavaPlugins.onSchedule(run);

    ScheduledRunnable scheduled = new ScheduledRunnable(run);

    executeRunnable(title, delay, unit, scheduled);

    // Re-check disposed state for removing in case we were racing a
    // call to dispose().
    if (disposed) {
        return Disposables.disposed();
    }

    return scheduled;
}
ObservableThrowingTest.java 文件源码 项目:GitHub 阅读 34 收藏 0 点赞 0 评论 0
@Test public void responseThrowingInOnCompleteDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingObserver<Response<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.response().subscribe(new ForwardingObserver<Response<String>>(observer) {
    @Override public void onComplete() {
      throw e;
    }
  });

  observer.assertAnyValue();
  assertThat(throwableRef.get()).isSameAs(e);
}
ObservableThrowingTest.java 文件源码 项目:GitHub 阅读 31 收藏 0 点赞 0 评论 0
@Test public void resultThrowingInOnCompletedDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingObserver<Result<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.result().subscribe(new ForwardingObserver<Result<String>>(observer) {
    @Override public void onComplete() {
      throw e;
    }
  });

  observer.assertAnyValue();
  assertThat(throwableRef.get()).isSameAs(e);
}
AsyncTest.java 文件源码 项目:GitHub 阅读 33 收藏 0 点赞 0 评论 0
@Test public void throwingInOnCompleteDeliveredToPlugin() throws InterruptedException {
  server.enqueue(new MockResponse());

  final CountDownLatch latch = new CountDownLatch(1);
  final AtomicReference<Throwable> errorRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!errorRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable); // Don't swallow secondary errors!
      }
      latch.countDown();
    }
  });

  TestObserver<Void> observer = new TestObserver<>();
  final RuntimeException e = new RuntimeException();
  service.completable().subscribe(new ForwardingCompletableObserver(observer) {
    @Override public void onComplete() {
      throw e;
    }
  });

  latch.await(1, SECONDS);
  assertThat(errorRef.get()).isSameAs(e);
}
SingleThrowingTest.java 文件源码 项目:GitHub 阅读 39 收藏 0 点赞 0 评论 0
@Test public void responseThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingSingleObserver<Response<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.response().subscribe(new ForwardingObserver<Response<String>>(observer) {
    @Override public void onSuccess(Response<String> value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
SingleThrowingTest.java 文件源码 项目:GitHub 阅读 33 收藏 0 点赞 0 评论 0
@Test public void resultThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingSingleObserver<Result<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.result().subscribe(new ForwardingObserver<Result<String>>(observer) {
    @Override public void onSuccess(Result<String> value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
FlowableThrowingTest.java 文件源码 项目:GitHub 阅读 27 收藏 0 点赞 0 评论 0
@Test public void bodyThrowingInOnCompleteDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingSubscriber<String> subscriber = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.body().subscribe(new ForwardingSubscriber<String>(subscriber) {
    @Override public void onComplete() {
      throw e;
    }
  });

  subscriber.assertAnyValue();
  assertThat(throwableRef.get()).isSameAs(e);

}


问题


面经


文章

微信
公众号

扫码关注公众号