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

The following examples show how to use reactor.util.concurrent.Queues#unbounded() . 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 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 2
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 3
Source File: FluxPublishTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@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();
  }
 
Example 4
Source File: FluxPublishTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanSubscriber() {
    FluxPublish<Integer> main = new FluxPublish<>(Flux.just(1), 123, Queues.unbounded());
    FluxPublish.PublishSubscriber<Integer> test = new FluxPublish.PublishSubscriber<>(789, main);
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);

    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(789);
    test.queue.add(5);
    assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);

    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    assertThat(test.scan(Scannable.Attr.ERROR)).isNull();
    test.error = new IllegalArgumentException("boom");
    assertThat(test.scan(Scannable.Attr.ERROR)).isSameAs(test.error);
    test.onComplete();
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();

    test = new FluxPublish.PublishSubscriber<>(789, main);
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.onSubscribe(Operators.cancelledSubscription());
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
 
Example 5
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 6
Source File: FluxWindowWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
  public void scanMainSubscriberError() {
      CoreSubscriber<Flux<Integer>> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
      FluxWindowWhen.WindowWhenMainSubscriber<Integer, Integer, Integer> test =
      		new FluxWindowWhen.WindowWhenMainSubscriber<>(actual,
		        Flux.never(), Flux::just,
		        Queues.unbounded());
      Subscription parent = Operators.emptySubscription();
      test.onSubscribe(parent);

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.TERMINATED)).isTrue();
Assertions.assertThat(test.scan(Scannable.Attr.ERROR))
          .isNotNull()
          .hasMessage("boom");
  }
 
Example 7
Source File: FluxWindowTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanOverlapSubscriberLargeBuffered() {
 @SuppressWarnings("unchecked")
 Queue<FluxIdentityProcessor<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(Processors.unicast());
    test.offer(Processors.unicast());
    test.offer(Processors.unicast());
    test.offer(Processors.unicast());
    test.offer(Processors.unicast());

    assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(Integer.MIN_VALUE);
    assertThat(test.scan(Scannable.Attr.LARGE_BUFFERED)).isEqualTo(Integer.MAX_VALUE + 5L);
}
 
Example 8
Source File: FluxWindowTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanOverlapSubscriberSmallBuffered() {
 @SuppressWarnings("unchecked")
 Queue<FluxIdentityProcessor<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(Processors.unicast());

    assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(Integer.MAX_VALUE - 1);
    assertThat(test.scan(Scannable.Attr.LARGE_BUFFERED)).isEqualTo(Integer.MAX_VALUE - 1L);
}
 
Example 9
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 10
Source File: FluxWindowPredicateTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
  public void scanOtherSubscriber() {
      CoreSubscriber<Flux<Integer>> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
      FluxWindowPredicate.WindowPredicateMain<Integer> main = new FluxWindowPredicate.WindowPredicateMain<>(actual,
      		Queues.<Flux<Integer>>unbounded().get(), Queues.unbounded(), 123, i -> true, Mode.WHILE);
      FluxWindowPredicate.WindowFlux<Integer> test = new FluxWindowPredicate.WindowFlux<>(
      		Queues.<Integer>unbounded().get(), main);

      Subscription parent = Operators.emptySubscription();
      test.onSubscribe(parent);

Assertions.assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(main);
Assertions.assertThat(test.scan(Scannable.Attr.ACTUAL)).isNull(); // RS: TODO Need to make actual non-null
test.requested = 35;
Assertions.assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(35);
test.queue.offer(27);
Assertions.assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);

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.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 11
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 12
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 13
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 14
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 15
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 16
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 17
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 18
Source File: FluxPublishOnTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
  public void scanConditionalSubscriber() {
@SuppressWarnings("unchecked")
Fuseable.ConditionalSubscriber<Integer> actual = Mockito.mock(MockUtils.TestScannableConditionalSubscriber.class);
      FluxPublishOn.PublishOnConditionalSubscriber<Integer> test =
      		new FluxPublishOn.PublishOnConditionalSubscriber<>(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);
      test.queue.add(1);
      assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);

      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)).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();
  }
 
Example 19
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 20
Source File: FluxWindowWhenTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
  public void scanMainSubscriber() {
      CoreSubscriber<Flux<Integer>> actual = new LambdaSubscriber<>(null, e -> {}, null,
        sub -> sub.request(1));
      FluxWindowWhen.WindowWhenMainSubscriber<Integer, Integer, Integer> test =
      		new FluxWindowWhen.WindowWhenMainSubscriber<>(actual,
		        Flux.never(), Flux::just,
		        Queues.unbounded());
      Subscription parent = Operators.emptySubscription();
      test.onSubscribe(parent);

Assertions.assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);

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();

Assertions.assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM))
          .isEqualTo(0);
test.request(123L);
Assertions.assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM))
          .isEqualTo(123L);
  }