ExpandBreathSubscriber(CoreSubscriber<? super T> actual, Function<? super T, ? extends Publisher<? extends T>> expander, int capacityHint) { super(actual); this.expander = expander; this.queue = Queues.<Publisher<? extends T>>unbounded(capacityHint).get(); }
BufferAsyncSink(CoreSubscriber<? super T> actual, int capacityHint) { super(actual); this.queue = Queues.<T>unbounded(capacityHint).get(); }
/** * Create a new {@link UnicastProcessor} that will buffer on an internal queue in an * unbounded fashion. * * @param <E> the relayed type * @return a unicast {@link FluxProcessor} */ public static <E> UnicastProcessor<E> create() { return new UnicastProcessor<>(Queues.<E>unbounded().get()); }
/** * Split this {@link Flux} sequence into continuous, non-overlapping windows * where the window boundary is signalled by another {@link Publisher} * * <p> * <img class="marble" src="doc-files/marbles/windowWithBoundary.svg" alt=""> * * @reactor.discard This operator discards elements it internally queued for backpressure * upon cancellation or error triggered by a data signal. * * @param boundary a {@link Publisher} to emit any item for a split signal and complete to terminate * * @return a {@link Flux} of {@link Flux} windows delimited by a given {@link Publisher} */ public final Flux<Flux<T>> window(Publisher<?> boundary) { return onAssembly(new FluxWindowBoundary<>(this, boundary, Queues.unbounded(Queues.XS_BUFFER_SIZE))); }
BackpressureBufferSubscriber(CoreSubscriber<? super T> actual, int bufferSize, boolean unbounded, boolean delayError, @Nullable Consumer<? super T> onOverflow) { this.actual = actual; this.ctx = actual.currentContext(); this.delayError = delayError; this.onOverflow = onOverflow; Queue<T> q; if (unbounded) { q = Queues.<T>unbounded(bufferSize).get(); } else { q = Queues.<T>get(bufferSize).get(); } this.queue = q; }
@Test public void capacityReactorUnboundedQueue() { Queue q = Queues.unbounded(2).get(); assertThat(Queues.capacity(q)).isEqualTo(Integer.MAX_VALUE); }
@Test public void bufferSizeReactorUnboundedQueue() { UnicastProcessor processor = UnicastProcessor.create( Queues.unbounded(2).get()); assertThat(processor.getBufferSize()).isEqualTo(Integer.MAX_VALUE); }
@Test public void scanMainLargeBuffered() { CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null); FluxFlatMap.FlatMapMain<Integer, Integer> test = new FluxFlatMap.FlatMapMain<>(actual, i -> Mono.just(i), true, 5, Queues.<Integer>unbounded(), 789, Queues.<Integer>get(789)); test.scalarQueue = new ConcurrentLinkedQueue<>(); test.scalarQueue.add(1); test.scalarQueue.add(2); test.scalarQueue.add(3); test.size = Integer.MAX_VALUE; assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(Integer.MIN_VALUE); assertThat(test.scan(Scannable.Attr.LARGE_BUFFERED)).isEqualTo(Integer.MAX_VALUE + 3L); }
@Test public void scanOverlapSubscriberSmallBuffered() { @SuppressWarnings("unchecked") Queue<UnicastProcessor<Integer>> mockQueue = Mockito.mock(Queue.class); CoreSubscriber<Flux<Integer>> actual = new LambdaSubscriber<>(null, e -> {}, null, null); FluxWindow.WindowOverlapSubscriber<Integer> test = new FluxWindow.WindowOverlapSubscriber<Integer>(actual, 3,3, Queues.unbounded(), mockQueue); when(mockQueue.size()).thenReturn(Integer.MAX_VALUE - 2); //size() is 1 test.offer(UnicastProcessor.create()); assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(Integer.MAX_VALUE - 1); assertThat(test.scan(Scannable.Attr.LARGE_BUFFERED)).isEqualTo(Integer.MAX_VALUE - 1L); }
@Test public void scanMain() { Flux<Integer> parent = Flux.just(1).map(i -> i); FluxPublish<Integer> test = new FluxPublish<>(parent, 123, Queues.unbounded()); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent); assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(123); }
public void assertProcessor(UnicastProcessor<Integer> processor, @Nullable Queue<Integer> queue, @Nullable Consumer<? super Integer> onOverflow, @Nullable Disposable onTerminate) { Queue<Integer> expectedQueue = queue != null ? queue : Queues.<Integer>unbounded().get(); Disposable expectedOnTerminate = onTerminate; assertEquals(expectedQueue.getClass(), processor.queue.getClass()); assertEquals(expectedOnTerminate, processor.onTerminate); if (onOverflow != null) assertEquals(onOverflow, processor.onOverflow); }
@Test public void scanCoordinator() { CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null); FluxZip.ZipCoordinator<Integer, Integer> test = new FluxZip.ZipCoordinator<Integer, Integer>(actual, i -> 5, 123, Queues.unbounded(), 345); Assertions.assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual); test.requested = 35; Assertions.assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(35); Assertions.assertThat(test.scan(Scannable.Attr.ERROR)).isNull(); test.error = new IllegalStateException("boom"); Assertions.assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom"); Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); test.cancel(); Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue(); }
@Test public void scanExactSubscriber() { CoreSubscriber<Flux<Integer>> actual = new LambdaSubscriber<>(null, e -> {}, null, null); FluxWindow.WindowExactSubscriber<Integer> test = new FluxWindow.WindowExactSubscriber<Integer>(actual, 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.CAPACITY)).isEqualTo(123); Assertions.assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse(); test.onComplete(); 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(); }
@Test public void scanInner() { CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null); FluxSwitchMap.SwitchMapMain<Integer, Integer> main = new FluxSwitchMap.SwitchMapMain<>(actual, i -> Mono.just(i), Queues.unbounded().get(), 234); FluxSwitchMap.SwitchMapInner<Integer> test = new FluxSwitchMap.SwitchMapInner<Integer>(main, 1, 0); Subscription parent = Operators.emptySubscription(); test.onSubscribe(parent); Assertions.assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent); Assertions.assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(main); Assertions.assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(1); Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); test.cancel(); Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue(); } }
@Test public void scanMulticastInner() { CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null); FluxPublishMulticast.FluxPublishMulticaster<Integer> parent = new FluxPublishMulticast.FluxPublishMulticaster<>(123, Queues.<Integer>unbounded(), Context.empty()); FluxPublishMulticast.PublishMulticastInner<Integer> test = new FluxPublishMulticast.PublishMulticastInner<>(parent, actual); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual); test.request(789); assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(789); assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); test.cancel(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue(); }
@Test public void scanPubSubInner() { FluxPublish<Integer> main = new FluxPublish<>(Flux.just(1), 123, Queues.unbounded()); FluxPublish.PublishSubscriber<Integer> parent = new FluxPublish.PublishSubscriber<>(789, main); Subscription sub = Operators.emptySubscription(); parent.onSubscribe(sub); FluxPublish.PubSubInner<Integer> test = new FluxPublish.PublishInner<>(parent); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(parent); test.request(35); assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(35); assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); test.cancel(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue(); }
@Test public void scanInner() { FluxPublish<Integer> main = new FluxPublish<>(Flux.just(1), 123, Queues.unbounded()); FluxPublish.PublishSubscriber<Integer> parent = new FluxPublish.PublishSubscriber<>(789, main); Subscription sub = Operators.emptySubscription(); parent.onSubscribe(sub); FluxPublish.PublishInner<Integer> test = new FluxPublish.PublishInner<>(parent); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(parent); test.parent = parent; assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent); test.request(35); assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(35); assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse(); parent.terminate(); assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse(); test.cancel(); assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue(); }
@Test public void scanOverlapSubscriberLargeBuffered() { @SuppressWarnings("unchecked") Queue<UnicastProcessor<Integer>> mockQueue = Mockito.mock(Queue.class); CoreSubscriber<Flux<Integer>> actual = new LambdaSubscriber<>(null, e -> {}, null, null); FluxWindow.WindowOverlapSubscriber<Integer> test = new FluxWindow.WindowOverlapSubscriber<Integer>(actual, 3, 3, Queues.unbounded(), mockQueue); when(mockQueue.size()).thenReturn(Integer.MAX_VALUE); //size() is 5 test.offer(UnicastProcessor.create()); test.offer(UnicastProcessor.create()); test.offer(UnicastProcessor.create()); test.offer(UnicastProcessor.create()); test.offer(UnicastProcessor.create()); assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(Integer.MIN_VALUE); assertThat(test.scan(Scannable.Attr.LARGE_BUFFERED)).isEqualTo(Integer.MAX_VALUE + 5L); }
@Test public void scanCancelFuseableMulticaster() { CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null); FluxPublishMulticast.FluxPublishMulticaster<Integer> parent = new FluxPublishMulticast.FluxPublishMulticaster<>(123, Queues.<Integer>unbounded(), Context.empty()); FluxPublishMulticast.CancelFuseableMulticaster<Integer> test = new FluxPublishMulticast.CancelFuseableMulticaster<>(actual, parent); Subscription sub = Operators.emptySubscription(); test.onSubscribe(sub); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(sub); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual); }
@Test public void scanCancelMulticaster() { CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null); FluxPublishMulticast.FluxPublishMulticaster<Integer> parent = new FluxPublishMulticast.FluxPublishMulticaster<>(123, Queues.<Integer>unbounded(), Context.empty()); FluxPublishMulticast.CancelMulticaster<Integer> test = new FluxPublishMulticast.CancelMulticaster<>(actual, parent); Subscription sub = Operators.emptySubscription(); test.onSubscribe(sub); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(sub); assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual); }