rx.plugins.RxJavaPlugins Java Examples
The following examples show how to use
rx.plugins.RxJavaPlugins.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RxSchedulersOverrideRule.java From Stock-Hawk with Apache License 2.0 | 6 votes |
@Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { RxAndroidPlugins.getInstance().reset(); RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook); RxJavaPlugins.getInstance().reset(); RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook); base.evaluate(); RxAndroidPlugins.getInstance().reset(); RxJavaPlugins.getInstance().reset(); } }; }
Example #2
Source File: SleuthRxJavaSchedulersHook.java From spring-cloud-sleuth with Apache License 2.0 | 6 votes |
SleuthRxJavaSchedulersHook(Tracer tracer, List<String> threadsToSample) { this.tracer = tracer; this.threadsToSample = threadsToSample; try { this.delegate = RxJavaPlugins.getInstance().getSchedulersHook(); if (this.delegate instanceof SleuthRxJavaSchedulersHook) { return; } RxJavaErrorHandler errorHandler = RxJavaPlugins.getInstance() .getErrorHandler(); RxJavaObservableExecutionHook observableExecutionHook = RxJavaPlugins .getInstance().getObservableExecutionHook(); logCurrentStateOfRxJavaPlugins(errorHandler, observableExecutionHook); RxJavaPlugins.getInstance().reset(); RxJavaPlugins.getInstance().registerSchedulersHook(this); RxJavaPlugins.getInstance().registerErrorHandler(errorHandler); RxJavaPlugins.getInstance() .registerObservableExecutionHook(observableExecutionHook); } catch (Exception ex) { log.error("Failed to register Sleuth RxJava SchedulersHook", ex); } }
Example #3
Source File: RxSchedulersOverrideRule.java From Hews with MIT License | 6 votes |
@Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { RxAndroidPlugins.getInstance().reset(); RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook); RxJavaPlugins.getInstance().reset(); RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook); base.evaluate(); RxAndroidPlugins.getInstance().reset(); RxJavaPlugins.getInstance().reset(); } }; }
Example #4
Source File: SleuthRxJavaSchedulersHookTests.java From spring-cloud-sleuth with Apache License 2.0 | 6 votes |
@Test public void should_wrap_delegates_action_in_wrapped_action_when_delegate_is_present_on_schedule() { RxJavaPlugins.getInstance().registerSchedulersHook(new MyRxJavaSchedulersHook()); SleuthRxJavaSchedulersHook schedulersHook = new SleuthRxJavaSchedulersHook( this.tracer, this.threadsToIgnore); Action0 action = schedulersHook.onSchedule(() -> { caller = new StringBuilder("hello"); }); action.call(); then(action).isInstanceOf(SleuthRxJavaSchedulersHook.TraceAction.class); then(caller.toString()).isEqualTo("called_from_schedulers_hook"); then(this.spans).isNotEmpty(); then(this.tracer.currentSpan()).isNull(); }
Example #5
Source File: RxUnitTestTools.java From fingerpoetry-android with Apache License 2.0 | 6 votes |
/** * 把异步变成同步,方便测试 */ public static void openRxTools() { if (isInitRxTools) { return; } isInitRxTools = true; RxAndroidSchedulersHook rxAndroidSchedulersHook = new RxAndroidSchedulersHook() { @Override public Scheduler getMainThreadScheduler() { return Schedulers.immediate(); } }; RxJavaSchedulersHook rxJavaSchedulersHook = new RxJavaSchedulersHook() { @Override public Scheduler getIOScheduler() { return Schedulers.immediate(); } }; RxAndroidPlugins.getInstance().registerSchedulersHook(rxAndroidSchedulersHook); RxJavaPlugins.getInstance().registerSchedulersHook(rxJavaSchedulersHook); }
Example #6
Source File: SleuthRxJavaSchedulersHookTests.java From spring-cloud-sleuth with Apache License 2.0 | 6 votes |
@Test public void should_not_create_a_span_when_current_thread_should_be_ignored() throws ExecutionException, InterruptedException { String threadNameToIgnore = "^MyCustomThread.*$"; RxJavaPlugins.getInstance().registerSchedulersHook(new MyRxJavaSchedulersHook()); SleuthRxJavaSchedulersHook schedulersHook = new SleuthRxJavaSchedulersHook( this.tracer, Collections.singletonList(threadNameToIgnore)); Future<Void> hello = executorService().submit((Callable<Void>) () -> { Action0 action = schedulersHook.onSchedule(() -> { caller = new StringBuilder("hello"); }); action.call(); return null; }); hello.get(); then(this.spans).isEmpty(); then(this.tracer.currentSpan()).isNull(); }
Example #7
Source File: RxSchedulersOverrideRule.java From FriendlyDemo with Apache License 2.0 | 6 votes |
@Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { RxAndroidPlugins.getInstance().reset(); RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook); callResetViaReflectionIn(RxJavaPlugins.getInstance()); RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook); base.evaluate(); RxAndroidPlugins.getInstance().reset(); callResetViaReflectionIn(RxJavaPlugins.getInstance()); } }; }
Example #8
Source File: RxSchedulersOverrideRule.java From ribot-app-android with Apache License 2.0 | 6 votes |
@Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { RxAndroidPlugins.getInstance().reset(); RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook); callResetViaReflectionIn(RxJavaPlugins.getInstance()); RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook); base.evaluate(); RxAndroidPlugins.getInstance().reset(); callResetViaReflectionIn(RxJavaPlugins.getInstance()); } }; }
Example #9
Source File: RxJavaResetRule.java From android with Apache License 2.0 | 6 votes |
@Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { //before: plugins reset, execution and schedulers hook defined RxJavaPlugins.getInstance().reset(); RxJavaPlugins.getInstance().registerSchedulersHook(new SchedulerHook()); RxAndroidPlugins.getInstance().reset(); RxAndroidPlugins.getInstance().registerSchedulersHook(new AndroidSchedulersHook()); base.evaluate(); //after: clean up RxJavaPlugins.getInstance().reset(); RxAndroidPlugins.getInstance().reset(); } }; }
Example #10
Source File: RepositoriesPresenterTest.java From Moxy with MIT License | 6 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); presenter = new RepositoriesPresenter(); presenter.setViewState(repositoriesViewState); RxJavaPlugins.getInstance().reset(); RxJavaPlugins.getInstance().registerSchedulersHook(new RxJavaSchedulersHook() { @Override public Scheduler getIOScheduler() { return Schedulers.immediate(); } }); RxAndroidPlugins.getInstance().reset(); RxAndroidPlugins.getInstance().registerSchedulersHook(new RxAndroidSchedulersHook() { @Override public Scheduler getMainThreadScheduler() { return Schedulers.immediate(); } }); }
Example #11
Source File: SignInPresenterTest.java From Moxy with MIT License | 6 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); presenter = new SignInPresenter(); presenter.setViewState(signInViewState); RxJavaPlugins.getInstance().reset(); RxJavaPlugins.getInstance().registerSchedulersHook(new RxJavaSchedulersHook() { @Override public Scheduler getIOScheduler() { return Schedulers.immediate(); } }); RxAndroidPlugins.getInstance().reset(); RxAndroidPlugins.getInstance().registerSchedulersHook(new RxAndroidSchedulersHook() { @Override public Scheduler getMainThreadScheduler() { return Schedulers.immediate(); } }); }
Example #12
Source File: API.java From ADP with MIT License | 6 votes |
private API(String baseUrl, String token) { this.token = token; this.baseUrl = baseUrl; RestAdapter restAdapter = buildRestAdapter(baseUrl, token); endpoints = restAdapter.create(Endpoints.class); if(RxJavaPlugins.getInstance().getErrorHandler() == null) RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() { @Override public void handleError(Throwable e) { Log.w(RxJavaErrorHandler.class.getSimpleName(), e); super.handleError(e); } }); }
Example #13
Source File: RxSchedulersOverrideRule.java From programming with GNU General Public License v3.0 | 6 votes |
@Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { RxAndroidPlugins.getInstance().reset(); RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook); RxJavaPlugins.getInstance().reset(); RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook); base.evaluate(); RxAndroidPlugins.getInstance().reset(); RxJavaPlugins.getInstance().reset(); } }; }
Example #14
Source File: RxUtils.java From fingerpoetry-android with Apache License 2.0 | 5 votes |
/** * 自定义处理 Rx 错误线程 */ public static void unifiedErrorHandler() { RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() { @Override public void handleError(Throwable e) { Timber.e(e.toString()); } }); }
Example #15
Source File: RxAndroidJUnitRunner.java From ribot-app-android with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle arguments) { super.onCreate(arguments); RxIdlingResource rxIdlingResource = new RxIdlingResource(); RxJavaPlugins.getInstance() .registerObservableExecutionHook(new RxIdlingExecutionHook(rxIdlingResource)); Espresso.registerIdlingResources(rxIdlingResource); }
Example #16
Source File: SleuthRxJavaSchedulersHookTests.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@Test public void should_not_override_existing_custom_hooks() { RxJavaPlugins.getInstance().registerErrorHandler(new MyRxJavaErrorHandler()); RxJavaPlugins.getInstance() .registerObservableExecutionHook(new MyRxJavaObservableExecutionHook()); new SleuthRxJavaSchedulersHook(this.tracer, this.threadsToIgnore); then(RxJavaPlugins.getInstance().getErrorHandler()) .isExactlyInstanceOf(MyRxJavaErrorHandler.class); then(RxJavaPlugins.getInstance().getObservableExecutionHook()) .isExactlyInstanceOf(MyRxJavaObservableExecutionHook.class); }
Example #17
Source File: SchedulerTest.java From vertx-rx with Apache License 2.0 | 5 votes |
@Override protected void tearDown() throws Exception { workerExecutor.close(); super.tearDown(); // Cleanup any RxJavaPlugins installed // Needs to hack a bit since we are not in the same package Method meth = RxJavaPlugins.class.getDeclaredMethod("reset"); meth.setAccessible(true); meth.invoke(RxJavaPlugins.getInstance()); }
Example #18
Source File: SchedulerTest.java From vertx-rx with Apache License 2.0 | 5 votes |
private void testSchedulerHook(Supplier<ContextScheduler> scheduler) throws Exception { RxJavaPlugins plugins = RxJavaPlugins.getInstance(); AtomicInteger scheduled = new AtomicInteger(); AtomicInteger called = new AtomicInteger(); CountDownLatch latchCalled = new CountDownLatch(1); plugins.registerSchedulersHook(new RxJavaSchedulersHook() { @Override public Action0 onSchedule(Action0 action) { scheduled.incrementAndGet(); return () -> { action.call(); called.getAndIncrement(); latchCalled.countDown(); }; } }); ContextScheduler scheduler2 = scheduler.get(); Scheduler.Worker worker = scheduler2.createWorker(); assertEquals(0, scheduled.get()); assertEquals(0, called.get()); CountDownLatch latch = new CountDownLatch(1); AtomicInteger workerScheduledVal = new AtomicInteger(); AtomicInteger workerCalledVal = new AtomicInteger(); worker.schedule(() -> { workerScheduledVal.set(scheduled.get()); workerCalledVal.set(called.get()); latch.countDown(); }, 0, SECONDS); awaitLatch(latch); awaitLatch(latchCalled); assertEquals(1, scheduled.get()); assertEquals(1, called.get()); assertEquals(1, workerScheduledVal.get()); assertEquals(0, workerCalledVal.get()); }
Example #19
Source File: OperatorDebounce.java From RxDebounceClick with MIT License | 5 votes |
@Override public void onError(Throwable e) { RxJavaPlugins.getInstance() .getErrorHandler() .handleError(e); child.onError(e); }
Example #20
Source File: NewsModuleApiImplTest.java From ZZShow with Apache License 2.0 | 5 votes |
@Test public void testLoadNews() throws Exception { System.out.println("-- 1.testLoadNews --"); // 让Schedulers.io()返回当前线程 RxJavaPlugins.getInstance().registerSchedulersHook(new RxJavaSchedulersHook() { @Override public Scheduler getIOScheduler() { return Schedulers.immediate(); } }); moduleApi.loadNews(new RequestCallBack<List<NewsSummary>>() { @Override public void beforeRequest() { } @Override public void success(List<NewsSummary> data) { } @Override public void onError(String errorMsg) { } }, ApiConstants.NETEASE_TYPE_OTHER, ApiConstants.NETEASE_ID_GAME, 0); assertEquals(1,1); }
Example #21
Source File: RxAndroidJUnitRunner.java From Stock-Hawk with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle arguments) { super.onCreate(arguments); RxIdlingResource rxIdlingResource = new RxIdlingResource(); RxJavaPlugins.getInstance() .registerObservableExecutionHook(new RxIdlingExecutionHook(rxIdlingResource)); Espresso.registerIdlingResources(rxIdlingResource); }
Example #22
Source File: BaseUnitTest.java From programming with GNU General Public License v3.0 | 5 votes |
private void startMocks(){ MockitoAnnotations.initMocks(this); PowerMockito.mockStatic(Log.class); RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() { @Override public void handleError(Throwable e) { e.printStackTrace(); } }); }
Example #23
Source File: LooperScheduler.java From letv with Apache License 2.0 | 5 votes |
public void run() { try { this.action.call(); } catch (Throwable e) { IllegalStateException ie; if (e instanceof OnErrorNotImplementedException) { ie = new IllegalStateException("Exception thrown on Scheduler.Worker thread. Add `onError` handling.", e); } else { ie = new IllegalStateException("Fatal Exception thrown on Scheduler.Worker thread.", e); } RxJavaPlugins.getInstance().getErrorHandler().handleError(ie); Thread thread = Thread.currentThread(); thread.getUncaughtExceptionHandler().uncaughtException(thread, ie); } }
Example #24
Source File: SleuthRxJavaSchedulersHookTests.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
@BeforeEach @AfterEach public void setup() { RxJavaPlugins.getInstance().reset(); caller = new StringBuilder(); }
Example #25
Source File: OperatorOnErrorResumeNextViaFunction.java From mantis with Apache License 2.0 | 4 votes |
@Override public Subscriber<? super T> call(final Subscriber<? super T> child) { Subscriber<T> parent = new Subscriber<T>() { private boolean done = false; @Override public void onCompleted() { if (done) { return; } done = true; child.onCompleted(); } @Override public void onError(Throwable e) { if (done) { Exceptions.throwIfFatal(e); return; } done = true; try { RxJavaPlugins.getInstance().getErrorHandler().handleError(e); unsubscribe(); Observable<? extends T> resume = resumeFunction.call(e); resume.unsafeSubscribe(child); } catch (Throwable e2) { child.onError(e2); } } @Override public void onNext(T t) { if (done) { return; } child.onNext(t); } @Override public void setProducer(final Producer producer) { child.setProducer(new Producer() { @Override public void request(long n) { producer.request(n); } }); } }; child.add(parent); return parent; }
Example #26
Source File: SleuthRxJavaTests.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
@BeforeAll @AfterAll public static void cleanUp() { RxJavaPlugins.getInstance().reset(); }
Example #27
Source File: RxSchedulersOverrideRule.java From FriendlyDemo with Apache License 2.0 | 4 votes |
private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset"); method.setAccessible(true); method.invoke(rxJavaPlugins); }
Example #28
Source File: RxSchedulersOverrideRule.java From ribot-app-android with Apache License 2.0 | 4 votes |
private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset"); method.setAccessible(true); method.invoke(rxJavaPlugins); }
Example #29
Source File: OperatorOnErrorResumeNextViaObservable.java From mantis with Apache License 2.0 | 4 votes |
@Override public Subscriber<? super T> call(final Subscriber<? super T> child) { // shared subscription won't work here Subscriber<T> s = new Subscriber<T>() { private boolean done = false; @Override public void onNext(T t) { if (done) { return; } child.onNext(t); } @Override public void onError(Throwable e) { if (done) { Exceptions.throwIfFatal(e); return; } done = true; RxJavaPlugins.getInstance().getErrorHandler().handleError(e); unsubscribe(); resumeSequence.unsafeSubscribe(child); } @Override public void onCompleted() { if (done) { return; } done = true; child.onCompleted(); } @Override public void setProducer(final Producer producer) { child.setProducer(new Producer() { @Override public void request(long n) { producer.request(n); } }); } }; child.add(s); return s; }