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

The following examples show how to use reactor.core.publisher.Mono#hide() . 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: BackpressureIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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
Source File: CancellationPropagationIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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
Source File: CancellationPropagationIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 File: MonoOperatorTest.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Override
protected Mono<I> hide(Mono<I> input) {
	return input.hide();
}