Java Code Examples for reactor.util.concurrent.Queues#one()
The following examples show how to use
reactor.util.concurrent.Queues#one() .
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: FluxConcatMapTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void scanConcatMapImmediate() { CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null); FluxConcatMap.ConcatMapImmediate<String, Integer> test = new FluxConcatMap.ConcatMapImmediate<>( actual, s -> Mono.just(s.length()), Queues.one(), 123); Subscription parent = Operators.emptySubscription(); test.onSubscribe(parent); test.queue.offer("foo"); assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1); assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(123); assertThat(test.scan(Scannable.Attr.DELAY_ERROR)).isFalse(); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual); assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse(); test.onComplete(); assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); test.cancelled = true; assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue(); }
Example 2
Source File: FluxConcatMapTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void scanConcatMapImmediateError() { CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null); FluxConcatMap.ConcatMapImmediate<String, Integer> test = new FluxConcatMap.ConcatMapImmediate<>( actual, s -> Mono.just(s.length()), Queues.one(), 123); Subscription parent = Operators.emptySubscription(); test.onSubscribe(parent); assertThat(test.scan(Scannable.Attr.DELAY_ERROR)).isFalse(); //note that most of the time, the error will be hidden by TERMINATED as soon as it has been propagated downstream :( test.error = new IllegalStateException("boom"); assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom"); assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse(); test.onError(new IllegalStateException("boom2")); assertThat(test.scan(Scannable.Attr.ERROR)).isSameAs(Exceptions.TERMINATED); assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue(); }
Example 3
Source File: ParallelSourceTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void scanInnerSubscriber() { @SuppressWarnings("unchecked") CoreSubscriber<String>[] subs = new CoreSubscriber[2]; subs[0] = new LambdaSubscriber<>(null, e -> {}, null, null); subs[1] = new LambdaSubscriber<>(null, e -> {}, null, null); ParallelSource.ParallelSourceMain<String> main = new ParallelSource.ParallelSourceMain<>( subs, 123, Queues.one()); ParallelSource.ParallelSourceMain.ParallelSourceInner<String> test = new ParallelSource.ParallelSourceMain.ParallelSourceInner<>( main, 1, 10); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(main); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(subs[test.index]); }
Example 4
Source File: FluxGroupByTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void scanMain() { CoreSubscriber<GroupedFlux<Integer, String>> actual = new LambdaSubscriber<>(null, e -> {}, null, null); FluxGroupBy.GroupByMain<Integer, Integer, String> test = new FluxGroupBy.GroupByMain<>(actual, Queues.<GroupedFlux<Integer, String>>one().get(), Queues.one(), 123, i -> i % 5, i -> String.valueOf(i)); Subscription sub = Operators.emptySubscription(); test.onSubscribe(sub); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(sub); assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(Long.MAX_VALUE); assertThat(test.scan(Scannable.Attr.PREFETCH)).isSameAs(123); assertThat(test.scan(Scannable.Attr.BUFFERED)).isSameAs(0); assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse(); assertThat(test.scan(Scannable.Attr.ERROR)).isNull(); test.error = new IllegalStateException("boom"); assertThat(test.scan(Scannable.Attr.ERROR)).isSameAs(test.error); }
Example 5
Source File: FluxGroupByTest.java From reactor-core with Apache License 2.0 | 6 votes |
@Test public void scanUnicastGroupedFlux() { CoreSubscriber<GroupedFlux<Integer, String>> actual = new LambdaSubscriber<>(null, e -> {}, null, null); FluxGroupBy.GroupByMain<Integer, Integer, String> main = new FluxGroupBy.GroupByMain<>(actual, Queues.<GroupedFlux<Integer, String>>one().get(), Queues.one(), 123, i -> i % 5, i -> String.valueOf(i)); FluxGroupBy.UnicastGroupedFlux<Integer, String> test = new FluxGroupBy.UnicastGroupedFlux<Integer, String>(1, Queues.<String>one().get(), main, 123); CoreSubscriber<String> sub = new LambdaSubscriber<>(null, e -> {}, null, null); test.subscribe(sub); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(sub); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(main); assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(Long.MAX_VALUE); assertThat(test.scan(Scannable.Attr.BUFFERED)).isSameAs(0); assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse(); assertThat(test.scan(Scannable.Attr.ERROR)).isNull(); test.error = new IllegalStateException("boom"); assertThat(test.scan(Scannable.Attr.ERROR)).isSameAs(test.error); }
Example 6
Source File: FluxConcatMapTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanConcatMapDelayed() { CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null); FluxConcatMap.ConcatMapDelayed<String, Integer> test = new FluxConcatMap.ConcatMapDelayed<>( actual, s -> Mono.just(s.length()), Queues.one(), 123, true); Subscription parent = Operators.emptySubscription(); test.onSubscribe(parent); test.error = new IllegalStateException("boom"); test.queue.offer("foo"); assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1); assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(123); assertThat(test.scan(Scannable.Attr.DELAY_ERROR)).isTrue(); assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom"); 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.cancelled = true; assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue(); }
Example 7
Source File: FluxGroupJoinTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanGroupJoinSubscription() { CoreSubscriber<String> actual = new LambdaSubscriber<>(null, e -> {}, null, sub -> sub.request(100)); FluxGroupJoin.GroupJoinSubscription<String, String, String, String, String> test = new FluxGroupJoin.GroupJoinSubscription<>(actual, s -> Mono.just(s), s -> Mono.just(s), (l, r) -> l, Queues.one()); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual); test.request(123); assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(123); test.queue.add(5); test.queue.add(10); assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1); test.error = new IllegalArgumentException("boom"); assertThat(test.scan(Scannable.Attr.ERROR)).isSameAs(test.error); assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse(); test.active = 0; assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); test.cancel(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue(); }
Example 8
Source File: ParallelPeekTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanOperator() { ParallelSource<Integer> source = new ParallelSource<>(Flux.just(500, 300), 10, 123, Queues.one()); ParallelPeek<Integer> test = new ParallelPeek<>(source, null, null, null, null, null, null, null, null); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(source); assertThat(test.scan(Scannable.Attr.PREFETCH)) .isEqualTo(source.getPrefetch()) .isEqualTo(test.getPrefetch()) .isEqualTo(123); }
Example 9
Source File: BlockingIterableTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanOperator() { Flux<Integer> source = Flux.range(1, 10); BlockingIterable<Integer> test = new BlockingIterable<>(source, 35, Queues.one()); assertThat(test.scanUnsafe(Scannable.Attr.PARENT)).describedAs("PARENT").isSameAs(source); //type safe attributes assertThat(test.scanUnsafe(Attr.PREFETCH)).describedAs("PREFETCH unsafe").isEqualTo(35); assertThat(test.scan(Attr.PREFETCH)).describedAs("PREFETCH").isEqualTo(35); //FIXME }
Example 10
Source File: BlockingIterableTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanOperatorLargePrefetchIsLimitedToIntMax() { Flux<Integer> source = Flux.range(1, 10); BlockingIterable<Integer> test = new BlockingIterable<>(source, Integer.MAX_VALUE, Queues.one()); assertThat(test.scan(Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE); }
Example 11
Source File: FluxFlattenIterableTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanOperator() { Flux<Integer> source = Flux.range(1, 10).map(i -> i - 1); FluxFlattenIterable<Integer, Integer> test = new FluxFlattenIterable<>(source, i -> new ArrayList<>(i), 35, Queues.one()); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(source); assertThat(test.scan(Attr.PREFETCH)).isEqualTo(35); }
Example 12
Source File: FluxFlattenIterableTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanSubscriber() { CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null); FluxFlattenIterable.FlattenIterableSubscriber<Integer, Integer> test = new FluxFlattenIterable.FlattenIterableSubscriber<>(actual, i -> new ArrayList<>(i), 123, Queues.<Integer>one()); Subscription s = Operators.emptySubscription(); test.onSubscribe(s); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(s); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual); assertThat(test.scan(Attr.PREFETCH)).isEqualTo(123); test.requested = 35; assertThat(test.scan(Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(35); test.queue.add(5); assertThat(test.scan(Attr.BUFFERED)).isEqualTo(1); assertThat(test.scan(Scannable.Attr.ERROR)).isNull(); assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse(); test.error = new IllegalStateException("boom"); assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom"); test.onComplete(); assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); test.cancel(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue(); }
Example 13
Source File: FluxFlattenIterableTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void concatMapIterableDoOnDiscardOnClear() { ReferenceCounted referenceCounted1 = new ReferenceCounted(1); ReferenceCounted referenceCounted2 = new ReferenceCounted(2); Context context = Operators.discardLocalAdapter(ReferenceCounted.class, ReferenceCounted::release).apply(Context.empty()); FluxFlattenIterable.FlattenIterableSubscriber<Integer, ReferenceCounted> test = new FluxFlattenIterable.FlattenIterableSubscriber<>( new BaseSubscriber<ReferenceCounted>() { @Override protected void hookOnSubscribe(Subscription subscription) { request(1); } @Override public Context currentContext() { return context; } }, i -> Arrays.asList(referenceCounted1, referenceCounted2), 1, Queues.one()); test.onSubscribe(Operators.scalarSubscription(test, 1)); assertThat(test.current).as("current iterator").isNotNull(); assertThat(test.currentKnownToBeFinite).as("iterator know to be finite").isTrue(); test.clear(); assertThat(referenceCounted2.refCount).as("ref2 is released by the clear").isZero(); assertThat(test.current).as("current nulled out") .isNull(); assertThat(test.currentKnownToBeFinite).as("knownFinite reset").isFalse(); }
Example 14
Source File: ParallelSourceTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanMainSubscriber() { @SuppressWarnings("unchecked") CoreSubscriber<String>[] subs = new CoreSubscriber[1]; subs[0] = new LambdaSubscriber<>(null, e -> {}, null, null); ParallelSource.ParallelSourceMain<String> test = new ParallelSource.ParallelSourceMain<>( subs, 123, Queues.one()); Subscription parent = Operators.emptySubscription(); test.onSubscribe(parent); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent); assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(123); assertThat(test.scan(Scannable.Attr.BUFFERED)).isZero(); test.queue.offer("foo"); assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1); assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); assertThat(test.scan(Scannable.Attr.ERROR)).isNull(); test.onError(new IllegalStateException("boom")); assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom"); test.cancel(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue(); }
Example 15
Source File: ParallelMergeSequentialTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void scanOperator() { ParallelFlux<Integer> source = Flux.just(500, 300).parallel(10); ParallelMergeSequential<Integer> test = new ParallelMergeSequential<>(source, 123, Queues.one()); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(source); assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(123); }