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();
}
}
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();
}
}
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();
}
}
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);
}
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);
}
Aggregations