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

The following examples show how to use reactor.core.publisher.Flux#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 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 2
@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 3
@Test
public void manyToMany() {
    ReactorGreeterGrpc.ReactorGreeterStub stub = ReactorGreeterGrpc.newReactorStub(channel);
    Flux<HelloRequest> req = Flux.just(HelloRequest.getDefaultInstance());
    Flux<HelloResponse> resp = req.transform(stub::sayHelloBothStream);

    StepVerifier.create(resp)
            .verifyErrorMatches(t -> t instanceof StatusRuntimeException && ((StatusRuntimeException)t).getStatus().getCode() == Status.Code.INTERNAL);
}
 
Example 4
@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 5
@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 6
@Override
public <T> Flux<T> run(Flux<T> toRun, Function<Throwable, Flux<T>> fallback) {
	Flux<T> toReturn = toRun.transform(new SentinelReactorTransformer<>(
			new EntryConfig(resourceName, entryType)));
	if (fallback != null) {
		toReturn = toReturn.onErrorResume(fallback);
	}
	return toReturn;
}
 
Example 7
@Override
public Flux<O> apply(Flux<I> input) {
	return input.transform(this.getTarget());
}