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

The following examples show how to use reactor.core.publisher.Mono#transform() . These examples are extracted from open source projects. 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
@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
@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
@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
@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
@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;
}