Java Code Examples for reactor.test.StepVerifier#Step

The following examples show how to use reactor.test.StepVerifier#Step . 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: OperatorScenario.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
final StepVerifier.Step<O> applySteps(int start,
		int stop,
		StepVerifier.Step<O> step) {
	if (stop <= start) {
		return step;
	}

	if (receivers != null) {
		for (int i = start; i < receivers.length; i++) {
			step = step.assertNext(receivers[i]);
			if (i == stop - 1) {
				return step;
			}
		}
	}
	else if (receiverValues != null) {
		for (int i = start; i < receiverValues.length; i++) {
			step = step.expectNext(receiverValues[i]);
			if (i == stop - 1) {
				return step;
			}
		}
	}

	return step;
}
 
Example 2
Source File: BaseOperatorTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
final StepVerifier.Step<O> inputConditionalError(OperatorScenario<I, PI, O, PO> scenario) {
	TestPublisher<I> ts =
			TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE);
	return StepVerifier.create(scenario.body()
	                                   .apply(withFluxSource(ts.flux())))
	                   .then(() -> {
		                   ts.error(exception());

		                   //verify drop path
		                   if (scenario.shouldHitDropErrorHookAfterTerminate()) {
			                   ts.complete();
			                   ts.error(scenario.droppedError);
		                   }
		                   if (scenario.shouldHitDropNextHookAfterTerminate()) {
			                   ts.next(scenario.droppedItem);
		                   }
	                   });
}
 
Example 3
Source File: SwitchOnFirstIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void SwitchOnFirstWorksAsExpected() {
    serverRule.getServiceRegistry().addService(svc);
    ReactorSkipGreeterGrpc.ReactorSkipGreeterStub stub = ReactorSkipGreeterGrpc.newReactorStub(serverRule.getChannel());

    StepVerifier.Step<String> stepVerifier = StepVerifier.create(
        stub.skipGreet(
            Flux.just(
                Frame.newBuilder().setConfig(Config.newBuilder().setSkip(3).build()).build(),
                Frame.newBuilder().setPayload(Payload.newBuilder().setName("Andy").build()).build(),
                Frame.newBuilder().setPayload(Payload.newBuilder().setName("Brad").build()).build(),
                Frame.newBuilder().setPayload(Payload.newBuilder().setName("Charles").build()).build(),
                Frame.newBuilder().setPayload(Payload.newBuilder().setName("Diane").build()).build(),
                Frame.newBuilder().setPayload(Payload.newBuilder().setName("Edith").build()).build()
            ))
            .map(Greeting::getMessage)
            .doOnNext(System.out::println));

    stepVerifier
            .expectNext("Hello Diane")
            .expectNext("Hello Edith")
            .verifyComplete();
}
 
Example 4
Source File: BaseOperatorTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
final StepVerifier.Step<O> inputHiddenErrorOutputConditional(OperatorScenario<I, PI, O, PO> scenario) {
	TestPublisher<I> ts =
			TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE);
	return StepVerifier.create(scenario.body()
	                                   .andThen(this::conditional)
	                                   .apply(hide(withFluxSource(ts.flux()))))
	                   .then(() -> {
		                   ts.error(exception());

		                   //verify drop path
		                   if (scenario.shouldHitDropNextHookAfterTerminate()) {
			                   ts.next(scenario.droppedItem);
		                   }
		                   if (scenario.shouldHitDropErrorHookAfterTerminate()) {
			                   ts.complete();
			                   ts.error(scenario.droppedError);
		                   }
	                   });
}
 
Example 5
Source File: EndToEndIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void manyToOne() throws Exception {
    ReactorGreeterGrpc.ReactorGreeterStub stub = ReactorGreeterGrpc.newReactorStub(channel);
    Flux<HelloRequest> req = Flux.just(
            HelloRequest.newBuilder().setName("a").build(),
            HelloRequest.newBuilder().setName("b").build(),
            HelloRequest.newBuilder().setName("c").build());

    if (!expectFusion) {
        req = req.hide();
    }

    Mono<HelloResponse> resp = req.as(stub::sayHelloReqStream);

    StepVerifier.Step<String> stepVerifier = StepVerifier.create(resp.map(HelloResponse::getMessage));

    if (expectFusion) {
        stepVerifier = ((StepVerifier.FirstStep<String>) stepVerifier).expectFusion();
    }

    stepVerifier
            .expectNext("Hello a and b and c")
            .verifyComplete();
}
 
Example 6
Source File: ClientThreadIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void manyToMany() {
    ReactorGreeterGrpc.ReactorGreeterStub stub = ReactorGreeterGrpc.newReactorStub(channel);
    Flux<HelloRequest> req = Flux.just(
            HelloRequest.newBuilder().setName("a").build(),
            HelloRequest.newBuilder().setName("b").build(),
            HelloRequest.newBuilder().setName("c").build(),
            HelloRequest.newBuilder().setName("d").build(),
            HelloRequest.newBuilder().setName("e").build());

    if (!expectFusion) {
        req = req.hide();
    }

    Flux<HelloResponse> resp = req.transform(stub::sayHelloBothStream);

    AtomicReference<String> clientThreadName = new AtomicReference<>();

    StepVerifier.Step<String> stepVerifier = StepVerifier.create(
        resp
            .map(HelloResponse::getMessage)
            .doOnNext(x -> clientThreadName.set(Thread.currentThread().getName()))
    );

    if (expectFusion) {
        stepVerifier = ((StepVerifier.FirstStep<String>) stepVerifier).expectFusion();
    }

    stepVerifier
            .expectNext("Hello a and b", "Hello c and d", "Hello e")
            .verifyComplete();

    assertThat(clientThreadName.get()).isEqualTo("TheGrpcClient");
    assertThat(service.serverThreadName.get()).isEqualTo("TheGrpcServer");
}
 
Example 7
Source File: BaseOperatorTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
final StepVerifier.Step<O> inputHiddenOutputConditionalTryNext(OperatorScenario<I, PI, O, PO> scenario) {
	return StepVerifier.create(scenario.body()
	                                   .andThen(this::conditional)
	                                   .apply(anySourceHidden(scenario)),
			Math.max(scenario.producerCount(), scenario.receiverCount()))
	                   .consumeSubscriptionWith(s -> s.request(0));
}
 
Example 8
Source File: BaseOperatorTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
final StepVerifier.Step<O> inputConditionalOutputConditional(OperatorScenario<I, PI, O, PO> scenario) {
	TestPublisher<I> ts = TestPublisher.create();

	return StepVerifier.create(scenario.body()
	                                   .andThen(this::conditional)
	                                   .apply(withFluxSource(ts.flux())))
	                   .then(() -> testPublisherSource(scenario, ts));

}
 
Example 9
Source File: ServerErrorUpstreamCancellationIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void serverErrorSignalsUpstreamCancellationBidi() {
    serverRule.getServiceRegistry().addService(service);
    ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel());

    AtomicBoolean upstreamCancel = new AtomicBoolean(false);

    Flux<NumberProto.Number> requestFlux = Flux.range(0, Integer.MAX_VALUE)
                                               .map(this::protoNum)
                                               .doOnCancel(() -> upstreamCancel.set(true));

    if (!expectFusion) {
        requestFlux = requestFlux.hide();
    }

    Flux<NumberProto.Number> subscriber = requestFlux
                                              .transform(stub::twoWayPressure)
                                              .doOnNext(i -> System.out.println(i.getNumber(0)));

    StepVerifier.Step<NumberProto.Number> stepVerifier = StepVerifier.create(subscriber);

    if (expectFusion) {
        stepVerifier = ((StepVerifier.FirstStep<NumberProto.Number>) stepVerifier).expectFusion();
    }

    stepVerifier
            .verifyError(StatusRuntimeException.class);

    assertThat(upstreamCancel.get()).isTrue();
}
 
Example 10
Source File: ServerErrorUpstreamCancellationIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void serverErrorSignalsUpstreamCancellationManyToOne() {
    serverRule.getServiceRegistry().addService(service);
    ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel());

    AtomicBoolean upstreamCancel = new AtomicBoolean(false);

    Flux<NumberProto.Number> requestFlux = Flux.range(0, Integer.MAX_VALUE)
                                               .map(this::protoNum)
                                               .doOnCancel(() -> upstreamCancel.set(true));

    if (!expectFusion) {
        requestFlux = requestFlux.hide();
    }

    Mono<NumberProto.Number> observer = requestFlux
                                            .as(stub::requestPressure)
                                            .doOnError(System.out::println)
                                            .doOnSuccess(i -> System.out.println(i.getNumber(0)));

    StepVerifier.Step<NumberProto.Number> stepVerifier = StepVerifier.create(observer);

    if (expectFusion) {
        stepVerifier = ((StepVerifier.FirstStep<NumberProto.Number>) stepVerifier).expectFusion();
    }

    stepVerifier
            .verifyError(StatusRuntimeException.class);

    assertThat(upstreamCancel.get()).isTrue();
}
 
Example 11
Source File: EndToEndIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void manyToMany() throws Exception {
    ReactorGreeterGrpc.ReactorGreeterStub stub = ReactorGreeterGrpc.newReactorStub(channel);
    Flux<HelloRequest> req = Flux.just(
            HelloRequest.newBuilder().setName("a").build(),
            HelloRequest.newBuilder().setName("b").build(),
            HelloRequest.newBuilder().setName("c").build(),
            HelloRequest.newBuilder().setName("d").build(),
            HelloRequest.newBuilder().setName("e").build());

    if (!expectFusion) {
        req = req.hide();
    }

    Flux<HelloResponse> resp = req.transform(stub::sayHelloBothStream);



    StepVerifier.Step<String> stepVerifier = StepVerifier.create(resp.map(HelloResponse::getMessage));

    if (expectFusion) {
        stepVerifier = ((StepVerifier.FirstStep<String>) stepVerifier).expectFusion();
    }

    stepVerifier
            .expectNext("Hello a and b", "Hello c and d", "Hello e")
            .verifyComplete();
}
 
Example 12
Source File: BackpressureIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void bidiRequestBackpressure() {
    serverRule.getServiceRegistry().addService(service);

    ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel());

    Flux<NumberProto.Number> reactorRequest = Flux
            .fromIterable(IntStream.range(0, NUMBER_OF_STREAM_ELEMENTS)::iterator)
            .doOnNext(i -> System.out.println(i + " --> "))
            .doOnNext(i -> updateNumberOfWaits(lastValueTime, numberOfWaits))
            .map(BackpressureIntegrationTest::protoNum);

    if (!expectFusion) {
        reactorRequest = reactorRequest.hide();
    }

    Flux<NumberProto.Number> reactorResponse = reactorRequest.transform(stub::twoWayRequestPressure);

    StepVerifier.Step<NumberProto.Number> stepVerifier = StepVerifier.create(reactorResponse);

    if (expectFusion) {
        stepVerifier = ((StepVerifier.FirstStep<NumberProto.Number>) stepVerifier).expectFusion();
    }

    stepVerifier
            .expectNextMatches(v -> v.getNumber(0) == NUMBER_OF_STREAM_ELEMENTS - 1)
            .expectComplete()
            .verify(Duration.ofSeconds(15));

    assertThat(numberOfWaits.get()).isGreaterThan(0L);
}
 
Example 13
Source File: BackpressureIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void clientToServerBackpressure() {
    serverRule.getServiceRegistry().addService(service);

    ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel());

    Flux<NumberProto.Number> reactorRequest = Flux
            .fromIterable(IntStream.range(0, NUMBER_OF_STREAM_ELEMENTS)::iterator)
            .doOnNext(i -> System.out.println(i + " --> "))
            .doOnNext(i -> updateNumberOfWaits(lastValueTime, numberOfWaits))
            .map(BackpressureIntegrationTest::protoNum);

    if (!expectFusion) {
        reactorRequest = reactorRequest.hide();
    }

    Mono<NumberProto.Number> reactorResponse = reactorRequest.as(stub::requestPressure);

    StepVerifier.Step<NumberProto.Number> stepVerifier = StepVerifier.create(reactorResponse);

    if (expectFusion) {
        stepVerifier = ((StepVerifier.FirstStep<NumberProto.Number>) stepVerifier).expectFusion();
    }

    stepVerifier
                .expectNextMatches(v -> v.getNumber(0) == NUMBER_OF_STREAM_ELEMENTS - 1)
                .expectComplete()
                .verify(Duration.ofSeconds(15));

    assertThat(numberOfWaits.get()).isGreaterThan(0L);
}
 
Example 14
Source File: BaseOperatorTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
final StepVerifier.Step<O> inputFusedSyncErrorOutputFusedSync(OperatorScenario<I, PI, O, PO> scenario) {
	return StepVerifier.create(scenario.body()
	                                   .apply(Flux.just(item(0), item(1))
	                                              .as(f -> withFluxSource(new FluxFuseableExceptionOnPoll<>(
			                                              f,
			                                              exception())))))
	                   .expectFusion(scenario.fusionMode() & SYNC);
}
 
Example 15
Source File: BaseOperatorTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
final StepVerifier.Step<O> inputFusedConditionalOutputConditionalTryNext(OperatorScenario<I, PI, O, PO> scenario) {
	return StepVerifier.create(scenario.body()
	                                   .andThen(this::conditional)
	                                   .apply(anySource(scenario)),
			Math.max(scenario.producerCount(), scenario.receiverCount()))
	                   .consumeSubscriptionWith(s -> s.request(0));
}
 
Example 16
Source File: BaseOperatorTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
final StepVerifier.Step<O> inputFusedAsyncErrorOutputFusedAsync(OperatorScenario<I, PI, O, PO> scenario) {
	FluxIdentityProcessor<I> up = Processors.unicast();
	up.onNext(item(0));
	return StepVerifier.create(scenario.body()
	                                   .apply(up.as(f -> withFluxSource(new FluxFuseableExceptionOnPoll<>(
			                                   f,
			                                   exception())))))
	                   .expectFusion(scenario.fusionMode() & ASYNC);
}
 
Example 17
Source File: OperatorScenario.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
final StepVerifier.Step<O> applySteps(StepVerifier.Step<O> step) {
	return applySteps(0, Integer.MAX_VALUE, step);
}
 
Example 18
Source File: OperatorScenario.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Nullable
final Consumer<StepVerifier.Step<O>> verifier() {
	return verifier;
}
 
Example 19
Source File: CancellationPropagationIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void serverCanCancelClientStreamImplicitly() {
    serverRule.getServiceRegistry().addService(service);

    ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel());

    service.setExplicitCancel(false);

    AtomicBoolean requestWasCanceled = new AtomicBoolean(false);
    AtomicBoolean requestDidProduce = new AtomicBoolean(false);

    Flux<NumberProto.Number> request = Flux
            .fromIterable(IntStream.range(0, NUMBER_OF_STREAM_ELEMENTS)::iterator)
            .delayElements(Duration.ofMillis(SEQUENCE_DELAY_MILLIS))
            .map(CancellationPropagationIntegrationTest::protoNum)
            .doOnNext(x -> {
                requestDidProduce.set(true);
                System.out.println("Produced: " + x.getNumber(0));
            })
            .doOnCancel(() -> {
                requestWasCanceled.set(true);
                System.out.println("Client canceled");
            });

    if (!expectFusion) {
        request = request.hide();
    }

    Mono<NumberProto.Number> observer = request.as(stub::requestPressure)
            .doOnSuccess(number -> System.out.println(number.getNumber(0)))
            .doOnError(throwable -> System.out.println(throwable.getMessage()));

    StepVerifier.Step<NumberProto.Number> stepVerifier = StepVerifier.create(observer);

    if (expectFusion) {
        stepVerifier = ((StepVerifier.FirstStep<NumberProto.Number>) stepVerifier).expectFusion();
    }

    stepVerifier
            .expectNext(protoNum(9))
            .verifyComplete();

    await().atMost(org.awaitility.Duration.FIVE_HUNDRED_MILLISECONDS).untilTrue(requestWasCanceled);

    assertThat(requestWasCanceled.get()).isTrue();
    assertThat(requestDidProduce.get()).isTrue();
}
 
Example 20
Source File: BaseOperatorTest.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
final StepVerifier.Step<O> inputConditionalTryNext(OperatorScenario<I, PI, O, PO> scenario) {
	TestPublisher<I> ts = TestPublisher.create();

	return StepVerifier.create(scenario.body().apply(withFluxSource(ts.flux())), Math.max(scenario.producerCount(), scenario.receiverCount()))
	                   .then(() -> testPublisherSource(scenario, ts));
}