Search in sources :

Example 1 with CachedThreadScheduler

use of rx.internal.schedulers.CachedThreadScheduler in project rxrabbit by meltwater.

the class RxRabbitTests method consumer_closes_internal_subscriber_on_error_during_connection.

@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));
}
Also used : CachedThreadScheduler(rx.internal.schedulers.CachedThreadScheduler) Scheduler(rx.Scheduler) CachedThreadScheduler(rx.internal.schedulers.CachedThreadScheduler) CountDownLatch(java.util.concurrent.CountDownLatch) Subscription(rx.Subscription) MonitoringTestThreadFactory(com.meltwater.rxrabbit.util.MonitoringTestThreadFactory) Test(org.junit.Test)

Aggregations

MonitoringTestThreadFactory (com.meltwater.rxrabbit.util.MonitoringTestThreadFactory)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1 Scheduler (rx.Scheduler)1 Subscription (rx.Subscription)1 CachedThreadScheduler (rx.internal.schedulers.CachedThreadScheduler)1