Java Code Examples for io.reactivex.plugins.RxJavaPlugins#setComputationSchedulerHandler()

The following examples show how to use io.reactivex.plugins.RxJavaPlugins#setComputationSchedulerHandler() . 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: CoreConnectionManagerTest.java    From RxCentralBle with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
  MockitoAnnotations.initMocks(this);

  RxJavaPlugins.setComputationSchedulerHandler(schedulerCallable -> testScheduler);

  when(scanner.scan()).thenReturn(scanDataPublishSubject.hide());
  when(bluetoothDetector.enabled()).thenReturn(bluetoothEnabledRelay.hide());
  when(peripheralFactory.produce(any(), any())).thenReturn(peripheral);
  when(peripheral.connect()).thenReturn(connectableStatePublishSubject.hide());
  when(scanData.getBluetoothDevice()).thenReturn(bluetoothDevice);

  coreConnectionManager =
      new CoreConnectionManager(
          context, bluetoothDetector, scanner, peripheralFactory);
}
 
Example 2
Source File: RxJavaHooksUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenComputationScheduler_whenCalled_shouldExecuteTheHooks() {

    RxJavaPlugins.setInitComputationSchedulerHandler((scheduler) -> {
        initHookCalled = true;
        return scheduler.call();
    });
    RxJavaPlugins.setComputationSchedulerHandler((scheduler) -> {
        hookCalled = true;
        return scheduler;
    });

    Observable.range(1, 10)
        .map(v -> v * 2)
        .subscribeOn(Schedulers.computation())
        .test();
    assertTrue(hookCalled && initHookCalled);
}
 
Example 3
Source File: RxSchedulerRule.java    From MovieGuide with MIT License 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxAndroidPlugins.reset();
            RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerFunctionLazy);

            RxJavaPlugins.reset();
            RxJavaPlugins.setIoSchedulerHandler(schedulerFunction);
            RxJavaPlugins.setNewThreadSchedulerHandler(schedulerFunction);
            RxJavaPlugins.setComputationSchedulerHandler(schedulerFunction);

            base.evaluate();

            RxAndroidPlugins.reset();
            RxJavaPlugins.reset();
        }
    };
}
 
Example 4
Source File: TestSchedulerRule.java    From resilience4j with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement statement, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxJavaPlugins.setIoSchedulerHandler(scheduler -> testScheduler);
            RxJavaPlugins.setComputationSchedulerHandler(scheduler -> testScheduler);
            RxJavaPlugins.setNewThreadSchedulerHandler(scheduler -> testScheduler);
            try {
                statement.evaluate();
            } finally {
                RxJavaPlugins.reset();
            }
        }
    };
}
 
Example 5
Source File: TestComponentRule.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxAndroidPlugins.reset();
            RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerMapperLazy);

            RxJavaPlugins.reset();
            RxJavaPlugins.setIoSchedulerHandler(schedulerMapper);
            RxJavaPlugins.setNewThreadSchedulerHandler(schedulerMapper);
            RxJavaPlugins.setComputationSchedulerHandler(schedulerMapper);

            TavernaApplication application = TavernaApplication.get(mContext);
            application.setComponent(mTestComponent);

            base.evaluate();
            application.setComponent(null);
            RxAndroidPlugins.reset();
            RxJavaPlugins.reset();
        }
    };
}
 
Example 6
Source File: RxSchedulersOverrideRule.java    From mvvm-template with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxAndroidPlugins.reset();
            RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> Schedulers.trampoline());

            RxJavaPlugins.reset();
            RxJavaPlugins.setIoSchedulerHandler(scheduler -> Schedulers.trampoline());
            RxJavaPlugins.setComputationSchedulerHandler(scheduler -> Schedulers.trampoline());
            RxJavaPlugins.setNewThreadSchedulerHandler(scheduler -> Schedulers.trampoline());

            base.evaluate();

            RxAndroidPlugins.reset();
            RxJavaPlugins.reset();
        }
    };
}
 
Example 7
Source File: RxJavaTestSchedulerRule.java    From JReadHub with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxJavaPlugins.setIoSchedulerHandler(scheduler -> mTestScheduler);
            RxJavaPlugins.setComputationSchedulerHandler(scheduler -> mTestScheduler);
            RxJavaPlugins.setNewThreadSchedulerHandler(scheduler -> mTestScheduler);
            RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> mTestScheduler);

            try {
                base.evaluate();
            } finally {
                RxJavaPlugins.reset();
                RxAndroidPlugins.reset();
            }
        }
    };
}
 
Example 8
Source File: ThrottledLollipopScannerTest.java    From RxCentralBle with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
  MockitoAnnotations.initMocks(this);

  RxJavaPlugins.setComputationSchedulerHandler(schedulerCallable -> testScheduler);

  mockStatic(BluetoothAdapter.class);

  when(bluetoothAdapter.getBluetoothLeScanner()).thenReturn(bluetoothLeScanner);
  when(adDataFactory.produce(any())).thenReturn(parsedAdvertisement);
  when(scanResult.getDevice()).thenReturn(bluetoothDevice);
  when(scanResult.getScanRecord()).thenReturn(scanRecord);
  when(scanRecord.getBytes()).thenReturn(new byte[] {0x00});
  when(scanResult.getRssi()).thenReturn(0);

  scanner = new ThrottledLollipopScanner();
}
 
Example 9
Source File: RxJavaTestSchedulerRule.java    From Awesome-WanAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxJavaPlugins.setIoSchedulerHandler(scheduler -> mTestScheduler);
            RxJavaPlugins.setComputationSchedulerHandler(scheduler -> mTestScheduler);
            RxJavaPlugins.setNewThreadSchedulerHandler(scheduler -> mTestScheduler);
            RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> mTestScheduler);

            try {
                base.evaluate();
            } finally {
                RxJavaPlugins.reset();
                RxAndroidPlugins.reset();
            }
        }
    };
}
 
Example 10
Source File: ReadTest.java    From RxCentralBle with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  MockitoAnnotations.initMocks(this);

  RxJavaPlugins.setComputationSchedulerHandler(schedulerCallable -> testScheduler);

  when(peripheral.read(any(), any())).thenReturn(readOperationSingle);

  read = new Read(svcUuid, chrUuid, 5000);
  readResultTestObserver = read.result().test();
}
 
Example 11
Source File: WriteTest.java    From RxCentralBle with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  MockitoAnnotations.initMocks(this);

  RxJavaPlugins.setComputationSchedulerHandler(schedulerCallable -> testScheduler);

  when(peripheral.write(any(), any(), any())).thenReturn(writeCompletable);
}
 
Example 12
Source File: RequestMtuTest.java    From RxCentralBle with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  MockitoAnnotations.initMocks(this);

  RxJavaPlugins.setComputationSchedulerHandler(schedulerCallable -> testScheduler);

  when(peripheral.requestMtu(anyInt())).thenReturn(readOperationSingle);

  requestMtu = new RequestMtu(100, 5000);
  readResultTestObserver = requestMtu.result().test();
}
 
Example 13
Source File: ThreadHelper.java    From AndroidGodEye with Apache License 2.0 5 votes vote down vote up
public static void setupRxjava() {
    TestScheduler testScheduler = new TestScheduler();
    RxJavaPlugins.setComputationSchedulerHandler(new Function<Scheduler, Scheduler>() {
        @Override
        public Scheduler apply(Scheduler scheduler) throws Exception {
            return testScheduler;
        }
    });
}
 
Example 14
Source File: RegisterNotificationTest.java    From RxCentralBle with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  MockitoAnnotations.initMocks(this);

  RxJavaPlugins.setComputationSchedulerHandler(schedulerCallable -> testScheduler);

  when(peripheral.registerNotification(any(), any(), any())).thenReturn(registerCompletable);

  registerNotification = new RegisterNotification(svcUuid, chrUuid, 5000);
  registerResultTestObserver = registerNotification.result().test();
}
 
Example 15
Source File: ReadRssiTest.java    From RxCentralBle with Apache License 2.0 5 votes vote down vote up
@Before
public void before() {
  MockitoAnnotations.initMocks(this);

  RxJavaPlugins.setComputationSchedulerHandler(schedulerCallable -> testScheduler);

  when(peripheral.readRssi()).thenReturn(readOperationSingle);

  readRssi = new ReadRssi(5000);
  readResultTestObserver = readRssi.result().test();
}
 
Example 16
Source File: RssiScanMatcherTest.java    From RxCentralBle with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  MockitoAnnotations.initMocks(this);

  RxJavaPlugins.setComputationSchedulerHandler(schedulerCallable -> testScheduler);

  when(scanData1.getBluetoothDevice()).thenReturn(bluetoothDevice1);
  when(scanData2.getBluetoothDevice()).thenReturn(bluetoothDevice2);

  when(bluetoothDevice1.getAddress()).thenReturn("bluetoothDevice1");
  when(bluetoothDevice2.getAddress()).thenReturn("bluetoothDevice2");

  rssiScanMatcher = new RssiScanMatcher(serviceScanMatcher);
}
 
Example 17
Source File: ThreadHelper.java    From AndroidGodEye with Apache License 2.0 4 votes vote down vote up
public static void teardownRxjava() {
    RxJavaPlugins.setComputationSchedulerHandler(null);
}
 
Example 18
Source File: NativeExamples.java    From vertx-rx with Apache License 2.0 4 votes vote down vote up
public void schedulerHook(Vertx vertx) {
  RxJavaPlugins.setComputationSchedulerHandler(s -> RxHelper.scheduler(vertx));
  RxJavaPlugins.setIoSchedulerHandler(s -> RxHelper.blockingScheduler(vertx));
  RxJavaPlugins.setNewThreadSchedulerHandler(s -> RxHelper.scheduler(vertx));
}
 
Example 19
Source File: RxifiedExamples.java    From vertx-rx with Apache License 2.0 4 votes vote down vote up
public void schedulerHook(Vertx vertx) {
  RxJavaPlugins.setComputationSchedulerHandler(s -> RxHelper.scheduler(vertx));
  RxJavaPlugins.setIoSchedulerHandler(s -> RxHelper.blockingScheduler(vertx));
  RxJavaPlugins.setNewThreadSchedulerHandler(s -> RxHelper.scheduler(vertx));
}