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

The following examples show how to use reactor.core.publisher.Flux#transform() . 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 vote down vote up
@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
Source File: ClientThreadIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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
Source File: UnexpectedServerErrorIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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
Source File: BackpressureIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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
Source File: EndToEndIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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
Source File: ReactiveSentinelCircuitBreaker.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
@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
Source File: FluxedFunction.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
@Override
public Flux<O> apply(Flux<I> input) {
	return input.transform(this.getTarget());
}