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

The following examples show how to use reactor.core.publisher.Flux#buffer() . 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: R040_Buffer.java    From reactor-workshop with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void buffer() throws Exception {
	//given
	final Flux<Integer> nums = Flux.range(1, 10);

	//when
	final Flux<List<Integer>> buffers = nums.buffer(3);

	//then
	buffers
			.as(StepVerifier::create)
			.expectNext(List.of(1, 2, 3))
			.expectNext(List.of(4, 5, 6))
			.expectNext(List.of(7, 8, 9))
			.expectNext(List.of(10))
			.verifyComplete();
}
 
Example 2
Source File: R040_Buffer.java    From reactor-workshop with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void overlapping() throws Exception {
	//given
	final Flux<Integer> nums = Flux.range(1, 8);

	//when
	final Flux<List<Integer>> buffers = nums.buffer(3, 2);

	//then
	buffers
			.as(StepVerifier::create)
			.expectNext(List.of(1, 2, 3))
			.expectNext(List.of(3, 4, 5))
			.expectNext(List.of(5, 6, 7))
			.expectNext(List.of(7, 8))
			.verifyComplete();
}
 
Example 3
Source File: R040_Buffer.java    From reactor-workshop with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void gaps() throws Exception {
	//given
	final Flux<Integer> nums = Flux.range(1, 10);

	//when
	final Flux<List<Integer>> buffers = nums.buffer(2, 3);

	//then
	buffers
			.as(StepVerifier::create)
			.expectNext(List.of(1, 2))
			.expectNext(List.of(4, 5))
			.expectNext(List.of(7, 8))
			.expectNext(List.of(10))
			.verifyComplete();
}
 
Example 4
Source File: FluxBufferingTests.java    From spring-in-action-5-samples with Apache License 2.0 5 votes vote down vote up
@Test
public void buffer() {
  Flux<String> fruitFlux = Flux.just(
      "apple", "orange", "banana", "kiwi", "strawberry");
  
  Flux<List<String>> bufferedFlux = fruitFlux.buffer(3);
  
  StepVerifier
      .create(bufferedFlux)
      .expectNext(Arrays.asList("apple", "orange", "banana"))
      .expectNext(Arrays.asList("kiwi", "strawberry"))
      .verifyComplete();
}