Java Code Examples for reactor.core.scheduler.Schedulers#single()
The following examples show how to use
reactor.core.scheduler.Schedulers#single() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RouterTest.java From Discord4J with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testCustomThreadingModel() throws Exception { Scheduler thread = Schedulers.single(); String cid = Integer.toHexString(this.hashCode()); for (int i = 0; i < 6; i++) { final int a = i; MessageCreateRequest body = MessageCreateRequest.builder() .content(cid + " " + a) .build(); Routes.MESSAGE_CREATE.newRequest(channelId) .body(body) .exchange(router) .bodyToMono(MessageData.class) .publishOn(thread) .cancelOn(thread) .subscribeOn(thread) .subscribe(response -> System.out.println("response " + a + ": " + response.content())); } TimeUnit.SECONDS.sleep(10); }
Example 2
Source File: MonoPublishOnTest.java From reactor-core with Apache License 2.0 | 6 votes |
@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); assertThat(test.scan(Scannable.Attr.RUN_ON)).isSameAs(Schedulers.single()); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual); assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); test.cancel(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue(); }
Example 3
Source File: MonoDelayElementTest.java From reactor-core with Apache License 2.0 | 6 votes |
@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.RUN_ON)).isSameAs(Schedulers.single()); 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(); }
Example 4
Source File: FluxReplayTest.java From reactor-core with Apache License 2.0 | 6 votes |
@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.ReplaySubscriber<Integer> parent = new FluxReplay.ReplaySubscriber<>(new FluxReplay.UnboundedReplayBuffer<>(10), main); FluxReplay.ReplayInner<Integer> test = new FluxReplay.ReplayInner<>(actual, parent, false); parent.add(test); 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 Assertions.assertThat(test.scan(Scannable.Attr.RUN_ON)).isSameAs(Schedulers.single()); 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(); }
Example 5
Source File: FluxReplayTest.java From reactor-core with Apache License 2.0 | 6 votes |
@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(); }
Example 6
Source File: FluxSubscribeOnValueTest.java From reactor-core with Apache License 2.0 | 6 votes |
@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(); assertThat(test.scan(Scannable.Attr.RUN_ON)).isSameAs(Schedulers.single()); }
Example 7
Source File: FluxElapsedTest.java From reactor-core with Apache License 2.0 | 5 votes |
@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); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual); assertThat(test.scan(Scannable.Attr.RUN_ON)).isSameAs(Schedulers.single()); }
Example 8
Source File: MonoPublishOnTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanSubscriberError() { CoreSubscriber<String> actual = new LambdaMonoSubscriber<>(null, e -> {}, null, null); MonoPublishOn.PublishOnSubscriber<String> test = new MonoPublishOn.PublishOnSubscriber<>( actual, Schedulers.single()); assertThat(test.scan(Scannable.Attr.ERROR)).isNull(); test.onError(new IllegalStateException("boom")); assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom"); }
Example 9
Source File: FluxPublishOnTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanSubscriber() throws InterruptedException { 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); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual); assertThat(test.scan(Scannable.Attr.DELAY_ERROR)).isTrue(); assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(123); test.requested = 35; assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(35L); assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse(); test.onError(new IllegalStateException("boom")); assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom"); assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); test.cancel(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue(); //once cancelled, there shouldn't be any draining left // => better place to test that BUFFERED reflects the size of the queue Thread.sleep(50); //"hiccup" to ensure cancellation / draining is done test.queue.add(1); test.queue.add(1); assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(2); }
Example 10
Source File: FluxPublishOnTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanConditionalSubscriber() { @SuppressWarnings("unchecked") Fuseable.ConditionalSubscriber<Integer> actual = Mockito.mock(MockUtils.TestScannableConditionalSubscriber.class); FluxPublishOn.PublishOnConditionalSubscriber<Integer> test = new FluxPublishOn.PublishOnConditionalSubscriber<>(actual, Schedulers.single(), Schedulers.single().createWorker(), true, 123, 123, Queues.unbounded()); Subscription parent = Operators.emptySubscription(); test.onSubscribe(parent); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual); assertThat(test.scan(Scannable.Attr.DELAY_ERROR)).isTrue(); assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(123); test.requested = 35; assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(35L); test.queue.add(1); assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1); assertThat(test.scan(Scannable.Attr.ERROR)).isNull(); assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse(); test.onError(new IllegalStateException("boom")); assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom"); assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); test.cancel(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue(); }
Example 11
Source File: FluxSubscribeOnCallableTest.java From reactor-core with Apache License 2.0 | 5 votes |
@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); Assertions.assertThat(test.scan(Scannable.Attr.RUN_ON)).isSameAs(Schedulers.single()); 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(); }
Example 12
Source File: ParallelRunOnTest.java From reactor-core with Apache License 2.0 | 5 votes |
@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); }
Example 13
Source File: ParallelRunOnTest.java From reactor-core with Apache License 2.0 | 5 votes |
@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); }
Example 14
Source File: FluxReplayTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanMain() { Flux<Integer> parent = Flux.just(1).map(i -> i); FluxReplay<Integer> test = new FluxReplay<>(parent, 25, 1000, Schedulers.single()); Assertions.assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent); Assertions.assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(25); Assertions.assertThat(test.scan(Scannable.Attr.RUN_ON)).isSameAs(Schedulers.single()); }
Example 15
Source File: FluxRefCountGraceTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanMain() { ConnectableFlux<Integer> parent = Flux.just(10).publish(); FluxRefCountGrace<Integer> test = new FluxRefCountGrace<Integer>(parent, 17, Duration.ofSeconds(1), Schedulers.single()); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent); assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(256); }
Example 16
Source File: FluxCancelOnTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanSubscriber() { CoreSubscriber<String> actual = new LambdaSubscriber<>(null, null, null, null); FluxCancelOn.CancelSubscriber<String> test = new FluxCancelOn.CancelSubscriber<>(actual, Schedulers.single()); Subscription parent = Operators.emptySubscription(); test.onSubscribe(parent); assertThat(test.scan(Scannable.Attr.RUN_ON)).isSameAs(Schedulers.single()); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual); assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); test.cancel(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue(); }