use of reactor.core.scheduler.BoundedElasticScheduler.BoundedScheduledExecutorService in project reactor-core by reactor.
the class BoundedElasticSchedulerTest method toStringOfExecutorReflectsIdleVsActive.
@Test
public void toStringOfExecutorReflectsIdleVsActive() throws InterruptedException {
BoundedScheduledExecutorService bounded = new BoundedScheduledExecutorService(123, Thread::new);
BoundedScheduledExecutorService unbounded = new BoundedScheduledExecutorService(Integer.MAX_VALUE, Thread::new);
try {
bounded.submit(ThrowingRunnable.unchecked(() -> Thread.sleep(1000)));
unbounded.submit(ThrowingRunnable.unchecked(() -> Thread.sleep(1000)));
// give a small window for the task to be picked from the queue to reflect active
Thread.sleep(10);
assertThat(bounded).hasToString("BoundedScheduledExecutorService{ACTIVE, queued=0/123, completed=0}");
assertThat(unbounded).hasToString("BoundedScheduledExecutorService{ACTIVE, queued=0/unbounded, completed=0}");
} finally {
bounded.shutdownNow();
unbounded.shutdownNow();
}
}
use of reactor.core.scheduler.BoundedElasticScheduler.BoundedScheduledExecutorService in project reactor-core by reactor.
the class BoundedElasticSchedulerTest method toStringOfExecutorReflectsBoundedVsUnboundedAndCompletedVsQueued.
@Test
public void toStringOfExecutorReflectsBoundedVsUnboundedAndCompletedVsQueued() throws InterruptedException {
BoundedScheduledExecutorService bounded = new BoundedScheduledExecutorService(123, Thread::new);
BoundedScheduledExecutorService unbounded = new BoundedScheduledExecutorService(Integer.MAX_VALUE, Thread::new);
try {
bounded.submit(() -> {
});
unbounded.submit(() -> {
});
bounded.schedule(() -> {
}, 100, TimeUnit.MILLISECONDS);
unbounded.schedule(() -> {
}, 100, TimeUnit.MILLISECONDS);
// give a small window for the task to be picked from the queue and completed
Thread.sleep(10);
assertThat(bounded).hasToString("BoundedScheduledExecutorService{IDLE, queued=1/123, completed=1}");
assertThat(unbounded).hasToString("BoundedScheduledExecutorService{IDLE, queued=1/unbounded, completed=1}");
} finally {
bounded.shutdownNow();
unbounded.shutdownNow();
}
}
Aggregations