Java Code Examples for reactor.core.publisher.Flux#hide()
The following examples show how to use
reactor.core.publisher.Flux#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: ServerErrorIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void manyToOne() { ReactorGreeterGrpc.ReactorGreeterStub stub = ReactorGreeterGrpc.newReactorStub(channel); Flux<HelloRequest> requestFlux = Flux.just(HelloRequest.getDefaultInstance()); if (!expectFusion) { requestFlux = requestFlux.hide(); } Mono<HelloResponse> resp = requestFlux.as(stub::sayHelloReqStream); StepVerifier.Step<HelloResponse> stepVerifier = StepVerifier.create(resp); if (expectFusion) { stepVerifier = ((StepVerifier.FirstStep<HelloResponse>) stepVerifier).expectFusion(); } stepVerifier .verifyErrorMatches(t -> t instanceof StatusRuntimeException && ((StatusRuntimeException)t).getStatus() == Status.INTERNAL); }
Example 2
Source File: ServerErrorIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void manyToMany() { ReactorGreeterGrpc.ReactorGreeterStub stub = ReactorGreeterGrpc.newReactorStub(channel); Flux<HelloRequest> requestFlux = Flux.just(HelloRequest.getDefaultInstance()); if (!expectFusion) { requestFlux = requestFlux.hide(); } Flux<HelloResponse> resp = requestFlux.transform(stub::sayHelloBothStream); StepVerifier.Step<HelloResponse> stepVerifier = StepVerifier.create(resp); if (expectFusion) { stepVerifier = ((StepVerifier.FirstStep<HelloResponse>) stepVerifier).expectFusion(); } stepVerifier .verifyErrorMatches(t -> t instanceof StatusRuntimeException && ((StatusRuntimeException)t).getStatus() == Status.INTERNAL); }
Example 3
Source File: EndToEndIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void manyToOne() throws Exception { ReactorGreeterGrpc.ReactorGreeterStub stub = ReactorGreeterGrpc.newReactorStub(channel); Flux<HelloRequest> req = Flux.just( HelloRequest.newBuilder().setName("a").build(), HelloRequest.newBuilder().setName("b").build(), HelloRequest.newBuilder().setName("c").build()); if (!expectFusion) { req = req.hide(); } Mono<HelloResponse> resp = req.as(stub::sayHelloReqStream); StepVerifier.Step<String> stepVerifier = StepVerifier.create(resp.map(HelloResponse::getMessage)); if (expectFusion) { stepVerifier = ((StepVerifier.FirstStep<String>) stepVerifier).expectFusion(); } stepVerifier .expectNext("Hello a and b and c") .verifyComplete(); }
Example 4
Source File: BackpressureIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void clientToServerBackpressure() { serverRule.getServiceRegistry().addService(service); ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel()); Flux<NumberProto.Number> reactorRequest = Flux .fromIterable(IntStream.range(0, NUMBER_OF_STREAM_ELEMENTS)::iterator) .doOnNext(i -> System.out.println(i + " --> ")) .doOnNext(i -> updateNumberOfWaits(lastValueTime, numberOfWaits)) .map(BackpressureIntegrationTest::protoNum); if (!expectFusion) { reactorRequest = reactorRequest.hide(); } Mono<NumberProto.Number> reactorResponse = reactorRequest.as(stub::requestPressure); StepVerifier.Step<NumberProto.Number> stepVerifier = StepVerifier.create(reactorResponse); if (expectFusion) { stepVerifier = ((StepVerifier.FirstStep<NumberProto.Number>) stepVerifier).expectFusion(); } stepVerifier .expectNextMatches(v -> v.getNumber(0) == NUMBER_OF_STREAM_ELEMENTS - 1) .expectComplete() .verify(Duration.ofSeconds(15)); assertThat(numberOfWaits.get()).isGreaterThan(0L); }
Example 5
Source File: ServerErrorUpstreamCancellationIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void serverErrorSignalsUpstreamCancellationBidi() { serverRule.getServiceRegistry().addService(service); ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel()); AtomicBoolean upstreamCancel = new AtomicBoolean(false); Flux<NumberProto.Number> requestFlux = Flux.range(0, Integer.MAX_VALUE) .map(this::protoNum) .doOnCancel(() -> upstreamCancel.set(true)); if (!expectFusion) { requestFlux = requestFlux.hide(); } Flux<NumberProto.Number> subscriber = requestFlux .transform(stub::twoWayPressure) .doOnNext(i -> System.out.println(i.getNumber(0))); StepVerifier.Step<NumberProto.Number> stepVerifier = StepVerifier.create(subscriber); if (expectFusion) { stepVerifier = ((StepVerifier.FirstStep<NumberProto.Number>) stepVerifier).expectFusion(); } stepVerifier .verifyError(StatusRuntimeException.class); assertThat(upstreamCancel.get()).isTrue(); }
Example 6
Source File: ServerErrorUpstreamCancellationIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void serverErrorSignalsUpstreamCancellationManyToOne() { serverRule.getServiceRegistry().addService(service); ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel()); AtomicBoolean upstreamCancel = new AtomicBoolean(false); Flux<NumberProto.Number> requestFlux = Flux.range(0, Integer.MAX_VALUE) .map(this::protoNum) .doOnCancel(() -> upstreamCancel.set(true)); if (!expectFusion) { requestFlux = requestFlux.hide(); } Mono<NumberProto.Number> observer = requestFlux .as(stub::requestPressure) .doOnError(System.out::println) .doOnSuccess(i -> System.out.println(i.getNumber(0))); StepVerifier.Step<NumberProto.Number> stepVerifier = StepVerifier.create(observer); if (expectFusion) { stepVerifier = ((StepVerifier.FirstStep<NumberProto.Number>) stepVerifier).expectFusion(); } stepVerifier .verifyError(StatusRuntimeException.class); assertThat(upstreamCancel.get()).isTrue(); }
Example 7
Source File: EndToEndIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void manyToMany() throws Exception { ReactorGreeterGrpc.ReactorGreeterStub stub = ReactorGreeterGrpc.newReactorStub(channel); Flux<HelloRequest> req = Flux.just( HelloRequest.newBuilder().setName("a").build(), HelloRequest.newBuilder().setName("b").build(), HelloRequest.newBuilder().setName("c").build(), HelloRequest.newBuilder().setName("d").build(), HelloRequest.newBuilder().setName("e").build()); if (!expectFusion) { req = req.hide(); } Flux<HelloResponse> resp = req.transform(stub::sayHelloBothStream); StepVerifier.Step<String> stepVerifier = StepVerifier.create(resp.map(HelloResponse::getMessage)); if (expectFusion) { stepVerifier = ((StepVerifier.FirstStep<String>) stepVerifier).expectFusion(); } stepVerifier .expectNext("Hello a and b", "Hello c and d", "Hello e") .verifyComplete(); }
Example 8
Source File: BackpressureIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void bidiRequestBackpressure() { serverRule.getServiceRegistry().addService(service); ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel()); Flux<NumberProto.Number> reactorRequest = Flux .fromIterable(IntStream.range(0, NUMBER_OF_STREAM_ELEMENTS)::iterator) .doOnNext(i -> System.out.println(i + " --> ")) .doOnNext(i -> updateNumberOfWaits(lastValueTime, numberOfWaits)) .map(BackpressureIntegrationTest::protoNum); if (!expectFusion) { reactorRequest = reactorRequest.hide(); } Flux<NumberProto.Number> reactorResponse = reactorRequest.transform(stub::twoWayRequestPressure); StepVerifier.Step<NumberProto.Number> stepVerifier = StepVerifier.create(reactorResponse); if (expectFusion) { stepVerifier = ((StepVerifier.FirstStep<NumberProto.Number>) stepVerifier).expectFusion(); } stepVerifier .expectNextMatches(v -> v.getNumber(0) == NUMBER_OF_STREAM_ELEMENTS - 1) .expectComplete() .verify(Duration.ofSeconds(15)); assertThat(numberOfWaits.get()).isGreaterThan(0L); }
Example 9
Source File: BackpressureIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void bidiResponseBackpressure() { serverRule.getServiceRegistry().addService(service); ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel()); Flux<NumberProto.Number> reactorRequest = Flux.empty(); if (!expectFusion) { reactorRequest = reactorRequest.hide(); } Flux<NumberProto.Number> reactorResponse = reactorRequest.transform(stub::twoWayResponsePressure) .doOnNext(n -> System.out.println(n.getNumber(0) + " <--")) .doOnNext(n -> waitIfValuesAreEqual(n.getNumber(0), 3)); StepVerifier.Step<NumberProto.Number> stepVerifier = StepVerifier.create(reactorResponse); if (expectFusion) { stepVerifier = ((StepVerifier.FirstStep<NumberProto.Number>) stepVerifier).expectFusion(); } stepVerifier .expectNextCount(NUMBER_OF_STREAM_ELEMENTS) .expectComplete() .verify(Duration.ofSeconds(15)); assertThat(numberOfWaits.get()).isGreaterThan(0L); }
Example 10
Source File: ClientThreadIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void manyToMany() { ReactorGreeterGrpc.ReactorGreeterStub stub = ReactorGreeterGrpc.newReactorStub(channel); Flux<HelloRequest> req = Flux.just( HelloRequest.newBuilder().setName("a").build(), HelloRequest.newBuilder().setName("b").build(), HelloRequest.newBuilder().setName("c").build(), HelloRequest.newBuilder().setName("d").build(), HelloRequest.newBuilder().setName("e").build()); if (!expectFusion) { req = req.hide(); } Flux<HelloResponse> resp = req.transform(stub::sayHelloBothStream); AtomicReference<String> clientThreadName = new AtomicReference<>(); StepVerifier.Step<String> stepVerifier = StepVerifier.create( resp .map(HelloResponse::getMessage) .doOnNext(x -> clientThreadName.set(Thread.currentThread().getName())) ); if (expectFusion) { stepVerifier = ((StepVerifier.FirstStep<String>) stepVerifier).expectFusion(); } stepVerifier .expectNext("Hello a and b", "Hello c and d", "Hello e") .verifyComplete(); assertThat(clientThreadName.get()).isEqualTo("TheGrpcClient"); assertThat(service.serverThreadName.get()).isEqualTo("TheGrpcServer"); }
Example 11
Source File: CancellationPropagationIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 12
Source File: CancellationPropagationIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 13
Source File: CancellationPropagationIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void serverCanCancelClientStreamExplicitlyBidi() { serverRule.getServiceRegistry().addService(service); ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel()); service.setExplicitCancel(true); AtomicBoolean requestWasCanceled = new AtomicBoolean(false); AtomicBoolean requestDidProduce = new AtomicBoolean(false); Flux<NumberProto.Number> request = Flux .fromIterable(IntStream.range(0, NUMBER_OF_STREAM_ELEMENTS)::iterator) .delayElements(Duration.ofMillis(SEQUENCE_DELAY_MILLIS)) .map(CancellationPropagationIntegrationTest::protoNum) .doOnNext(n -> { requestDidProduce.set(true); System.out.println("P: " + n.getNumber(0)); }) .doOnCancel(() -> { requestWasCanceled.set(true); System.out.println("Client canceled"); }); if (!expectFusion) { request = request.hide(); } Flux<NumberProto.Number> observer = request.transform(stub::twoWayPressure) .doOnNext(number -> System.out.println(number.getNumber(0))) .doOnError(throwable -> System.out.println(throwable.getMessage())); StepVerifier.Step<NumberProto.Number> stepVerifier = StepVerifier.create(observer); if (expectFusion) { stepVerifier = ((StepVerifier.FirstStep<NumberProto.Number>) stepVerifier).expectFusion(); } stepVerifier .expectNext(protoNum(-1)) .verifyComplete(); await().atMost(org.awaitility.Duration.FIVE_HUNDRED_MILLISECONDS).untilTrue(requestWasCanceled); assertThat(requestWasCanceled.get()).isTrue(); assertThat(requestDidProduce.get()).isTrue(); }
Example 14
Source File: CancellationPropagationIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void serverCanCancelClientStreamImplicitlyBidi() { serverRule.getServiceRegistry().addService(service); ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel()); service.setExplicitCancel(false); AtomicBoolean requestWasCanceled = new AtomicBoolean(false); AtomicBoolean requestDidProduce = new AtomicBoolean(false); Flux<NumberProto.Number> request = Flux .fromIterable(IntStream.range(0, NUMBER_OF_STREAM_ELEMENTS)::iterator) .delayElements(Duration.ofMillis(SEQUENCE_DELAY_MILLIS)) .map(CancellationPropagationIntegrationTest::protoNum) .doOnNext(x -> { requestDidProduce.set(true); System.out.println("Produced: " + x.getNumber(0)); }) .doOnCancel(() -> { requestWasCanceled.set(true); System.out.println("Client canceled"); }); if (!expectFusion) { request = request.hide(); } Flux<NumberProto.Number> observer = request.transform(stub::twoWayPressure) .doOnNext(number -> System.out.println(number.getNumber(0))) .doOnError(throwable -> System.out.println(throwable.getMessage())); StepVerifier.Step<NumberProto.Number> stepVerifier = StepVerifier.create(observer); if (expectFusion) { stepVerifier = ((StepVerifier.FirstStep<NumberProto.Number>) stepVerifier).expectFusion(); } stepVerifier .expectNext(protoNum(9)) .verifyComplete(); await().atMost(org.awaitility.Duration.FIVE_HUNDRED_MILLISECONDS).untilTrue(requestWasCanceled); assertThat(requestWasCanceled.get()).isTrue(); assertThat(requestDidProduce.get()).isTrue(); }
Example 15
Source File: CancellationPropagationIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void serverCanCancelClientStreamExplicitly() { serverRule.getServiceRegistry().addService(service); ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel()); service.setExplicitCancel(true); AtomicBoolean requestWasCanceled = new AtomicBoolean(false); AtomicBoolean requestDidProduce = new AtomicBoolean(false); Flux<NumberProto.Number> request = Flux .fromIterable(IntStream.range(0, NUMBER_OF_STREAM_ELEMENTS)::iterator) .delayElements(Duration.ofMillis(SEQUENCE_DELAY_MILLIS)) .map(CancellationPropagationIntegrationTest::protoNum) .doOnNext(n -> { requestDidProduce.set(true); System.out.println("P: " + n.getNumber(0)); }) .doOnCancel(() -> { requestWasCanceled.set(true); System.out.println("Client canceled"); }); if (!expectFusion) { request = request.hide(); } Mono<NumberProto.Number> observer = request.as(stub::requestPressure) .doOnSuccess(number -> System.out.println(number.getNumber(0))) .doOnError(throwable -> System.out.println(throwable.getMessage())); StepVerifier.Step<NumberProto.Number> stepVerifier = StepVerifier.create(observer); if (expectFusion) { stepVerifier = ((StepVerifier.FirstStep<NumberProto.Number>) stepVerifier).expectFusion(); } stepVerifier .expectNext(protoNum(-1)) .verifyComplete(); await().atMost(org.awaitility.Duration.FIVE_HUNDRED_MILLISECONDS).untilTrue(requestWasCanceled); assertThat(requestWasCanceled.get()).isTrue(); assertThat(requestDidProduce.get()).isTrue(); }
Example 16
Source File: CancellationPropagationIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void serverCanCancelClientStreamImplicitly() { serverRule.getServiceRegistry().addService(service); ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(serverRule.getChannel()); service.setExplicitCancel(false); AtomicBoolean requestWasCanceled = new AtomicBoolean(false); AtomicBoolean requestDidProduce = new AtomicBoolean(false); Flux<NumberProto.Number> request = Flux .fromIterable(IntStream.range(0, NUMBER_OF_STREAM_ELEMENTS)::iterator) .delayElements(Duration.ofMillis(SEQUENCE_DELAY_MILLIS)) .map(CancellationPropagationIntegrationTest::protoNum) .doOnNext(x -> { requestDidProduce.set(true); System.out.println("Produced: " + x.getNumber(0)); }) .doOnCancel(() -> { requestWasCanceled.set(true); System.out.println("Client canceled"); }); if (!expectFusion) { request = request.hide(); } Mono<NumberProto.Number> observer = request.as(stub::requestPressure) .doOnSuccess(number -> System.out.println(number.getNumber(0))) .doOnError(throwable -> System.out.println(throwable.getMessage())); StepVerifier.Step<NumberProto.Number> stepVerifier = StepVerifier.create(observer); if (expectFusion) { stepVerifier = ((StepVerifier.FirstStep<NumberProto.Number>) stepVerifier).expectFusion(); } stepVerifier .expectNext(protoNum(9)) .verifyComplete(); await().atMost(org.awaitility.Duration.FIVE_HUNDRED_MILLISECONDS).untilTrue(requestWasCanceled); assertThat(requestWasCanceled.get()).isTrue(); assertThat(requestDidProduce.get()).isTrue(); }
Example 17
Source File: ReduceOperatorTest.java From reactor-core with Apache License 2.0 | 4 votes |
@Override final Flux<I> hide(Flux<I> input) { return input.hide(); }
Example 18
Source File: FluxOperatorTest.java From reactor-core with Apache License 2.0 | 4 votes |
@Override Flux<I> hide(Flux<I> input) { return input.hide(); }