Search in sources :

Example 11 with Worker

use of reactor.core.scheduler.Scheduler.Worker in project reactor-core by reactor.

the class ImmediateSchedulerTest method scanWorker.

@Test
public void scanWorker() {
    Worker worker = Schedulers.immediate().createWorker();
    Scannable s = (Scannable) worker;
    assertThat(s.scan(Scannable.Attr.TERMINATED)).isFalse();
    assertThat(s.scan(Scannable.Attr.CANCELLED)).isFalse();
    assertThat(s.scan(Scannable.Attr.NAME)).isEqualTo(Schedulers.IMMEDIATE + ".worker");
    worker.dispose();
    assertThat(s.scan(Scannable.Attr.TERMINATED)).isTrue();
    assertThat(s.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : Worker(reactor.core.scheduler.Scheduler.Worker) Scannable(reactor.core.Scannable) Test(org.junit.Test)

Example 12 with Worker

use of reactor.core.scheduler.Scheduler.Worker in project reactor-core by reactor.

the class ImmediateSchedulerTest method directAndWorkerTimeSchedulingRejected.

@Test
public void directAndWorkerTimeSchedulingRejected() {
    Scheduler scheduler = scheduler();
    Worker worker = scheduler.createWorker();
    try {
        assertThatExceptionOfType(RejectedExecutionException.class).isThrownBy(() -> scheduler.schedule(() -> {
        }, 100, TimeUnit.MILLISECONDS)).isSameAs(Exceptions.failWithRejectedNotTimeCapable());
        assertThatExceptionOfType(RejectedExecutionException.class).isThrownBy(() -> scheduler.schedulePeriodically(() -> {
        }, 100, 100, TimeUnit.MILLISECONDS)).isSameAs(Exceptions.failWithRejectedNotTimeCapable());
        assertThatExceptionOfType(RejectedExecutionException.class).isThrownBy(() -> worker.schedule(() -> {
        }, 100, TimeUnit.MILLISECONDS)).isSameAs(Exceptions.failWithRejectedNotTimeCapable());
        assertThatExceptionOfType(RejectedExecutionException.class).isThrownBy(() -> worker.schedulePeriodically(() -> {
        }, 100, 100, TimeUnit.MILLISECONDS)).isSameAs(Exceptions.failWithRejectedNotTimeCapable());
    } finally {
        worker.dispose();
    }
}
Also used : Worker(reactor.core.scheduler.Scheduler.Worker) Test(org.junit.Test)

Aggregations

Worker (reactor.core.scheduler.Scheduler.Worker)12 Test (org.junit.Test)6 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)4 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CoreSubscriber (reactor.core.CoreSubscriber)1 Disposable (reactor.core.Disposable)1 Scannable (reactor.core.Scannable)1 Scheduler (reactor.core.scheduler.Scheduler)1