reactor.core.CoreSubscriber Java Examples

The following examples show how to use reactor.core.CoreSubscriber. 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: 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 #2
Source File: MonoDelayUntilTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanCoordinator() {
	CoreSubscriber<String> actual = new LambdaMonoSubscriber<>(null, e -> {}, null, null);
	@SuppressWarnings("unchecked")
	Function<? super String, ? extends Publisher<?>>[] otherGenerators = new Function[3];
	MonoDelayUntil.DelayUntilCoordinator<String> test = new MonoDelayUntil.DelayUntilCoordinator<>(actual, otherGenerators);
	Subscription subscription = Operators.emptySubscription();
	test.onSubscribe(subscription);

	assertThat(test.scan(Scannable.Attr.PARENT)).isNull();
	assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
	assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);

	assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
	test.done = 2;
	assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
	test.done = 3;
	assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();

	assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
	test.cancel();
	assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
 
Example #3
Source File: MonoDeferWithContext.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Override
public void subscribe(CoreSubscriber<? super T> actual) {
	Mono<? extends T> p;

	Context ctx = actual.currentContext();
	try {
		p = Objects.requireNonNull(supplier.apply(ctx),
				"The Mono returned by the supplier is null");
	}
	catch (Throwable e) {
		Operators.error(actual, Operators.onOperatorError(e, ctx));
		return;
	}

	p.subscribe(actual);
}
 
Example #4
Source File: MonoDelay.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Override
public void subscribe(CoreSubscriber<? super Long> actual) {
	MonoDelayRunnable r = new MonoDelayRunnable(actual);

	actual.onSubscribe(r);

	try {
		r.setCancel(timedScheduler.schedule(r, delay, unit));
	}
	catch (RejectedExecutionException ree) {
		if(r.cancel != OperatorDisposables.DISPOSED) {
			actual.onError(Operators.onRejectedExecution(ree, r, null, null,
					actual.currentContext()));
		}
	}
}
 
Example #5
Source File: WingtipsSpringWebfluxWebFilterTest.java    From wingtips with Apache License 2.0 6 votes vote down vote up
@Test
public void WingtipsWebFilterTracingSubscriber_constructor_sets_fields_as_expected() {
    // given
    @SuppressWarnings("unchecked")
    CoreSubscriber<Void> actualSubscriberMock = mock(CoreSubscriber.class);
    Context subscriberContextMock = mock(Context.class);
    TracingState tracingStateMock = mock(TracingState.class);

    // when
    WingtipsWebFilterTracingSubscriber impl =
        new WingtipsWebFilterTracingSubscriber(
            actualSubscriberMock, exchange, subscriberContextMock, tracingStateMock,
            tagAndNamingStrategy, tagAndNamingAdapterMock
        );

    // then
    assertThat(impl.actual).isSameAs(actualSubscriberMock);
    assertThat(impl.exchange).isSameAs(exchange);
    assertThat(impl.subscriberContext).isSameAs(subscriberContextMock);
    assertThat(impl.overallRequestTracingState).isSameAs(tracingStateMock);
    assertThat(impl.tagAndNamingStrategy).isSameAs(tagAndNamingStrategy);
    assertThat(impl.tagAndNamingAdapter).isSameAs(tagAndNamingAdapterMock);
}
 
Example #6
Source File: ParallelPeek.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void subscribe(CoreSubscriber<? super T>[] subscribers) {
	if (!validate(subscribers)) {
		return;
	}
	
	int n = subscribers.length;

	CoreSubscriber<? super T>[] parents = new CoreSubscriber[n];

	boolean conditional = subscribers[0] instanceof Fuseable.ConditionalSubscriber;

	for (int i = 0; i < n; i++) {
		if (conditional) {
			parents[i] = new FluxPeekFuseable.PeekConditionalSubscriber<>(
					(Fuseable.ConditionalSubscriber<T>)subscribers[i], this);
		}
		else {
			parents[i] = new FluxPeek.PeekSubscriber<>(subscribers[i], this);
		}
	}
	
	source.subscribe(parents);
}
 
Example #7
Source File: FluxExpandTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanExpandBreathSubscriber() {
	CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null,
			Throwable::printStackTrace, null,null);
	ExpandBreathSubscriber<Integer> test = new ExpandBreathSubscriber<>(actual,
			i -> i > 5 ? Mono.empty() : Mono.just(i + 1), 123);

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

	assertThat(test.scan(Scannable.Attr.PARENT)).isEqualTo(s);
	assertThat(test.scan(Scannable.Attr.ACTUAL)).isEqualTo(actual);

	test.request(3);
	assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(3);

	assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(0);
	test.onNext(1);
	assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);

	assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
	test.cancel();
	assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
 
Example #8
Source File: FluxBufferPredicateTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanMain() {
	CoreSubscriber<? super List> actual = new LambdaSubscriber<>(null, e -> {}, null,
			sub -> sub.request(100));
	List<String> initialBuffer = Arrays.asList("foo", "bar");
	FluxBufferPredicate.BufferPredicateSubscriber<String, List<String>> test = new FluxBufferPredicate.BufferPredicateSubscriber<>(
			actual, initialBuffer, ArrayList::new, s -> s.length() < 5,
			FluxBufferPredicate.Mode.WHILE
	);
	Subscription parent = Operators.emptySubscription();
	test.onSubscribe(parent);

	assertThat(test.scan(Scannable.Attr.CAPACITY)).isEqualTo(2);
	assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(100L);
	assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
	assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);

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

	assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
	test.onError(new IllegalStateException("boom"));
	assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
}
 
Example #9
Source File: WingtipsSpringWebfluxExchangeFilterFunction.java    From wingtips with Apache License 2.0 6 votes vote down vote up
@Override
public void subscribe(
    @NotNull CoreSubscriber<? super ClientResponse> actual
) {
    // The request will be kicked off as part of the source.subscribe(...) call, so wrap it in
    //      a runnableWithTracing(...) so it has the correct tracing state.
    runnableWithTracing(
        () -> {
            // Wrap the actual subscriber with a WingtipsExchangeFilterFunctionTracingCompletionSubscriber
            //      in order to complete the subspan when the source Mono finishes.
            source.subscribe(
                new WingtipsExchangeFilterFunctionTracingCompletionSubscriber(
                    actual,
                    request,
                    actual.currentContext(),
                    spanAroundCallTracingState,
                    tagAndNamingStrategy,
                    tagAndNamingAdapter
                )
            );
        },
        spanAroundCallTracingState
    ).run();
}
 
Example #10
Source File: FluxFilterWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanSubscriber() {
    CoreSubscriber<String> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
    FluxFilterWhen.FluxFilterWhenSubscriber<String> test = new FluxFilterWhen.FluxFilterWhenSubscriber<>(actual, t -> Mono.just(true), 789);
    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.TERMINATED)).isFalse();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(Long.MAX_VALUE);
    assertThat(test.scan(Scannable.Attr.CAPACITY)).isEqualTo(1024); // next power of 2 of 789
    assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(0);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(789);

    test.error = new IllegalStateException("boom");
    assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
}
 
Example #11
Source File: MonoFlatMapTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanInner() {
	CoreSubscriber<Integer> actual = new LambdaMonoSubscriber<>(null, e -> {}, null, null);
	MonoFlatMap.FlatMapMain<String, Integer> main = new MonoFlatMap.FlatMapMain<>(actual, s
			-> Mono.just(s.length()));
	MonoFlatMap.FlatMapInner<Integer> test = new MonoFlatMap.FlatMapInner<>(main);
	Subscription innerSubscription = Operators.emptySubscription();
	test.onSubscribe(innerSubscription);

	assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(innerSubscription);
	assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(main);
	assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
	assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();

	test.onError(new IllegalStateException("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 #12
Source File: FluxBufferBoundary.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Override
public CoreSubscriber<? super T> subscribeOrReturn(CoreSubscriber<? super C> actual) {
	C buffer = Objects.requireNonNull(bufferSupplier.get(),
			"The bufferSupplier returned a null buffer");

	BufferBoundaryMain<T, U, C> parent =
			new BufferBoundaryMain<>(
					source instanceof FluxInterval ?
							actual : Operators.serialize(actual),
					buffer, bufferSupplier);

	actual.onSubscribe(parent);

	other.subscribe(parent.other);

	return parent;
}
 
Example #13
Source File: FluxDefer.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void subscribe(CoreSubscriber<? super T> actual) {
	Publisher<? extends T> p;

	try {
		p = Objects.requireNonNull(supplier.get(),
				"The Publisher returned by the supplier is null");
	}
	catch (Throwable e) {
		Operators.error(actual, Operators.onOperatorError(e, actual.currentContext()));
		return;
	}

	from(p).subscribe(actual);
}
 
Example #14
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 #15
Source File: ParallelGroup.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void subscribe(CoreSubscriber<? super GroupedFlux<Integer, T>> actual) {
	int n = source.parallelism();

	@SuppressWarnings("unchecked")
	ParallelInnerGroup<T>[] groups = new ParallelInnerGroup[n];

	for (int i = 0; i < n; i++) {
		groups[i] = new ParallelInnerGroup<>(i);
	}

	FluxArray.subscribe(actual, groups);

	source.subscribe(groups);
}
 
Example #16
Source File: DefaultRSocketClient.java    From rsocket-java with Apache License 2.0 5 votes vote down vote up
@Override
public void subscribe(CoreSubscriber<? super Payload> actual) {
  if (requestType == FrameType.REQUEST_CHANNEL) {
    RequestChannelInner inner =
        new RequestChannelInner(this.parent, source, actual, requestType);
    actual.onSubscribe(inner);
    this.parent.observe(inner);
  } else {
    this.source.subscribe(new FlatMapMain<>(this.parent, actual, this.requestType));
  }
}
 
Example #17
Source File: FluxPeek.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public CoreSubscriber<? super T> subscribeOrReturn(CoreSubscriber<? super T> actual) {
	if (actual instanceof ConditionalSubscriber) {
		@SuppressWarnings("unchecked") // javac, give reason to suppress because inference anomalies
				ConditionalSubscriber<T> s2 = (ConditionalSubscriber<T>) actual;
		return new PeekConditionalSubscriber<>(s2, this);
	}
	return new PeekSubscriber<>(actual, this);
}
 
Example #18
Source File: FluxRepeatWhen.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public CoreSubscriber<? super T> subscribeOrReturn(CoreSubscriber<? super T> actual) {
	RepeatWhenOtherSubscriber other = new RepeatWhenOtherSubscriber();
	Subscriber<Long> signaller = Operators.serialize(other.completionSignal);

	signaller.onSubscribe(Operators.emptySubscription());

	CoreSubscriber<T> serial = Operators.serialize(actual);

	RepeatWhenMainSubscriber<T> main =
			new RepeatWhenMainSubscriber<>(serial, signaller, source);
	other.main = main;

	serial.onSubscribe(main);

	Publisher<?> p;

	try {
		p = Objects.requireNonNull(whenSourceFactory.apply(other),
				"The whenSourceFactory returned a null Publisher");
	}
	catch (Throwable e) {
		actual.onError(Operators.onOperatorError(e, actual.currentContext()));
		return null;
	}

	p.subscribe(other);

	if (!main.cancelled) {
		return main;
	}
	else {
		return null;
	}
}
 
Example #19
Source File: FluxFilterWhenTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void scanSmallBuffered() {
    CoreSubscriber<String> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
    FluxFilterWhen.FluxFilterWhenSubscriber<String> test = new FluxFilterWhen.FluxFilterWhenSubscriber<>(actual, t -> Mono.just(true), 789);

    test.producerIndex = Integer.MAX_VALUE + 5L;
    test.consumerIndex = Integer.MAX_VALUE + 2L;
    assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(3);
    assertThat(test.scan(Scannable.Attr.LARGE_BUFFERED)).isEqualTo(3L);
}
 
Example #20
Source File: FluxHideTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
  public void scanSubscriber() {
CoreSubscriber<String> actual = new LambdaSubscriber<>(null, e -> {}, null, null);
      FluxHide.HideSubscriber<String> test = new FluxHide.HideSubscriber<>(actual);
      Subscription parent = Operators.emptySubscription();
      test.onSubscribe(parent);

      assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
      assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
  }
 
Example #21
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);
  }
 
Example #22
Source File: FluxCreate.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void subscribe(CoreSubscriber<? super T> actual) {
	BaseSink<T> sink = createSink(actual, backpressure);

	actual.onSubscribe(sink);
	try {
		source.accept(
				createMode == CreateMode.PUSH_PULL ? new SerializedSink<>(sink) :
						sink);
	}
	catch (Throwable ex) {
		Exceptions.throwIfFatal(ex);
		sink.error(Operators.onOperatorError(ex, actual.currentContext()));
	}
}
 
Example #23
Source File: FluxScanSeed.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public CoreSubscriber<? super T> subscribeOrReturn(CoreSubscriber<? super R> actual) {
	ScanSeedCoordinator<T, R> coordinator =
			new ScanSeedCoordinator<>(actual, source, accumulator, initialSupplier);

	actual.onSubscribe(coordinator);

	if (!coordinator.isCancelled()) {
		coordinator.onComplete();
	}
	return null;
}
 
Example #24
Source File: MonoMapFuseable.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public CoreSubscriber<? super T> subscribeOrReturn(CoreSubscriber<? super R> actual) {
	if (actual instanceof ConditionalSubscriber) {
		ConditionalSubscriber<? super R> cs = (ConditionalSubscriber<? super R>) actual;
		return new FluxMapFuseable.MapFuseableConditionalSubscriber<>(cs, mapper);
	}
	return new FluxMapFuseable.MapFuseableSubscriber<>(actual, mapper);
}
 
Example #25
Source File: DefaultRSocketClient.java    From rsocket-java with Apache License 2.0 5 votes vote down vote up
RequestChannelInner(
    DefaultRSocketClient parent,
    Publisher<Payload> upstream,
    CoreSubscriber<? super Payload> actual,
    FrameType interactionType) {
  super(parent, actual);

  this.upstream = upstream;
  this.interactionType = interactionType;
}
 
Example #26
Source File: FluxDelaySequence.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
DelaySubscriber(CoreSubscriber<? super T> actual, Duration delay, Scheduler.Worker w) {
	super();
	this.actual = new SerializedSubscriber<>(actual);
	this.w = w;
	this.delay = delay.toNanos();
	this.timeUnit = TimeUnit.NANOSECONDS;
}
 
Example #27
Source File: TracingClientResponseSubscriber.java    From java-spring-web with Apache License 2.0 5 votes vote down vote up
TracingClientResponseSubscriber(
        final CoreSubscriber<? super ClientResponse> subscriber,
        final ClientRequest clientRequest,
        final Context context,
        final Span span,
        final List<WebClientSpanDecorator> spanDecorators
) {
    this.subscriber = subscriber;
    this.clientRequest = clientRequest;
    this.context = context.put(Span.class, span);
    this.span = span;
    this.spanDecorators = spanDecorators;
}
 
Example #28
Source File: ParallelGroupTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void scanInnerGroupRequestNotTrackedWhenParent() {
	ParallelInnerGroup<Integer> test = new ParallelInnerGroup<>(1023);

	CoreSubscriber<Integer> subscriber = new LambdaSubscriber<>(null, e -> {}, null,
			sub -> sub.request(3));
	Subscription s = Operators.emptySubscription();
	test.onSubscribe(s);
	test.subscribe(subscriber);

	assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isZero();
	test.request(2);
	assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isZero();
}
 
Example #29
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 #30
Source File: SubscribeOnlyOnceLifter.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public CoreSubscriber<? super T> apply(Scannable scannable, CoreSubscriber<? super T> coreSubscriber) {
    return new CoreSubscriber<T>() {
        @Override
        public void onSubscribe(Subscription subscription) {
            if (!compareAndSet(false, true)) {
                throw new NullPointerException("You cannot directly subscribe to a gRPC service multiple times " +
                        "concurrently. Use Flux.share() instead.");
            } else {
                coreSubscriber.onSubscribe(subscription);
            }
        }

        @Override
        public void onNext(T t) {
            coreSubscriber.onNext(t);
        }

        @Override
        public void onError(Throwable throwable) {
            coreSubscriber.onError(throwable);
        }

        @Override
        public void onComplete() {
            coreSubscriber.onComplete();
        }
    };
}