mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-15 00:22:11 +00:00
Fix reactive save of Flux.
Original Pull Request #2581 Closes #2576 (cherry picked from commit d6b55406142abe2f72d2da29f7180621d0380b08)
This commit is contained in:
parent
89afa819f3
commit
a5934442bf
@ -225,8 +225,8 @@ abstract public class AbstractReactiveElasticsearchTemplate
|
||||
|
||||
return Flux.defer(() -> {
|
||||
Sinks.Many<T> sink = Sinks.many().unicast().onBackpressureBuffer();
|
||||
entities //
|
||||
.bufferTimeout(bulkSize, Duration.ofMillis(200)) //
|
||||
entities.window(bulkSize) //
|
||||
.concatMap(flux -> flux.collectList()) //
|
||||
.subscribe(new Subscriber<List<T>>() {
|
||||
private Subscription subscription;
|
||||
private AtomicBoolean upstreamComplete = new AtomicBoolean(false);
|
||||
|
@ -28,6 +28,7 @@ import java.lang.Boolean;
|
||||
import java.lang.Integer;
|
||||
import java.lang.Long;
|
||||
import java.lang.Object;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
@ -1181,7 +1182,7 @@ public abstract class ReactiveElasticsearchIntegrationTests {
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // #2496
|
||||
@Test // #2496, #2576
|
||||
@DisplayName("should save data from Flux and return saved data in a flux")
|
||||
void shouldSaveDataFromFluxAndReturnSavedDataInAFlux() {
|
||||
|
||||
@ -1190,9 +1191,11 @@ public abstract class ReactiveElasticsearchIntegrationTests {
|
||||
.mapToObj(SampleEntity::of) //
|
||||
.collect(Collectors.toList());
|
||||
|
||||
var entityFlux = Flux.fromIterable(entityList);
|
||||
// we add a random delay to make suure the underlying implementation handles irregular incoming data
|
||||
var entities = Flux.fromIterable(entityList).concatMap(
|
||||
entity -> Mono.just(entity).delay(Duration.ofMillis((long) (Math.random() * 10))).thenReturn(entity));
|
||||
|
||||
operations.save(entityFlux, SampleEntity.class).collectList() //
|
||||
operations.save(entities, SampleEntity.class).collectList() //
|
||||
.as(StepVerifier::create) //
|
||||
.consumeNextWith(savedEntities -> {
|
||||
assertThat(savedEntities).isEqualTo(entityList);
|
||||
|
Loading…
x
Reference in New Issue
Block a user