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

The following examples show how to use reactor.util.concurrent.Queues#small() . 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: FluxBufferWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void discardOnDrainDoneWithErrors() {
	List<Object> discarded = new ArrayList<>();

	CoreSubscriber<List<Integer>> actual = new AssertSubscriber<>(
			Context.of(Hooks.KEY_ON_DISCARD, (Consumer<?>) discarded::add));
	FluxBufferWhen.BufferWhenMainSubscriber<Integer, Integer, Integer, List<Integer>> operator =
			new FluxBufferWhen.BufferWhenMainSubscriber<Integer, Integer, Integer, List<Integer>>(actual,
					ArrayList::new,
					Queues.small(),
					Flux.just(1), i -> Flux.never());
	operator.onSubscribe(new Operators.EmptySubscription());
	operator.request(1);

	operator.buffers.put(0L, Arrays.asList(4, 5));
	operator.queue.offer(Arrays.asList(1, 2, 3));
	operator.onError(new IllegalStateException("boom")); //triggers the drain

	assertThat(discarded).containsExactly(1, 2, 3, 4, 5);
}
 
Example 2
Source File: ParallelMergeSequentialTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanMainSubscriber() {
	LambdaSubscriber<Integer> subscriber = new LambdaSubscriber<>(null, e -> { }, null,
			s -> s.request(2));
	MergeSequentialMain<Integer>
			test = new MergeSequentialMain<>(subscriber, 4, 123, Queues.small());

	subscriber.onSubscribe(test);

	assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(subscriber);
	assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(2);

	assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
	assertThat(test.scan(Scannable.Attr.ERROR)).isNull();

	assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
	test.cancel();
	assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
 
Example 3
Source File: FluxBufferWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void discardOnCancelPostQueueing() {
	List<Object> discarded = new ArrayList<>();

	CoreSubscriber<List<Integer>> actual = new AssertSubscriber<>(
			Context.of(Hooks.KEY_ON_DISCARD, (Consumer<?>) discarded::add));
	FluxBufferWhen.BufferWhenMainSubscriber<Integer, Integer, Integer, List<Integer>> operator =
			new FluxBufferWhen.BufferWhenMainSubscriber<Integer, Integer, Integer, List<Integer>>(actual,
					ArrayList::new,
					Queues.small(),
					Flux.just(1), i -> Flux.never());
	operator.onSubscribe(new Operators.EmptySubscription());

	operator.buffers.put(0L, Arrays.asList(4, 5));
	operator.queue.offer(Arrays.asList(1, 2, 3));
	operator.cancel();

	assertThat(discarded).containsExactly(1, 2, 3, 4, 5);
}
 
Example 4
Source File: FluxBufferWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanStartEndMain() {
	CoreSubscriber<List<String>> actual = new LambdaSubscriber<>(null, e -> {}, null, null);

	BufferWhenMainSubscriber<String, Integer, Long, List<String>> test =
			new BufferWhenMainSubscriber<String, Integer, Long, List<String>>(
					actual, ArrayList::new, Queues.small(), Mono.just(1), u -> Mono.just(1L));
	Subscription parent = Operators.emptySubscription();
	test.onSubscribe(parent);
	test.request(100L);

	assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
	assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
	assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
	assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
	assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(0); //TODO
	assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(100L);
	assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);

	test.onError(new IllegalStateException("boom"));
	assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
}
 
Example 5
Source File: FluxBufferWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void discardOnDrainEmittedAllWithErrors() {
	List<Object> discarded = new ArrayList<>();

	CoreSubscriber<List<Integer>> actual = new AssertSubscriber<>(
			Context.of(Hooks.KEY_ON_DISCARD, (Consumer<?>) discarded::add));
	FluxBufferWhen.BufferWhenMainSubscriber<Integer, Integer, Integer, List<Integer>> operator =
			new FluxBufferWhen.BufferWhenMainSubscriber<Integer, Integer, Integer, List<Integer>>(actual,
					ArrayList::new,
					Queues.small(),
					Flux.just(1), i -> Flux.never());
	operator.onSubscribe(new Operators.EmptySubscription());

	operator.buffers.put(0L, Arrays.asList(4, 5));
	operator.queue.offer(Arrays.asList(1, 2, 3));
	operator.onError(new IllegalStateException("boom"));

	assertThat(discarded).containsExactly(1, 2, 3, 4, 5);
}
 
Example 6
Source File: FluxWindowPredicateTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void mainErrorUntilCutBeforeIsPropagatedToBothWindowAndMain() {
	FluxIdentityProcessor<Integer> sp1 = Processors.more().multicastNoBackpressure();
	FluxWindowPredicate<Integer> windowUntilCutBefore =
			new FluxWindowPredicate<>(sp1, Queues.small(), Queues.unbounded(), Queues.SMALL_BUFFER_SIZE,
					i -> i % 3 == 0, Mode.UNTIL_CUT_BEFORE);

	StepVerifier.create(windowUntilCutBefore.flatMap(Flux::materialize))
	            .expectSubscription()
	            .then(() -> sp1.onNext(1))
	            .expectNext(Signal.next(1))
	            .then(() -> sp1.onNext(2))
	            .expectNext(Signal.next(2))
	            .then(() -> sp1.onNext(3))
	            .expectNext(Signal.complete())
	            .expectNext(Signal.next(3))
	            .then(() -> sp1.onNext(4))
	            .expectNext(Signal.next(4))
	            .then(() -> sp1.onError(new RuntimeException("forced failure")))
	            //this is the error in the window:
	            .expectNextMatches(signalErrorMessage("forced failure"))
	            //this is the error in the main:
	            .expectErrorMessage("forced failure")
	            .verify();
	assertThat(sp1.hasDownstreams()).isFalse();
}
 
Example 7
Source File: FluxWindowPredicateTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void mainErrorUntilIsPropagatedToBothWindowAndMain() {
	FluxIdentityProcessor<Integer> sp1 = Processors.more().multicastNoBackpressure();
	FluxWindowPredicate<Integer> windowUntil = new FluxWindowPredicate<>(
			sp1, Queues.small(), Queues.unbounded(), Queues.SMALL_BUFFER_SIZE,
			i -> i % 3 == 0, Mode.UNTIL);

	StepVerifier.create(windowUntil.flatMap(Flux::materialize))
	            .expectSubscription()
	            .then(() -> sp1.onNext(1))
	            .expectNext(Signal.next(1))
	            .then(() -> sp1.onNext(2))
	            .expectNext(Signal.next(2))
	            .then(() -> sp1.onNext(3))
	            .expectNext(Signal.next(3), Signal.complete())
	            .then(() -> sp1.onNext(4))
	            .expectNext(Signal.next(4))
	            .then(() -> sp1.onError(new RuntimeException("forced failure")))
	            //this is the error in the window:
	            .expectNextMatches(signalErrorMessage("forced failure"))
	            //this is the error in the main:
	            .expectErrorMessage("forced failure")
	            .verify();
	assertThat(sp1.hasDownstreams()).isFalse();
}
 
Example 8
Source File: FluxBufferWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void discardOnDrainEmittedAllCancelled() {
	List<Object> discarded = new ArrayList<>();

	CoreSubscriber<List<Integer>> actual = new AssertSubscriber<>(
			Context.of(Hooks.KEY_ON_DISCARD, (Consumer<?>) discarded::add));
	FluxBufferWhen.BufferWhenMainSubscriber<Integer, Integer, Integer, List<Integer>> operator =
			new FluxBufferWhen.BufferWhenMainSubscriber<Integer, Integer, Integer, List<Integer>>(actual,
					ArrayList::new,
					Queues.small(),
					Flux.just(1), i -> Flux.never());
	operator.onSubscribe(new Operators.EmptySubscription());

	operator.buffers.put(0L, Arrays.asList(4, 5));
	operator.queue.offer(Arrays.asList(1, 2, 3));
	operator.cancelled = true;
	operator.drain();

	//drain only deals with queue, other method calling drain should deal with the open buffers (notably cancel)
	assertThat(discarded).containsExactly(1, 2, 3);
}
 
Example 9
Source File: FluxWindowPredicateTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void normalUntilCutBefore() {
	FluxIdentityProcessor<Integer> sp1 = Processors.more().multicastNoBackpressure();
	FluxWindowPredicate<Integer> windowUntilCutBefore = new FluxWindowPredicate<>(sp1,
			Queues.small(), Queues.unbounded(), Queues.SMALL_BUFFER_SIZE,
			i -> i % 3 == 0, Mode.UNTIL_CUT_BEFORE);

	StepVerifier.create(windowUntilCutBefore.flatMap(Flux::materialize))
			.expectSubscription()
			    .then(() -> sp1.onNext(1))
			    .expectNext(Signal.next(1))
			    .then(() -> sp1.onNext(2))
			    .expectNext(Signal.next(2))
			    .then(() -> sp1.onNext(3))
			    .expectNext(Signal.complete(), Signal.next(3))
			    .then(() -> sp1.onNext(4))
			    .expectNext(Signal.next(4))
			    .then(() -> sp1.onNext(5))
			    .expectNext(Signal.next(5))
			    .then(() -> sp1.onNext(6))
			    .expectNext(Signal.complete(), Signal.next(6))
			    .then(() -> sp1.onNext(7))
			    .expectNext(Signal.next(7))
			    .then(() -> sp1.onNext(8))
			    .expectNext(Signal.next(8))
			    .then(sp1::onComplete)
			    .expectNext(Signal.complete())
			    .verifyComplete();
	assertThat(sp1.hasDownstreams()).isFalse();
}
 
Example 10
Source File: FluxWindowPredicateTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void predicateErrorUntilCutBefore() {
	FluxIdentityProcessor<Integer> sp1 = Processors.more().multicastNoBackpressure();
	FluxWindowPredicate<Integer> windowUntilCutBefore =
			new FluxWindowPredicate<>(sp1, Queues.small(), Queues.unbounded(), Queues.SMALL_BUFFER_SIZE,
			i -> {
				if (i == 5) throw new IllegalStateException("predicate failure");
				return i % 3 == 0;
			}, Mode.UNTIL_CUT_BEFORE);

	StepVerifier.create(windowUntilCutBefore.flatMap(Flux::materialize))
				.expectSubscription()
				.then(() -> sp1.onNext(1))
				.expectNext(Signal.next(1))
				.then(() -> sp1.onNext(2))
				.expectNext(Signal.next(2))
				.then(() -> sp1.onNext(3))
				.expectNext(Signal.complete(), Signal.next(3))
				.then(() -> sp1.onNext(4))
				.expectNext(Signal.next(4))
				.then(() -> sp1.onNext(5))
				//error in the window:
				.expectNextMatches(signalErrorMessage("predicate failure"))
				.expectErrorMessage("predicate failure")
				.verify();
	assertThat(sp1.hasDownstreams()).isFalse();
}
 
Example 11
Source File: FluxWindowPredicateTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void normalWhile() {
	FluxIdentityProcessor<Integer> sp1 = Processors.more().multicastNoBackpressure();
	FluxWindowPredicate<Integer> windowWhile = new FluxWindowPredicate<>(
			sp1, Queues.small(), Queues.unbounded(), Queues.SMALL_BUFFER_SIZE,
			i -> i % 3 != 0, Mode.WHILE);

	StepVerifier.create(windowWhile.flatMap(Flux::materialize))
	            .expectSubscription()
	            .then(() -> sp1.onNext(1))
	            .expectNext(Signal.next(1))
	            .then(() -> sp1.onNext(2))
	            .expectNext(Signal.next(2))
	            .then(() -> sp1.onNext(3))
	            .expectNext(Signal.complete())
	            .then(() -> sp1.onNext(4))
	            .expectNext(Signal.next(4))
	            .then(() -> sp1.onNext(5))
	            .expectNext(Signal.next(5))
	            .then(() -> sp1.onNext(6))
	            .expectNext(Signal.complete())
	            .then(() -> sp1.onNext(7))
	            .expectNext(Signal.next(7))
	            .then(() -> sp1.onNext(8))
	            .expectNext(Signal.next(8))
	            .then(sp1::onComplete)
	            .expectNext(Signal.complete())
	            .verifyComplete();
	assertThat(sp1.hasDownstreams()).isFalse();
}
 
Example 12
Source File: FluxBufferWhenTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void scanStartEndMainCompleted() {
	CoreSubscriber<List<String>> actual = new LambdaSubscriber<>(null, e -> {}, null, null);

	BufferWhenMainSubscriber<String, Integer, Long, List<String>> test =
			new BufferWhenMainSubscriber<String, Integer, Long, List<String>>(
			actual, ArrayList::new, Queues.small(), Mono.just(1), u -> Mono.just(1L));
	Subscription parent = Operators.emptySubscription();
	test.onSubscribe(parent);
	assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();

	test.onComplete();
	assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
}
 
Example 13
Source File: FluxWindowPredicateTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void onCompletionBeforeLastBoundaryWindowEmitted() {
	Flux<Integer> source = Flux.just(1, 2);

	FluxWindowPredicate<Integer> windowUntil =
			new FluxWindowPredicate<>(source, Queues.small(), Queues.unbounded(), Queues.SMALL_BUFFER_SIZE,
					i -> i >= 3, Mode.UNTIL);

	FluxWindowPredicate<Integer> windowUntilCutBefore =
			new FluxWindowPredicate<>(source, Queues.small(), Queues.unbounded(), Queues.SMALL_BUFFER_SIZE,
					i -> i >= 3, Mode.UNTIL_CUT_BEFORE);

	FluxWindowPredicate<Integer> windowWhile =
			new FluxWindowPredicate<>(source, Queues.small(), Queues.unbounded(), Queues.SMALL_BUFFER_SIZE,
					i -> i < 3, Mode.WHILE);

	StepVerifier.create(windowUntil.flatMap(Flux::collectList))
			.expectNext(Arrays.asList(1, 2))
			.expectComplete()
			.verify();

	StepVerifier.create(windowUntilCutBefore.flatMap(Flux::collectList))
	            .expectNext(Arrays.asList(1, 2))
	            .expectComplete()
	            .verify();

	StepVerifier.create(windowWhile.flatMap(Flux::collectList))
	            .expectNext(Arrays.asList(1, 2))
	            .expectComplete()
	            .verify();
}
 
Example 14
Source File: FluxWindowPredicateTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void normalUntil() {
	FluxIdentityProcessor<Integer> sp1 = Processors.more().multicastNoBackpressure();
	FluxWindowPredicate<Integer> windowUntil = new FluxWindowPredicate<>(sp1,
			Queues.small(),
			Queues.unbounded(),
			Queues.SMALL_BUFFER_SIZE,
			i -> i % 3 == 0,
			Mode.UNTIL);

	StepVerifier.create(windowUntil.flatMap(Flux::materialize))
	            .expectSubscription()
	            .then(() -> sp1.onNext(1))
	            .expectNext(Signal.next(1))
			    .then(() -> sp1.onNext(2))
	            .expectNext(Signal.next(2))
			    .then(() -> sp1.onNext(3))
	            .expectNext(Signal.next(3), Signal.complete())
			    .then(() -> sp1.onNext(4))
			    .expectNext(Signal.next(4))
			    .then(() -> sp1.onNext(5))
			    .expectNext(Signal.next(5))
			    .then(() -> sp1.onNext(6))
			    .expectNext(Signal.next(6), Signal.complete())
			    .then(() -> sp1.onNext(7))
			    .expectNext(Signal.next(7))
			    .then(() -> sp1.onNext(8))
			    .expectNext(Signal.next(8))
			    .then(sp1::onComplete)
	            .expectNext(Signal.complete())
			    .verifyComplete();

	assertThat(sp1.hasDownstreams()).isFalse();
}
 
Example 15
Source File: ParallelConcatMapTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void scanOperator() throws Exception {
	ParallelFlux<Integer> source = Flux.range(1, 4).parallel(3);
	ParallelConcatMap<Integer, Integer> test = new ParallelConcatMap<>(source,
			i -> Flux.range(1, i), Queues.small(), 123,
			FluxConcatMap.ErrorMode.IMMEDIATE);

	assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(source);
	assertThat(test.scan(Scannable.Attr.PREFETCH))
			.isEqualTo(123)
			.isNotEqualTo(source.getPrefetch());

	assertThat(test.scan(Scannable.Attr.DELAY_ERROR)).isFalse();
}
 
Example 16
Source File: ParallelMergeSequentialTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void scanInnerSubscriber() {
	CoreSubscriber<Integer>
			mainActual = new LambdaSubscriber<>(null, e -> { }, null, null);
	MergeSequentialMain<Integer> main = new MergeSequentialMain<>(mainActual, 2,  123, Queues.small());
	MergeSequentialInner<Integer> test = new MergeSequentialInner<>(main, 456);

	Subscription subscription = Operators.emptySubscription();
	test.onSubscribe(subscription);
}
 
Example 17
Source File: ParallelConcatMapTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void scanOperatorErrorModeEnd() throws Exception {
	ParallelFlux<Integer> source = Flux.range(1, 4).parallel(3);
	ParallelConcatMap<Integer, Integer> test = new ParallelConcatMap<>(source,
			i -> Flux.range(1, i), Queues.small(), 123,
			FluxConcatMap.ErrorMode.END);

	assertThat(test.scan(Scannable.Attr.DELAY_ERROR)).isTrue();
}
 
Example 18
Source File: ParallelRunOnTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@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 19
Source File: ParallelRunOnTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@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 20
Source File: ParallelSourceTest.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Test
public void parallelism() {
	Flux<String> source = Flux.empty();
	ParallelSource<String> test = new ParallelSource<>(source, 100, 123, Queues.small());
	assertThat(test.parallelism()).isEqualTo(100);
}