Search in sources :

Example 1 with BoundedServices

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);
}
Also used : BoundedServices(reactor.core.scheduler.BoundedElasticScheduler.BoundedServices) Test(org.junit.jupiter.api.Test)

Example 2 with BoundedServices

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);
}
Also used : BoundedServices(reactor.core.scheduler.BoundedElasticScheduler.BoundedServices) Test(org.junit.jupiter.api.Test)

Example 3 with BoundedServices

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();
}
Also used : Offset(org.assertj.core.data.Offset) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) AfterAll(org.junit.jupiter.api.AfterAll) BoundedServices(reactor.core.scheduler.BoundedElasticScheduler.BoundedServices) Loggers(reactor.util.Loggers) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Logger(reactor.util.Logger) BoundedState(reactor.core.scheduler.BoundedElasticScheduler.BoundedState) Assertions(org.assertj.core.api.Assertions) Tag(org.junit.jupiter.api.Tag) Disposables(reactor.core.Disposables) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) Set(java.util.Set) Worker(reactor.core.scheduler.Scheduler.Worker) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Stream(java.util.stream.Stream) ThrowingSupplier(com.pivovarit.function.ThrowingSupplier) Awaitility(org.awaitility.Awaitility) CsvSource(org.junit.jupiter.params.provider.CsvSource) Disposable(reactor.core.Disposable) Scannable(reactor.core.Scannable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MonoSink(reactor.core.publisher.MonoSink) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ThrowingRunnable(com.pivovarit.function.ThrowingRunnable) MockUtils(reactor.test.MockUtils) LinkedList(java.util.LinkedList) RaceTestUtils(reactor.test.util.RaceTestUtils) ExecutorService(java.util.concurrent.ExecutorService) BoundedScheduledExecutorService(reactor.core.scheduler.BoundedElasticScheduler.BoundedScheduledExecutorService) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) Mono(reactor.core.publisher.Mono) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Flux(reactor.core.publisher.Flux) Clock(java.time.Clock) Comparator(java.util.Comparator) BoundedServices(reactor.core.scheduler.BoundedElasticScheduler.BoundedServices) Worker(reactor.core.scheduler.Scheduler.Worker) MockUtils(reactor.test.MockUtils) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 BoundedServices (reactor.core.scheduler.BoundedElasticScheduler.BoundedServices)3 ThrowingRunnable (com.pivovarit.function.ThrowingRunnable)1 ThrowingSupplier (com.pivovarit.function.ThrowingSupplier)1 Clock (java.time.Clock)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 ZoneId (java.time.ZoneId)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1