Java Code Examples for reactor.util.concurrent.Queues#SMALL_BUFFER_SIZE

The following examples show how to use reactor.util.concurrent.Queues#SMALL_BUFFER_SIZE . 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: FluxCreate.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
static <T> BaseSink<T> createSink(CoreSubscriber<? super T> t,
		OverflowStrategy backpressure) {
	switch (backpressure) {
		case IGNORE: {
			return new IgnoreSink<>(t);
		}
		case ERROR: {
			return new ErrorAsyncSink<>(t);
		}
		case DROP: {
			return new DropAsyncSink<>(t);
		}
		case LATEST: {
			return new LatestAsyncSink<>(t);
		}
		default: {
			return new BufferAsyncSink<>(t, Queues.SMALL_BUFFER_SIZE);
		}
	}
}
 
Example 2
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 3
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 4
Source File: FluxWindowPredicateTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void mainErrorWhileIsPropagatedToBothWindowAndMain() {
	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.complete())
	            .then(() -> sp1.onNext(2))
	            .expectNext(Signal.complete())
	            .then(() -> sp1.onNext(3)) //at this point, new window, need another data to close it
	            .then(() -> sp1.onNext(4))
	            .expectNext(Signal.next(3), Signal.complete())
	            .then(() -> sp1.onError(new RuntimeException("forced failure")))
	            //this is the error in the main:
	            .expectErrorMessage("forced failure")
	            .verify(Duration.ofMillis(100));
	assertThat(sp1.hasDownstreams()).isFalse();
}
 
Example 5
Source File: FluxReplay.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
ReplaySubscriber<T> newState() {
	if (scheduler != null) {
		return new ReplaySubscriber<>(new SizeAndTimeBoundReplayBuffer<>(history,
				ttl,
				scheduler),
				this);
	}
	if (history != Integer.MAX_VALUE) {
		return new ReplaySubscriber<>(new SizeBoundReplayBuffer<>(history),
				this);
	}
	return new ReplaySubscriber<>(new UnboundedReplayBuffer<>(Queues.SMALL_BUFFER_SIZE),
				this);
}
 
Example 6
Source File: EmitterProcessorTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
public void assertProcessor(EmitterProcessor<Integer> processor,
		@Nullable Integer bufferSize,
		@Nullable Boolean autoCancel) {
	int expectedBufferSize = bufferSize != null ? bufferSize : Queues.SMALL_BUFFER_SIZE;
	boolean expectedAutoCancel = autoCancel != null ? autoCancel : true;

	assertEquals(expectedBufferSize, processor.prefetch);
	assertEquals(expectedAutoCancel, processor.autoCancel);
}
 
Example 7
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 8
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 9
Source File: FluxWindowPredicateTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void predicateErrorUntil() {
	FluxIdentityProcessor<Integer> sp1 = Processors.more().multicastNoBackpressure();
	FluxWindowPredicate<Integer> windowUntil = 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);

	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))
				//error in the window:
				.expectNextMatches(signalErrorMessage("predicate failure"))
				.expectErrorMessage("predicate failure")
				.verify();
	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 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 11
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 12
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 13
Source File: FluxWindowPredicateTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void normalWhileDoesntInitiallyMatch() {
	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()
	            .expectNoEvent(Duration.ofMillis(10))
	            .then(() -> sp1.onNext(1)) //closes initial, open 2nd
	            .expectNext(Signal.complete())
	            .then(() -> sp1.onNext(2)) //closes second, open 3rd
	            .expectNext(Signal.complete())
	            .then(() -> sp1.onNext(3)) //emits 3
	            .expectNext(Signal.next(3))
	            .expectNoEvent(Duration.ofMillis(10))
	            .then(() -> sp1.onNext(4)) //closes 3rd, open 4th
	            .expectNext(Signal.complete())
	            .then(() -> sp1.onNext(5)) //closes 4th, open 5th
	            .expectNext(Signal.complete())
	            .then(() -> sp1.onNext(6)) //emits 6
	            .expectNext(Signal.next(6))
	            .expectNoEvent(Duration.ofMillis(10))
	            .then(() -> sp1.onNext(7)) //closes 5th, open 6th
	            .expectNext(Signal.complete())
	            .then(() -> sp1.onNext(8)) //closes 6th, open 7th
	            .expectNext(Signal.complete())
	            .then(() -> sp1.onNext(9)) //emits 9
	            .expectNext(Signal.next(9))
	            .expectNoEvent(Duration.ofMillis(10))
	            .then(sp1::onComplete) // completion triggers completion of the last window (7th)
	            .expectNext(Signal.complete())
	            .expectComplete()
	            .verify(Duration.ofSeconds(1));
	assertThat(sp1.hasDownstreams()).isFalse();
}
 
Example 14
Source File: FluxWindowPredicateTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void normalWhileDoesntMatch() {
	FluxIdentityProcessor<Integer> sp1 = Processors.more().multicastNoBackpressure();
	FluxWindowPredicate<Integer> windowWhile = new FluxWindowPredicate<>(
			sp1, Queues.small(), Queues.unbounded(), Queues.SMALL_BUFFER_SIZE,
			i -> i > 4, Mode.WHILE);

	StepVerifier.create(windowWhile.flatMap(Flux::materialize))
	            .expectSubscription()
	            .expectNoEvent(Duration.ofMillis(10))
	            .then(() -> sp1.onNext(1))
	            .expectNext(Signal.complete())
	            .then(() -> sp1.onNext(2))
	            .expectNext(Signal.complete())
	            .then(() -> sp1.onNext(3))
	            .expectNext(Signal.complete())
	            .then(() -> sp1.onNext(4))
	            .expectNext(Signal.complete())
	            .expectNoEvent(Duration.ofMillis(10))
	            .then(() -> sp1.onNext(1))
	            .expectNext(Signal.complete())
	            .then(() -> sp1.onNext(2))
	            .expectNext(Signal.complete())
	            .then(() -> sp1.onNext(3))
	            .expectNext(Signal.complete())
	            .then(() -> sp1.onNext(4))
	            .expectNext(Signal.complete()) //closing window opened by 3
	            .expectNoEvent(Duration.ofMillis(10))
	            .then(sp1::onComplete)
	            //remainder window, not emitted
	            .expectComplete()
	            .verify(Duration.ofSeconds(1));
	assertThat(sp1.hasDownstreams()).isFalse();
}
 
Example 15
Source File: FluxWindowPredicateTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void predicateErrorWhile() {
	FluxIdentityProcessor<Integer> sp1 = Processors.more().multicastNoBackpressure();
	FluxWindowPredicate<Integer> windowWhile = new FluxWindowPredicate<>(
			sp1, Queues.small(), Queues.unbounded(), Queues.SMALL_BUFFER_SIZE,
			i -> {
				if (i == 3) return true;
				if (i == 5) throw new IllegalStateException("predicate failure");
				return false;
			}, Mode.WHILE);

	StepVerifier.create(windowWhile.flatMap(Flux::materialize))
				.expectSubscription()
				.then(() -> sp1.onNext(1)) //empty window
				.expectNext(Signal.complete())
				.then(() -> sp1.onNext(2)) //empty window
				.expectNext(Signal.complete())
				.then(() -> sp1.onNext(3)) //window opens
				.expectNext(Signal.next(3))
				.then(() -> sp1.onNext(4)) //previous window closes, new (empty) window
				.expectNext(Signal.complete())
				.then(() -> sp1.onNext(5)) //fails, the empty window receives onError
				//error in the window:
				.expectErrorMessage("predicate failure")
				.verify(Duration.ofMillis(100));
	assertThat(sp1.hasDownstreams()).isFalse();
}
 
Example 16
Source File: UnboundedProcessor.java    From rsocket-java with Apache License 2.0 4 votes vote down vote up
public UnboundedProcessor() {
  this.queue = new MpscUnboundedArrayQueue<>(Queues.SMALL_BUFFER_SIZE);
  this.priorityQueue = new MpscUnboundedArrayQueue<>(Queues.SMALL_BUFFER_SIZE);
}