reactor.util.concurrent.Queues Java Examples

The following examples show how to use reactor.util.concurrent.Queues. 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 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 #2
Source File: UnicastProcessorTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void bufferSizeReactorBoundedQueue() {
   	//the bounded queue floors at 8 and rounds to the next power of 2

	assertThat(UnicastProcessor.create(Queues.get(2).get())
	                           .getBufferSize())
			.isEqualTo(8);

	assertThat(UnicastProcessor.create(Queues.get(8).get())
	                           .getBufferSize())
			.isEqualTo(8);

	assertThat(UnicastProcessor.create(Queues.get(9).get())
	                           .getBufferSize())
			.isEqualTo(16);
}
 
Example #3
Source File: FluxMergeOrderedTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void mergeAdditionalSource() {
	Comparator<Integer> originalComparator = Comparator.naturalOrder();
	@SuppressWarnings("unchecked")
	FluxMergeOrdered<Integer> fmo = new FluxMergeOrdered<>(2,
			Queues.small(),
			originalComparator,
			Flux.just(1, 2),
			Flux.just(3, 4));

	FluxMergeOrdered<Integer> fmo2 = fmo.mergeAdditionalSource(Flux.just(5, 6), Comparator.naturalOrder());

	assertThat(fmo2).isNotSameAs(fmo);
	assertThat(fmo2.sources).startsWith(fmo.sources)
	                        .hasSize(3);
	assertThat(fmo.sources).hasSize(2);
	assertThat(fmo2.valueComparator)
			.as("same comparator detected and used")
			.isSameAs(originalComparator);

	StepVerifier.create(fmo2)
	            .expectNext(1, 2, 3, 4, 5, 6)
	            .verifyComplete();
}
 
Example #4
Source File: FluxWindowBoundaryTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanOtherSubscriber() {
    CoreSubscriber<Flux<Integer>> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
    FluxWindowBoundary.WindowBoundaryMain<Integer, Integer> main = new FluxWindowBoundary.WindowBoundaryMain<>(actual,
    		Queues.unbounded(), Queues.<Integer>unbounded().get());
    FluxWindowBoundary.WindowBoundaryOther<Integer> test =
    		new FluxWindowBoundary.WindowBoundaryOther<>(main);
    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);
    test.requested = 35;
    Assertions.assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(35);

    Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.cancel();
    Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
 
Example #5
Source File: FluxWindowTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #6
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 #7
Source File: BlockingIterableTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanSubscriberError() {
	BlockingIterable.SubscriberIterator<String> test = new BlockingIterable.SubscriberIterator<>(
			Queues.<String>one().get(),
			123);
	IllegalStateException error = new IllegalStateException("boom");

	assertThat(test.scan(Scannable.Attr.ERROR)).describedAs("before ERROR")
	                                                    .isNull();

	test.onError(error);

	assertThat(test.scan(Scannable.Attr.ERROR)).describedAs("after ERROR")
	                                                       .isSameAs(error);
	assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
}
 
Example #8
Source File: FluxConcatMapTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void discardDelayedOnNextQueueReject() {
	List<Object> discarded = new ArrayList<>();
	AssertSubscriber<Object> testSubscriber = new AssertSubscriber<>(
			Context.of(Hooks.KEY_ON_DISCARD, (Consumer<?>) discarded::add));
	final CoreSubscriber<Object> subscriber =
			FluxConcatMap.subscriber(testSubscriber,
					Mono::just,
					Queues.get(0),
					1,
					FluxConcatMap.ErrorMode.END);
	subscriber.onSubscribe(Operators.emptySubscription());

	subscriber.onNext(1);

	assertThat(discarded).containsExactly(1);
}
 
Example #9
Source File: FluxConcatMapTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void asyncFusionMapToNull() {
	AssertSubscriber<Integer> ts = AssertSubscriber.create();

	FluxIdentityProcessor<Integer> up = Processors.more().unicast(Queues.<Integer>get(2).get());
	up.onNext(1);
	up.onNext(2);
	up.onComplete();

	up.map(v -> v == 2 ? null : v)
	  .concatMap(Flux::just)
	  .subscribe(ts);

	ts.assertValues(1)
	  .assertError(NullPointerException.class)
	  .assertNotComplete();
}
 
Example #10
Source File: FluxConcatMapTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@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 #11
Source File: FluxSubscribeOnTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void forceScheduledRequests() {
	Flux<Integer> test = Flux.<Integer>create(sink -> {
		for (int i = 1; i < 1001; i++) {
			sink.next(i);
			try {
				Thread.sleep(1);
			}
			catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		sink.complete();
	}, DROP)
			.map(Function.identity())
			.subscribeOn(Schedulers.single(), true)
			.publishOn(Schedulers.boundedElastic());

	AtomicInteger count = new AtomicInteger();
	StepVerifier.create(test)
	            .thenConsumeWhile(t -> count.incrementAndGet() != -1)
	            .expectComplete()
	            .verify(Duration.ofSeconds(5));

	assertThat(count.get()).isEqualTo(Queues.SMALL_BUFFER_SIZE);
}
 
Example #12
Source File: FluxConcatMapTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void asyncFusionMapToNullFilter() {
	AssertSubscriber<Integer> ts = AssertSubscriber.create();

	FluxIdentityProcessor<Integer> up =
			Processors.more().unicast(Queues.<Integer>get(2).get());
	up.onNext(1);
	up.onNext(2);
	up.onComplete();

	up.map(v -> v == 2 ? null : v)
	  .filter(v -> true)
	  .concatMap(Flux::just)
	  .subscribe(ts);

	ts.assertValues(1)
	  .assertError(NullPointerException.class)
	  .assertNotComplete();
}
 
Example #13
Source File: FluxZipTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@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();
  }
 
Example #14
Source File: FluxSwitchMapTest.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);
    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();
}
 
Example #15
Source File: FluxGroupJoin.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
GroupJoinSubscription(CoreSubscriber<? super R> actual,
		Function<? super TLeft, ? extends Publisher<TLeftEnd>> leftEnd,
		Function<? super TRight, ? extends Publisher<TRightEnd>> rightEnd,
		BiFunction<? super TLeft, ? super Flux<TRight>, ? extends R> resultSelector,
		Supplier<? extends Queue<TRight>> processorQueueSupplier) {
	this.actual = actual;
	this.cancellations = Disposables.composite();
	this.processorQueueSupplier = processorQueueSupplier;
	this.queue = Queues.unboundedMultiproducer().get();
	this.queueBiOffer = (BiPredicate) queue;
	this.lefts = new LinkedHashMap<>();
	this.rights = new LinkedHashMap<>();
	this.leftEnd = leftEnd;
	this.rightEnd = rightEnd;
	this.resultSelector = resultSelector;
	ACTIVE.lazySet(this, 2);
}
 
Example #16
Source File: FluxGroupByTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@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 #17
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 #18
Source File: FluxWindowTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanOverlapSubscriber() {
    CoreSubscriber<Flux<Integer>> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
    FluxWindow.WindowOverlapSubscriber<Integer> test = new FluxWindow.WindowOverlapSubscriber<Integer>(actual,
    		123, 3, Queues.unbounded(), Queues.<FluxIdentityProcessor<Integer>>unbounded().get());
    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);
    test.requested = 35;
    Assertions.assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(35);
    test.onNext(2);
    Assertions.assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);

    Assertions.assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    Assertions.assertThat(test.scan(Scannable.Attr.ERROR)).isNull();
    test.onError(new IllegalStateException("boom"));
    Assertions.assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
    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();
}
 
Example #19
Source File: FluxWindowTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanSkipSubscriber() {
    CoreSubscriber<Flux<Integer>> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
    FluxWindow.WindowSkipSubscriber<Integer> test = new FluxWindow.WindowSkipSubscriber<Integer>(actual,
    		123, 3, 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();
}
 
Example #20
Source File: ParallelSourceTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@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 #21
Source File: FluxPublishTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@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();
  }
 
Example #22
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 #23
Source File: FluxPublishMulticastTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@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);
  }
 
Example #24
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 #25
Source File: FluxPublishOnTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
  public void scanSubscriber() throws InterruptedException {
      CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
      FluxPublishOn.PublishOnSubscriber<Integer> test = new FluxPublishOn.PublishOnSubscriber<>(actual,
      		Schedulers.single(), Schedulers.single().createWorker(), true, 123, 123, Queues.unbounded());
      Subscription parent = Operators.emptySubscription();
      test.onSubscribe(parent);

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

      assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
      test.onError(new IllegalStateException("boom"));
      assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
      assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();

      assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
      test.cancel();
      assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();

      //once cancelled, there shouldn't be any draining left
      // => better place to test that BUFFERED reflects the size of the queue
Thread.sleep(50); //"hiccup" to ensure cancellation / draining is done
      test.queue.add(1);
      test.queue.add(1);
      assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(2);
  }
 
Example #26
Source File: FluxBufferWhenTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void scanStartEndMainCancelled() {
	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.cancel();
	assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
 
Example #27
Source File: FluxMergeSequential.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
	if (Operators.setOnce(SUBSCRIPTION, this, s)) {
		if (s instanceof QueueSubscription) {
			@SuppressWarnings("unchecked")
			QueueSubscription<R> qs = (QueueSubscription<R>) s;

			int m = qs.requestFusion(Fuseable.ANY | Fuseable.THREAD_BARRIER);
			if (m == Fuseable.SYNC) {
				fusionMode = m;
				queue = qs;
				done = true;
				parent.innerComplete(this);
				return;
			}
			if (m == Fuseable.ASYNC) {
				fusionMode = m;
				queue = qs;
				s.request(Operators.unboundedOrPrefetch(prefetch));
				return;
			}
		}

		queue = Queues.<R>get(prefetch).get();
		s.request(Operators.unboundedOrPrefetch(prefetch));
	}
}
 
Example #28
Source File: FluxFlattenIterableTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@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 #29
Source File: EmitterProcessor.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(final Subscription s) {
	if (Operators.setOnce(S, this, s)) {
		if (s instanceof Fuseable.QueueSubscription) {
			@SuppressWarnings("unchecked") Fuseable.QueueSubscription<T> f =
					(Fuseable.QueueSubscription<T>) s;

			int m = f.requestFusion(Fuseable.ANY);
			if (m == Fuseable.SYNC) {
				sourceMode = m;
				queue = f;
				drain();
				return;
			}
			else if (m == Fuseable.ASYNC) {
				sourceMode = m;
				queue = f;
				s.request(Operators.unboundedOrPrefetch(prefetch));
				return;
			}
		}

		queue = Queues.<T>get(prefetch).get();

		s.request(Operators.unboundedOrPrefetch(prefetch));
	}
}
 
Example #30
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();
}