Search in sources :

Example 91 with Disposable

use of reactor.core.Disposable in project reactor-core by reactor.

the class SchedulersTest method testWorkerScheduleSupportZeroPeriodWithDelayPeriod.

@Test
public void testWorkerScheduleSupportZeroPeriodWithDelayPeriod() {
    try (TaskCheckingScheduledExecutor executorService = new TaskCheckingScheduledExecutor()) {
        Disposable.Composite tasks = Disposables.composite();
        Disposable disposable = Schedulers.workerSchedulePeriodically(executorService, tasks, () -> {
        }, 1000, 0, TimeUnit.MILLISECONDS);
        disposable.dispose();
        assertThat(executorService.isAllTasksCancelled()).isTrue();
    }
}
Also used : Disposable(reactor.core.Disposable) Test(org.junit.jupiter.api.Test)

Example 92 with Disposable

use of reactor.core.Disposable in project reactor-core by reactor.

the class SchedulersTest method testDirectSchedulePeriodicallyCancelsSchedulerTask.

@Test
public void testDirectSchedulePeriodicallyCancelsSchedulerTask() throws Exception {
    try (TaskCheckingScheduledExecutor executorService = new TaskCheckingScheduledExecutor()) {
        CountDownLatch latch = new CountDownLatch(2);
        Disposable disposable = Schedulers.directSchedulePeriodically(executorService, () -> {
            latch.countDown();
        }, 0, 10, TimeUnit.MILLISECONDS);
        latch.await();
        disposable.dispose();
        assertThat(executorService.isAllTasksCancelled()).isTrue();
    }
}
Also used : Disposable(reactor.core.Disposable) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 93 with Disposable

use of reactor.core.Disposable in project reactor-core by reactor.

the class TimedSchedulerTest method massCancel.

@Test
public void massCancel() throws InterruptedException {
    Scheduler timer = Schedulers.newSingle("test-timer");
    try {
        Worker w1 = timer.createWorker();
        AtomicInteger counter = new AtomicInteger();
        Runnable task = counter::getAndIncrement;
        int tasks = 10;
        Disposable[] c = new Disposable[tasks];
        for (int i = 0; i < tasks; i++) {
            c[i] = w1.schedulePeriodically(task, 500, 500, TimeUnit.MILLISECONDS);
        }
        w1.dispose();
        for (int i = 0; i < tasks; i++) {
            assertThat(c[i].isDisposed()).isTrue();
        }
        assertThat(counter).hasValue(0);
    } finally {
        timer.dispose();
    }
}
Also used : Disposable(reactor.core.Disposable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Worker(reactor.core.scheduler.Scheduler.Worker) Test(org.junit.jupiter.api.Test)

Example 94 with Disposable

use of reactor.core.Disposable in project spring-cloud-gcp by spring-cloud.

the class PubSubReactiveFactory method pollingPull.

private void pollingPull(String subscriptionName, long pollingPeriodMs, FluxSink<AcknowledgeablePubsubMessage> sink) {
    Disposable disposable = Flux.interval(Duration.ZERO, Duration.ofMillis(pollingPeriodMs), scheduler).flatMap(ignore -> pullAll(subscriptionName)).subscribe(sink::next, sink::error);
    sink.onDispose(disposable);
}
Also used : Disposable(reactor.core.Disposable) Disposable(reactor.core.Disposable) FluxSink(reactor.core.publisher.FluxSink) CompletableFuture(java.util.concurrent.CompletableFuture) Mono(reactor.core.publisher.Mono) Scheduler(reactor.core.scheduler.Scheduler) AcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.AcknowledgeablePubsubMessage) Flux(reactor.core.publisher.Flux) List(java.util.List) Duration(java.time.Duration) DeadlineExceededException(com.google.api.gax.rpc.DeadlineExceededException) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) PubSubSubscriberOperations(org.springframework.cloud.gcp.pubsub.core.subscriber.PubSubSubscriberOperations) Assert(org.springframework.util.Assert)

Example 95 with Disposable

use of reactor.core.Disposable in project reactor-core by reactor.

the class FluxTests method shouldWindowCorrectly.

@Test
public void shouldWindowCorrectly() throws InterruptedException {
    Flux<Integer> sensorDataStream = Flux.fromIterable(createTestDataset(1000));
    CountDownLatch endLatch = new CountDownLatch(1000 / 100);
    /*Disposable controls = */
    sensorDataStream.window(100).subscribe(batchedStream -> {
        System.out.println("New window starting");
        batchedStream.reduce(Integer.MAX_VALUE, Math::min).doOnSuccess(v -> endLatch.countDown()).subscribe(i -> System.out.println("Minimum " + i));
    });
    endLatch.await(10, TimeUnit.SECONDS);
    assertThat(endLatch.getCount()).isEqualTo(0);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Sinks(reactor.core.publisher.Sinks) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) TestLogger(reactor.test.util.TestLogger) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Tuples(reactor.util.function.Tuples) TimeoutException(java.util.concurrent.TimeoutException) Hooks(reactor.core.publisher.Hooks) Timer(java.util.Timer) Disabled(org.junit.jupiter.api.Disabled) CoreSubscriber(reactor.core.CoreSubscriber) Loggers(reactor.util.Loggers) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) Logger(reactor.util.Logger) Tag(org.junit.jupiter.api.Tag) AutoDisposingExtension(reactor.test.AutoDisposingExtension) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Signal(reactor.core.publisher.Signal) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) LockSupport(java.util.concurrent.locks.LockSupport) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Fuseable(reactor.core.Fuseable) Assertions.fail(org.assertj.core.api.Assertions.fail) LoggerUtils(reactor.test.util.LoggerUtils) Exceptions(reactor.core.Exceptions) IntStream(java.util.stream.IntStream) Disposable(reactor.core.Disposable) Scannable(reactor.core.Scannable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Tuple2(reactor.util.function.Tuple2) Callable(java.util.concurrent.Callable) Scheduler(reactor.core.scheduler.Scheduler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Queues(reactor.util.concurrent.Queues) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Schedulers(reactor.core.scheduler.Schedulers) Operators(reactor.core.publisher.Operators) Semaphore(java.util.concurrent.Semaphore) Publisher(org.reactivestreams.Publisher) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Flux(reactor.core.publisher.Flux) FAIL_FAST(reactor.core.publisher.Sinks.EmitFailureHandler.FAIL_FAST) Phaser(java.util.concurrent.Phaser) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Comparator(java.util.Comparator) Collections(java.util.Collections) Timeout(org.junit.jupiter.api.Timeout) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

Disposable (reactor.core.Disposable)118 Test (org.junit.jupiter.api.Test)99 CountDownLatch (java.util.concurrent.CountDownLatch)33 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)32 StepVerifier (reactor.test.StepVerifier)29 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)25 AtomicReference (java.util.concurrent.atomic.AtomicReference)18 Duration (java.time.Duration)15 List (java.util.List)15 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)15 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)15 Subscription (org.reactivestreams.Subscription)15 TimeUnit (java.util.concurrent.TimeUnit)14 Timeout (org.junit.jupiter.api.Timeout)13 CoreSubscriber (reactor.core.CoreSubscriber)12 ArrayList (java.util.ArrayList)11 Arrays (java.util.Arrays)11 Disabled (org.junit.jupiter.api.Disabled)11 Scannable (reactor.core.Scannable)11 Fuseable (reactor.core.Fuseable)10