Java Code Examples for reactor.util.concurrent.Queues#get()

The following examples show how to use reactor.util.concurrent.Queues#get() . 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: FluxFlatMapTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void noOuterScalarReordering() {
	AssertSubscriber<Integer> ts = AssertSubscriber.create(0);
	FluxFlatMap.FlatMapMain<Publisher<Integer>, Integer> fmm =
			new FluxFlatMap.FlatMapMain<>(ts,
					Function.identity(),
					false,
					128,
					Queues.get(128),
					128,
					Queues.get(128));

	fmm.onSubscribe(Operators.emptySubscription());

	fmm.onNext(Flux.just(1));

	Operators.addCap(FluxFlatMap.FlatMapMain.REQUESTED, fmm, 2L);

	fmm.onNext(Flux.just(2));

	fmm.drain(null);

	ts.assertValues(1, 2);
}
 
Example 2
Source File: FluxFlatMapTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@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);
 }
 
Example 3
Source File: FluxFlatMapTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanInner() {
    CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
    FluxFlatMap.FlatMapMain<Integer, Integer> main = new FluxFlatMap.FlatMapMain<>(actual,
            i -> Mono.just(i), true, 5, Queues.<Integer>unbounded(), 789,  Queues.<Integer>get(789));
    FluxFlatMap.FlatMapInner<Integer> inner = new FluxFlatMap.FlatMapInner<>(main, 123);
    Subscription parent = Operators.emptySubscription();
    inner.onSubscribe(parent);

    assertThat(inner.scan(Scannable.Attr.ACTUAL)).isSameAs(main);
    assertThat(inner.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(inner.scan(Scannable.Attr.PREFETCH)).isEqualTo(123);
    inner.queue = new ConcurrentLinkedQueue<>();
    inner.queue.add(5);
    assertThat(inner.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);

    assertThat(inner.scan(Scannable.Attr.TERMINATED)).isFalse();
    inner.onError(new IllegalStateException("boom"));
    assertThat(main.scan(Scannable.Attr.ERROR)).hasMessage("boom");
    inner.queue.clear();
    assertThat(inner.scan(Scannable.Attr.TERMINATED)).isTrue();

    assertThat(inner.scan(Scannable.Attr.CANCELLED)).isFalse();
    inner.cancel();
    assertThat(inner.scan(Scannable.Attr.CANCELLED)).isTrue();
}
 
Example 4
Source File: FluxMergeSequentialTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void mergeSequentialLargeBadQueueSize() {
	int prefetch = 32;
	int maxConcurrency = 256;
	Supplier<Queue<FluxMergeSequential.MergeSequentialInner<Integer>>> badQueueSupplier =
			Queues.get(Math.min(prefetch, maxConcurrency));

	FluxMergeSequential<Integer, Integer> fluxMergeSequential =
			new FluxMergeSequential<>(Flux.range(0, 500),
					Mono::just,
					maxConcurrency, prefetch, FluxConcatMap.ErrorMode.IMMEDIATE,
					badQueueSupplier);

	StepVerifier.create(fluxMergeSequential.zipWith(Flux.range(0, Integer.MAX_VALUE)))
	            .expectErrorMatches(e -> e instanceof IllegalStateException &&
	                e.getMessage().startsWith("Too many subscribers for fluxMergeSequential on item: ") &&
	                e.getMessage().endsWith("; subscribers: 32"))
	            .verify();
}
 
Example 5
Source File: FluxFlatMapTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void noInnerReordering() {
	AssertSubscriber<Integer> ts = AssertSubscriber.create(0);
	FluxFlatMap.FlatMapMain<Publisher<Integer>, Integer> fmm =
			new FluxFlatMap.FlatMapMain<>(ts,
					Function.identity(),
					false,
					128,
					Queues.get(128),
					128,
					Queues.get(128));

	fmm.onSubscribe(Operators.emptySubscription());

	FluxIdentityProcessor<Integer> ps = Processors.multicast();

	fmm.onNext(ps);

	ps.onNext(1);

	Operators.addCap(FluxFlatMap.FlatMapMain.REQUESTED, fmm, 2L);

	ps.onNext(2);

	fmm.drain(null);

	ts.assertValues(1, 2);
}
 
Example 6
Source File: FluxFlatMapTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void scanMain() {
    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));
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);

    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.DELAY_ERROR)).isTrue();
    test.requested = 35;
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(35);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(5);

    test.scalarQueue = new ConcurrentLinkedQueue<>();
    test.scalarQueue.add(1);
    assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);
    assertThat(test.scan(Scannable.Attr.LARGE_BUFFERED)).isEqualTo(1L);
    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)).isSameAs(test.error);
    test.scalarQueue.clear();
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();

    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.cancel();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
 
Example 7
Source File: FluxMergeSequential.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
FluxMergeSequential(Flux<? extends T> source,
		Function<? super T, ? extends Publisher<? extends R>> mapper,
		int maxConcurrency, int prefetch, ErrorMode errorMode) {
	this(source, mapper, maxConcurrency, prefetch, errorMode,
			Queues.get(Math.max(prefetch, maxConcurrency)));
}
 
Example 8
Source File: ParallelFlux.java    From reactor-core with Apache License 2.0 2 votes vote down vote up
/**
 * Merges the values from each 'rail', but choose which one to merge by way of a
 * provided {@link Comparator}, picking the smallest of all rails. The result is
 * exposed back as a {@link Flux}.
 *
 * @param comparator the comparator to choose the smallest value available from all rails
 * @param prefetch the prefetch to use
 * @return the new Flux instance
 *
 * @see ParallelFlux#ordered(Comparator)
 */
public final Flux<T> ordered(Comparator<? super T> comparator, int prefetch) {
	return new ParallelMergeOrdered<>(this, prefetch, Queues.get(prefetch), comparator);
}