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

The following examples show how to use reactor.core.publisher.Flux#collectList() . 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: DefaultClientResponseTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void bodyToFlux() {
	DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
	DefaultDataBuffer dataBuffer =
			factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
	Flux<DataBuffer> body = Flux.just(dataBuffer);
	mockTextPlainResponse(body);

	List<HttpMessageReader<?>> messageReaders = Collections
			.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
	given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);

	Flux<String> resultFlux = defaultClientResponse.bodyToFlux(String.class);
	Mono<List<String>> result = resultFlux.collectList();
	assertEquals(Collections.singletonList("foo"), result.block());
}
 
Example 2
Source File: DefaultClientResponseTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void bodyToFluxTypeReference() {
	DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
	DefaultDataBuffer dataBuffer =
			factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
	Flux<DataBuffer> body = Flux.just(dataBuffer);
	mockTextPlainResponse(body);

	List<HttpMessageReader<?>> messageReaders = Collections
			.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
	given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);

	Flux<String> resultFlux =
			defaultClientResponse.bodyToFlux(new ParameterizedTypeReference<String>() {
			});
	Mono<List<String>> result = resultFlux.collectList();
	assertEquals(Collections.singletonList("foo"), result.block());
}
 
Example 3
Source File: DefaultClientResponseTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void bodyToFlux() {
	DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
	DefaultDataBuffer dataBuffer =
			factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
	Flux<DataBuffer> body = Flux.just(dataBuffer);
	mockTextPlainResponse(body);

	List<HttpMessageReader<?>> messageReaders = Collections
			.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
	when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders);

	Flux<String> resultFlux = defaultClientResponse.bodyToFlux(String.class);
	Mono<List<String>> result = resultFlux.collectList();
	assertEquals(Collections.singletonList("foo"), result.block());
}
 
Example 4
Source File: DefaultClientResponseTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void bodyToFluxTypeReference() {
	DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
	DefaultDataBuffer dataBuffer =
			factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
	Flux<DataBuffer> body = Flux.just(dataBuffer);
	mockTextPlainResponse(body);

	List<HttpMessageReader<?>> messageReaders = Collections
			.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
	when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders);

	Flux<String> resultFlux =
			defaultClientResponse.bodyToFlux(new ParameterizedTypeReference<String>() {
			});
	Mono<List<String>> result = resultFlux.collectList();
	assertEquals(Collections.singletonList("foo"), result.block());
}
 
Example 5
Source File: GuideTests.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void introFutureHellReactorVersion() {
	Flux<String> ids = ifhrIds(); // <1>

	Flux<String> combinations =
			ids.flatMap(id -> { // <2>
				Mono<String> nameTask = ifhrName(id); // <3>
				Mono<Integer> statTask = ifhrStat(id); // <4>

				return nameTask.zipWith(statTask, // <5>
						(name, stat) -> "Name " + name + " has stats " + stat);
			});

	Mono<List<String>> result = combinations.collectList(); // <6>

	List<String> results = result.block(); // <7>
	assertThat(results).containsExactly( // <8>
			"Name NameJoe has stats 103",
			"Name NameBart has stats 104",
			"Name NameHenry has stats 105",
			"Name NameNicole has stats 106",
			"Name NameABSLAJNFOAJNFOANFANSF has stats 121"
	);
}
 
Example 6
Source File: FluxBufferingTests.java    From spring-in-action-5-samples with Apache License 2.0 5 votes vote down vote up
@Test
public void collectList() {
  Flux<String> fruitFlux = Flux.just(
      "apple", "orange", "banana", "kiwi", "strawberry");
  
  Mono<List<String>> fruitListMono = fruitFlux.collectList();
  
  StepVerifier
      .create(fruitListMono)
      .expectNext(Arrays.asList(
          "apple", "orange", "banana", "kiwi", "strawberry"))
      .verifyComplete();
}
 
Example 7
Source File: ReactiveController.java    From Hands-On-Reactive-Programming-with-Reactor with MIT License 5 votes vote down vote up
@GetMapping("/numbers")
public String handleSeries(Model model) {
    Flux<Long> fibonacciGenerator = Flux.generate(() -> Tuples.<Long,
            Long>of(0L, 1L), (state, sink) -> {
        if (state.getT1() < 0)
            sink.complete();
        else
            sink.next(state.getT1());
        return Tuples.of(state.getT2(), state.getT1() + state.getT2());
    });
    Mono<List<Long>> listMono = fibonacciGenerator.collectList();
    model.addAttribute("series",listMono);
    return "numbers";
}