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
Source Project: reactive-grpc File: ClientThreadIntegrationTest.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
@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 Project: reactive-grpc File: UnaryZeroMessageResponseIntegrationTest.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 Project: reactive-grpc File: UnaryZeroMessageResponseIntegrationTest.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 Project: reactive-grpc File: EndToEndIntegrationTest.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 Project: spring-cloud-alibaba File: ReactiveSentinelCircuitBreaker.java License: Apache License 2.0 | 5 votes |
@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; }