Java Code Examples for rx.plugins.RxJavaHooks#setOnIOScheduler()

The following examples show how to use rx.plugins.RxJavaHooks#setOnIOScheduler() . 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: RxSchedulersTestRule.java    From AndroidSchool 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 {
            RxJavaHooks.reset();
            RxJavaHooks.setOnIOScheduler(mMockSchedulerFunc);
            RxJavaHooks.setOnNewThreadScheduler(mMockSchedulerFunc);

            RxAndroidPlugins.getInstance().reset();
            RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);

            base.evaluate();

            RxJavaHooks.reset();
            RxAndroidPlugins.getInstance().reset();
        }
    };
}
 
Example 2
Source File: RxRabbitTests.java    From rxrabbit with MIT License 6 votes vote down vote up
@Before
public void setup() throws Exception {
    dockerContainers.rabbit().assertUp();
    rabbitTcpPort = dockerContainers.rabbit().tcpPort();
    rabbitAdminPort = dockerContainers.rabbit().adminPort();
    log.infoWithParams("****** Rabbit broker is up and running *****");

    BrokerAddresses addresses = new BrokerAddresses("amqp://localhost:" + rabbitTcpPort);
    channelFactory = new DefaultChannelFactory(addresses, connectionSettings);
    consumerFactory = new DefaultConsumerFactory(channelFactory, consumeSettings);
    publisherFactory = new DefaultPublisherFactory(channelFactory, publishSettings);
    httpClient = new AsyncHttpClient();

    messagesSeen.clear();
    createQueues(channelFactory, inputQueue, new Exchange(inputExchange));
    publisher = publisherFactory.createPublisher();
    RxJavaHooks.setOnIOScheduler(null);
}
 
Example 3
Source File: UserActivityViewModelTest.java    From Anago with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    BaseActivity activity = Robolectric.setupActivity(UserActivity.class);

    // ユースケースのモック
    User user = new User();
    user.id = 1L;
    user.login = "user";
    GetUserUseCase getUserUseCase = mock(GetUserUseCase.class);
    when(getUserUseCase.run("user")).thenReturn(Single.just(user));
    when(getUserUseCase.run("wrong")).thenReturn(Single.error(new Throwable("error")));

    // イベントバスのモック
    eventBus = mock(EventBus.class);

    // ビューモデルの作成
    userViewModel = new UserActivityViewModel(activity, getUserUseCase, eventBus);

    // subscribeOnのスレッドをioからimmediateに変更
    RxJavaHooks.setOnIOScheduler(scheduler -> Schedulers.immediate());
}
 
Example 4
Source File: RunTestOnContextRx.java    From sfs with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
    Statement st = new Statement() {
        @Override
        public void evaluate() throws Throwable {
            Vertx v = vertx();
            RxJavaSchedulersHook hook = RxHelper.schedulerHook(v.getOrCreateContext());
            RxJavaHooks.setOnIOScheduler(f -> hook.getIOScheduler());
            RxJavaHooks.setOnNewThreadScheduler(f -> hook.getNewThreadScheduler());
            RxJavaHooks.setOnComputationScheduler(f -> hook.getComputationScheduler());
            base.evaluate();
        }
    };
    return super.apply(st, description);
}
 
Example 5
Source File: RxUtils.java    From AndroidSchool with Apache License 2.0 5 votes vote down vote up
public static void setupTestSchedulers() {
    try {
        RxJavaHooks.setOnIOScheduler(scheduler -> Schedulers.immediate());
        RxJavaHooks.setOnNewThreadScheduler(scheduler -> Schedulers.immediate());

        RxAndroidPlugins.getInstance().registerSchedulersHook(new RxAndroidSchedulersHook() {
            @Override
            public Scheduler getMainThreadScheduler() {
                return Schedulers.immediate();
            }
        });
    } catch (IllegalStateException ignored) {
    }
}
 
Example 6
Source File: RxJUnitRunner.java    From AndroidSchool with Apache License 2.0 5 votes vote down vote up
private void setupTestSchedulers() {
    RxJavaHooks.setOnIOScheduler(scheduler -> Schedulers.immediate());
    RxJavaHooks.setOnNewThreadScheduler(scheduler -> Schedulers.immediate());

    try {
        RxAndroidPlugins.getInstance().registerSchedulersHook(new RxAndroidSchedulersHook() {
            @Override
            public Scheduler getMainThreadScheduler() {
                return Schedulers.immediate();
            }
        });
    } catch (IllegalStateException ignored) {
        // already registered
    }
}
 
Example 7
Source File: RxRabbitTests.java    From rxrabbit with MIT License 5 votes vote down vote up
@Test
public void consumer_closes_internal_subscriber_on_error_during_connection() throws Exception {
    MonitoringTestThreadFactory threadFactory = new MonitoringTestThreadFactory();
    Scheduler threadPoolScheduler = new CachedThreadScheduler(threadFactory);
    RxJavaHooks.setOnIOScheduler((ioScheduler) -> threadPoolScheduler);

    CountDownLatch retries = new CountDownLatch(10);

    ConsumerSettings consumerSettings = new ConsumerSettings()
            .withRetryCount(ConsumerSettings.RETRY_FOREVER)
            .withNumChannels(1)
            .withPreFetchCount(1024)
            .withBackoffAlgorithm(integer -> {
                retries.countDown();
                return 1;
            });

    Observable<Message> consumer = new DefaultConsumerFactory(channelFactory, consumerSettings)
            .createConsumer("non-existent-queue");

    Subscription subscribe = consumer.subscribe();

    retries.await();
    subscribe.unsubscribe();

    assertThat(threadFactory.getAliveThreads(), lessThan(10));
}
 
Example 8
Source File: SfsServer.java    From sfs with Apache License 2.0 4 votes vote down vote up
public static void initRxSchedulers(Context context) {
    RxJavaSchedulersHook hook = RxHelper.schedulerHook(context);
    RxJavaHooks.setOnIOScheduler(f -> hook.getIOScheduler());
    RxJavaHooks.setOnNewThreadScheduler(f -> hook.getNewThreadScheduler());
    RxJavaHooks.setOnComputationScheduler(f -> hook.getComputationScheduler());
}
 
Example 9
Source File: NativeExamples.java    From vertx-rx with Apache License 2.0 4 votes vote down vote up
public void schedulerHook(Vertx vertx) {
  RxJavaSchedulersHook hook = RxHelper.schedulerHook(vertx);
  RxJavaHooks.setOnIOScheduler(f -> hook.getIOScheduler());
  RxJavaHooks.setOnNewThreadScheduler(f -> hook.getNewThreadScheduler());
  RxJavaHooks.setOnComputationScheduler(f -> hook.getComputationScheduler());
}
 
Example 10
Source File: RxifiedExamples.java    From vertx-rx with Apache License 2.0 4 votes vote down vote up
public void schedulerHook(Vertx vertx) {
  RxJavaSchedulersHook hook = io.vertx.rxjava.core.RxHelper.schedulerHook(vertx);
    RxJavaHooks.setOnIOScheduler(f -> hook.getIOScheduler());
    RxJavaHooks.setOnNewThreadScheduler(f -> hook.getNewThreadScheduler());
    RxJavaHooks.setOnComputationScheduler(f -> hook.getComputationScheduler());
}