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

The following examples show how to use reactor.core.publisher.Mono#hide() . 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 serverToClientBackpressure() {
    serverRule.getServiceRegistry().addService(service);

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

    Mono<Empty> reactorRequest = Mono.just(Empty.getDefaultInstance());

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

    Flux<NumberProto.Number> reactorResponse = reactorRequest.as(stub::responsePressure)
            .doOnNext(n -> System.out.println(n.getNumber(0) + "  <--"))
            .doOnNext(n -> waitIfValuesAreEqual(n.getNumber(0), 3));


    StepVerifier
            .create(reactorResponse)
            .expectNextCount(NUMBER_OF_STREAM_ELEMENTS)
            .expectComplete()
            .verify(Duration.ofSeconds(15));

    assertThat(numberOfWaits.get()).isGreaterThan(0L);
}
 
Example 3
@Test
public void clientCanCancelServerStreamExplicitly() throws InterruptedException {
    serverRule.getServiceRegistry().addService(service);

    AtomicInteger lastNumberConsumed = new AtomicInteger(Integer.MAX_VALUE);
    ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel());
    Mono<Empty> request = Mono.just(Empty.getDefaultInstance());

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

    Flux<NumberProto.Number> test =
            request
                .as(stub::responsePressure)
                .doOnNext(number -> {lastNumberConsumed.set(number.getNumber(0)); System.out.println("C: " + number.getNumber(0));})
                .doOnError(throwable -> System.out.println(throwable.getMessage()))
                .doOnComplete(() -> System.out.println("Completed"))
                .doOnCancel(() -> System.out.println("Client canceled"));

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

    Disposable subscription = test.publish().connect();

    Thread.sleep(1000);
    subscription.dispose();
    Thread.sleep(1000);

    // Cancellation may or may not deliver the last generated message due to delays in the gRPC processing thread
    assertThat(Math.abs(lastNumberConsumed.get() - service.getLastNumberProduced())).isLessThanOrEqualTo(3);
    assertThat(service.wasCanceled()).isTrue();
}
 
Example 4
@Test
public void clientCanCancelServerStreamImplicitly() throws InterruptedException {
    serverRule.getServiceRegistry().addService(service);

    ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel());
    Mono<Empty> request = Mono.just(Empty.getDefaultInstance());

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

    Flux<NumberProto.Number> test =
            request
                .as(stub::responsePressure)
                .doOnNext(number -> System.out.println(number.getNumber(0)))
                .doOnError(throwable -> System.out.println(throwable.getMessage()))
                .doOnComplete(() -> System.out.println("Completed"))
                .doOnCancel(() -> System.out.println("Client canceled"))
                .take(10);

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

    Disposable subscription = test.publish().connect();

    Thread.sleep(1000);

    assertThat(service.wasCanceled()).isTrue();
}
 
Example 5
Source Project: reactor-core   File: MonoOperatorTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Mono<I> hide(Mono<I> input) {
	return input.hide();
}