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

The following examples show how to use reactor.core.publisher.Flux#buffer() . 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 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
@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
@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
@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();
}