Java Code Examples for reactor.core.publisher.Mono#transform()

The following examples show how to use reactor.core.publisher.Mono#transform() . 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: ClientThreadIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void oneToOne() {
    ReactorGreeterGrpc.ReactorGreeterStub stub = ReactorGreeterGrpc.newReactorStub(channel);
    Mono<HelloRequest> req = Mono.just(HelloRequest.newBuilder().setName("reactorjava").build());

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

    Mono<HelloResponse> resp = req.transform(stub::sayHello);

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

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

    stepVerifier
            .expectNext("Hello reactorjava")
            .verifyComplete();

    assertThat(clientThreadName.get()).isEqualTo("TheGrpcClient");
    assertThat(service.serverThreadName.get()).isEqualTo("TheGrpcServer");
}
 
Example 2
Source File: UnaryZeroMessageResponseIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void zeroMessageResponseOneToOne() {
    serverRule.getServiceRegistry().addService(new MissingUnaryResponseService());

    ReactorGreeterGrpc.ReactorGreeterStub stub = ReactorGreeterGrpc.newReactorStub(serverRule.getChannel());
    Mono<HelloRequest> req = Mono.just(HelloRequest.newBuilder().setName("reactor").build());
    Mono<HelloResponse> resp = req.transform(stub::sayHello);

    StepVerifier.create(resp).verifyErrorMatches(t ->
            t instanceof StatusRuntimeException &&
            ((StatusRuntimeException) t).getStatus().getCode() == Status.Code.CANCELLED);
}
 
Example 3
Source File: UnaryZeroMessageResponseIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void reactorZeroMessageResponseOneToOne() {
    serverRule.getServiceRegistry().addService(new ReactorMissingUnaryResponseService());

    ReactorGreeterGrpc.ReactorGreeterStub stub = ReactorGreeterGrpc.newReactorStub(serverRule.getChannel());
    Mono<HelloRequest> req = Mono.just(HelloRequest.newBuilder().setName("reactor").build());
    Mono<HelloResponse> resp = req.transform(stub::sayHello);

    StepVerifier.create(resp).verifyErrorMatches(t ->
            t instanceof StatusRuntimeException &&
                    ((StatusRuntimeException) t).getStatus().getCode() == Status.Code.CANCELLED);
}
 
Example 4
Source File: EndToEndIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void oneToOne() throws IOException {
    ReactorGreeterGrpc.ReactorGreeterStub stub = ReactorGreeterGrpc.newReactorStub(channel);
    Mono<HelloRequest> req = Mono.just(HelloRequest.newBuilder().setName("reactorjava").build());
    Mono<HelloResponse> resp = req.transform(stub::sayHello);

    StepVerifier.create(resp.map(HelloResponse::getMessage))
            .expectNext("Hello reactorjava")
            .verifyComplete();
}
 
Example 5
Source File: ReactiveSentinelCircuitBreaker.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
@Override
public <T> Mono<T> run(Mono<T> toRun, Function<Throwable, Mono<T>> fallback) {
	Mono<T> toReturn = toRun.transform(new SentinelReactorTransformer<>(
			new EntryConfig(resourceName, entryType)));
	if (fallback != null) {
		toReturn = toReturn.onErrorResume(fallback);
	}
	return toReturn;
}