use of reactor.core.scheduler.BoundedElasticScheduler.BoundedServices in project reactor-core by reactor.
the class BoundedElasticSchedulerTest method restartSupported.
@Test
public void restartSupported() {
BoundedElasticScheduler s = scheduler();
s.dispose();
BoundedServices servicesBefore = s.boundedServices;
assertThat(servicesBefore).as("SHUTDOWN").isSameAs(BoundedElasticScheduler.SHUTDOWN);
s.start();
assertThat(s.boundedServices).isNotSameAs(servicesBefore).hasValue(0);
}
use of reactor.core.scheduler.BoundedElasticScheduler.BoundedServices in project reactor-core by reactor.
the class BoundedElasticSchedulerTest method startNoOpIfStarted.
@Test
public void startNoOpIfStarted() {
BoundedElasticScheduler s = scheduler();
// need a first call to `start()` after construction
BoundedServices servicesBefore = s.boundedServices;
s.start();
s.start();
s.start();
assertThat(s.boundedServices).isSameAs(servicesBefore);
}
use of reactor.core.scheduler.BoundedElasticScheduler.BoundedServices in project reactor-core by reactor.
the class BoundedElasticSchedulerTest method evictionForWorkerScheduling.
@Test
public void evictionForWorkerScheduling() {
MockUtils.VirtualClock clock = new MockUtils.VirtualClock(Instant.ofEpochMilli(1_000_000), ZoneId.systemDefault());
BoundedElasticScheduler s = afterTest.autoDispose(new BoundedElasticScheduler(2, Integer.MAX_VALUE, r -> new Thread(r, "eviction"), 60 * 1000, clock));
s.start();
BoundedServices services = s.boundedServices;
Worker worker1 = afterTest.autoDispose(s.createWorker());
assertThat(services).as("count worker 1").hasValue(1);
assertThat(s.estimateSize()).as("non null size before workers 2 and 3").isEqualTo(1);
Worker worker2 = afterTest.autoDispose(s.createWorker());
Worker worker3 = afterTest.autoDispose(s.createWorker());
assertThat(services).as("count worker 1 2 3").hasValue(2);
assertThat(s.estimateSize()).as("3 workers equals 2 executors").isEqualTo(2);
services.eviction();
assertThat(s.estimateIdle()).as("not idle yet").isZero();
clock.advanceTimeBy(Duration.ofMillis(1));
worker1.dispose();
worker2.dispose();
worker3.dispose();
clock.advanceTimeBy(Duration.ofMillis(10));
services.eviction();
assertThat(s.estimateIdle()).as("idle for 10 milliseconds").isEqualTo(2);
clock.advanceTimeBy(Duration.ofMinutes(1));
services.eviction();
assertThat(s.estimateIdle()).as("idle for 1 minute and 10ms").isEqualTo(s.estimateBusy()).isEqualTo(s.estimateSize()).isZero();
}
Aggregations