本文整理汇总了Java中reactor.core.scheduler.Schedulers.single方法的典型用法代码示例。如果您正苦于以下问题:Java Schedulers.single方法的具体用法?Java Schedulers.single怎么用?Java Schedulers.single使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reactor.core.scheduler.Schedulers
的用法示例。
在下文中一共展示了Schedulers.single方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sampleZipTest3
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test
public void sampleZipTest3() throws Exception {
int elements = 1;
CountDownLatch latch = new CountDownLatch(elements + 1);
EmitterProcessor<SensorData> sensorDataProcessor = EmitterProcessor.create();
Scheduler scheduler = Schedulers.single();
sensorDataProcessor.publishOn(scheduler)
.subscribe(d -> latch.countDown(), null, latch::countDown);
Flux.zip(Flux.just(new SensorData(2L, 12.0f)), Flux.just(new SensorData(1L, 14.0f)), this::computeMin)
.log("zip3")
.subscribe(sensorDataProcessor);
awaitLatch(null, latch);
scheduler.dispose();
}
示例2: scanSubscriber
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test
public void scanSubscriber() {
CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
FluxPublishOn.PublishOnSubscriber<Integer> test = new FluxPublishOn.PublishOnSubscriber<>(actual,
Schedulers.single(), Schedulers.single().createWorker(), true, 123, 123, Queues.unbounded());
Subscription parent = Operators.emptySubscription();
test.onSubscribe(parent);
Assertions.assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
Assertions.assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
Assertions.assertThat(test.scan(Scannable.Attr.DELAY_ERROR)).isTrue();
Assertions.assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(123);
test.requested = 35;
Assertions.assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(35L);
test.queue.add(1);
Assertions.assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);
Assertions.assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
test.onError(new IllegalStateException("boom"));
Assertions.assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
Assertions.assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
test.cancel();
Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
示例3: testBufferSize1Created
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test(timeout = 5_000)
public void testBufferSize1Created() throws Exception {
TopicProcessor<String> broadcast = TopicProcessor.<String>builder().name("share-name").bufferSize(1).autoCancel(true).build();
int simultaneousSubscribers = 3000;
CountDownLatch latch = new CountDownLatch(simultaneousSubscribers);
Scheduler scheduler = Schedulers.single();
FluxSink<String> sink = broadcast.sink();
Flux<String> flux = broadcast.filter(Objects::nonNull)
.publishOn(scheduler)
.cache(1);
for (int i = 0; i < simultaneousSubscribers; i++) {
flux.subscribe(s -> latch.countDown());
}
sink.next("data");
assertThat(latch.await(4, TimeUnit.SECONDS))
.overridingErrorMessage("Data not received")
.isTrue();
}
示例4: scanSubscriber
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test
public void scanSubscriber() {
CoreSubscriber<String> actual = new LambdaMonoSubscriber<>(null, e -> {}, null, null);
MonoDelayElement.DelayElementSubscriber<String> test = new MonoDelayElement.DelayElementSubscriber<>(
actual, Schedulers.single(), 10, TimeUnit.MILLISECONDS);
Subscription parent = Operators.emptySubscription();
test.onSubscribe(parent);
assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
test.onError(new IllegalStateException("boom"));
assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
test.cancel();
assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
示例5: scanInner
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test
public void scanInner() {
CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
FluxReplay<Integer> main = new FluxReplay<>(Flux.just(1), 2, 1000, Schedulers.single());
FluxReplay.ReplayInner<Integer> test = new FluxReplay.ReplayInner<>(actual);
FluxReplay.ReplaySubscriber<Integer> parent = new FluxReplay.ReplaySubscriber<>(new FluxReplay.UnboundedReplayBuffer<>(10), main);
parent.add(test);
test.parent = parent;
parent.buffer.replay(test);
Assertions.assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
Assertions.assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
Assertions.assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(0); // RS: TODO non-zero size
test.request(35);
Assertions.assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(35);
Assertions.assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
test.parent.terminate();
Assertions.assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
test.cancel();
Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
示例6: scanSubscriber
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test
public void scanSubscriber() {
FluxReplay<Integer> parent = new FluxReplay<>(Flux.just(1), 2, 1000, Schedulers.single());
FluxReplay.ReplaySubscriber<Integer> test = new FluxReplay.ReplaySubscriber<>(new FluxReplay.UnboundedReplayBuffer<>(10), parent);
Subscription sub = Operators.emptySubscription();
test.onSubscribe(sub);
Assertions.assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(sub);
Assertions.assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
Assertions.assertThat(test.scan(Scannable.Attr.CAPACITY)).isEqualTo(Integer.MAX_VALUE);
test.buffer.add(1);
Assertions.assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);
Assertions.assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
Assertions.assertThat(test.scan(Scannable.Attr.ERROR)).isNull();
test.onError(new IllegalStateException("boom"));
Assertions.assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
test.terminate();
Assertions.assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
test.cancelled = true;
Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
示例7: scanMainSubscriber
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test
public void scanMainSubscriber() {
CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
FluxSubscribeOnValue.ScheduledScalar<Integer> test =
new FluxSubscribeOnValue.ScheduledScalar<Integer>(actual, 1, Schedulers.single());
assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);
assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
test.future = FluxSubscribeOnValue.ScheduledScalar.FINISHED;
assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
test.future = OperatorDisposables.DISPOSED;
assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
示例8: scanSubscriber
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test
public void scanSubscriber() {
CoreSubscriber<Tuple2<Long, String>> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
FluxElapsed.ElapsedSubscriber<String> test = new FluxElapsed.ElapsedSubscriber<>(actual, Schedulers.single());
Subscription parent = Operators.emptySubscription();
test.onSubscribe(parent);
Assertions.assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
Assertions.assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
}
示例9: scanSubscriber
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test
public void scanSubscriber() {
CoreSubscriber<String> actual = new LambdaMonoSubscriber<>(null, e -> {}, null, null);
MonoPublishOn.PublishOnSubscriber<String> test = new MonoPublishOn.PublishOnSubscriber<>(
actual, Schedulers.single());
Subscription parent = Operators.emptySubscription();
test.onSubscribe(parent);
Assertions.assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
Assertions.assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
test.cancel();
Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
示例10: scanSubscriberError
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test
public void scanSubscriberError() {
CoreSubscriber<String> actual = new LambdaMonoSubscriber<>(null, e -> {}, null, null);
MonoPublishOn.PublishOnSubscriber<String> test = new MonoPublishOn.PublishOnSubscriber<>(
actual, Schedulers.single());
Assertions.assertThat(test.scan(Scannable.Attr.ERROR)).isNull();
test.onError(new IllegalStateException("boom"));
Assertions.assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
}
示例11: scanMainSubscriber
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test
public void scanMainSubscriber() {
CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
FluxSubscribeOnCallable.CallableSubscribeOnSubscription<Integer> test =
new FluxSubscribeOnCallable.CallableSubscribeOnSubscription<Integer>(actual, () -> 1, Schedulers.single());
Assertions.assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
test.value = 1;
Assertions.assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);
Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
test.cancel();
Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
示例12: testBufferSize1Shared
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test(timeout = 5_000)
public void testBufferSize1Shared() throws Exception {
WorkQueueProcessor<String> broadcast = WorkQueueProcessor.<String>builder()
.share(true)
.name("share-name")
.bufferSize(1)
.autoCancel(true)
.build();
int simultaneousSubscribers = 3000;
CountDownLatch latch = new CountDownLatch(simultaneousSubscribers);
Scheduler scheduler = Schedulers.single();
FluxSink<String> sink = broadcast.sink();
Flux<String> flux = broadcast.filter(Objects::nonNull)
.publishOn(scheduler)
.cache(1);
for (int i = 0; i < simultaneousSubscribers; i++) {
flux.subscribe(s -> latch.countDown());
}
sink.next("data");
Assertions.assertThat(latch.await(4, TimeUnit.SECONDS))
.overridingErrorMessage("Data not received")
.isTrue();
}
示例13: testBufferSize1Created
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test(timeout = 5_000)
public void testBufferSize1Created() throws Exception {
WorkQueueProcessor<String> broadcast = WorkQueueProcessor.<String>builder()
.share(true).name("share-name")
.bufferSize(1)
.autoCancel(true)
.build();
int simultaneousSubscribers = 3000;
CountDownLatch latch = new CountDownLatch(simultaneousSubscribers);
Scheduler scheduler = Schedulers.single();
FluxSink<String> sink = broadcast.sink();
Flux<String> flux = broadcast.filter(Objects::nonNull)
.publishOn(scheduler)
.cache(1);
for (int i = 0; i < simultaneousSubscribers; i++) {
flux.subscribe(s -> latch.countDown());
}
sink.next("data");
Assertions.assertThat(latch.await(4, TimeUnit.SECONDS))
.overridingErrorMessage("Data not received")
.isTrue();
}
示例14: scanOperator
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test
public void scanOperator() throws Exception {
ParallelFlux<String> source = Flux.<String>empty().parallel(2);
ParallelRunOn<String> test = new ParallelRunOn<>(source, Schedulers.single(), 123, Queues.small());
assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(source);
assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(123);
}
示例15: parallelism
import reactor.core.scheduler.Schedulers; //导入方法依赖的package包/类
@Test
public void parallelism() {
ParallelFlux<String> source = Flux.<String>empty().parallel(2);
ParallelRunOn<String> test = new ParallelRunOn<>(source, Schedulers.single(), 123, Queues.small());
assertThat(test.parallelism()).isEqualTo(2);
}