mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-07-06 18:52:11 +00:00
Fix code not terminating on repository saving an empty flux.
Original Pull Request #3099 Closes: #3039 Signed-off-by: Peter-Josef Meisch <pj.meisch@sothawo.com>
This commit is contained in:
parent
9d025dd469
commit
a07ac3c93d
@ -233,6 +233,7 @@ abstract public class AbstractReactiveElasticsearchTemplate
|
|||||||
.subscribe(new Subscriber<>() {
|
.subscribe(new Subscriber<>() {
|
||||||
@Nullable private Subscription subscription = null;
|
@Nullable private Subscription subscription = null;
|
||||||
private final AtomicBoolean upstreamComplete = new AtomicBoolean(false);
|
private final AtomicBoolean upstreamComplete = new AtomicBoolean(false);
|
||||||
|
private final AtomicBoolean onNextHasBeenCalled = new AtomicBoolean(false);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSubscribe(Subscription subscription) {
|
public void onSubscribe(Subscription subscription) {
|
||||||
@ -242,6 +243,7 @@ abstract public class AbstractReactiveElasticsearchTemplate
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(List<T> entityList) {
|
public void onNext(List<T> entityList) {
|
||||||
|
onNextHasBeenCalled.set(true);
|
||||||
saveAll(entityList, index)
|
saveAll(entityList, index)
|
||||||
.map(sink::tryEmitNext)
|
.map(sink::tryEmitNext)
|
||||||
.doOnComplete(() -> {
|
.doOnComplete(() -> {
|
||||||
@ -267,6 +269,10 @@ abstract public class AbstractReactiveElasticsearchTemplate
|
|||||||
@Override
|
@Override
|
||||||
public void onComplete() {
|
public void onComplete() {
|
||||||
upstreamComplete.set(true);
|
upstreamComplete.set(true);
|
||||||
|
if (!onNextHasBeenCalled.get()) {
|
||||||
|
// this happens when an empty flux is saved
|
||||||
|
sink.tryEmitComplete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return sink.asFlux();
|
return sink.asFlux();
|
||||||
|
@ -105,6 +105,26 @@ abstract class SimpleReactiveElasticsearchRepositoryIntegrationTests {
|
|||||||
return operations.exists(id, IndexCoordinates.of(indexNameProvider.indexName()));
|
return operations.exists(id, IndexCoordinates.of(indexNameProvider.indexName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // #3093
|
||||||
|
@DisplayName("should save all from empty collection")
|
||||||
|
void shouldSaveAllFromEmptyCollection() {
|
||||||
|
|
||||||
|
repository.saveAll(Collections.emptyList())
|
||||||
|
.as(StepVerifier::create)
|
||||||
|
.expectNextCount(0)
|
||||||
|
.verifyComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // #3093
|
||||||
|
@DisplayName("should save all from empty flux")
|
||||||
|
void shouldSaveAllFromEmptyFlux() {
|
||||||
|
|
||||||
|
repository.saveAll(Flux.empty())
|
||||||
|
.as(StepVerifier::create)
|
||||||
|
.expectNextCount(0)
|
||||||
|
.verifyComplete();
|
||||||
|
}
|
||||||
|
|
||||||
@Test // DATAES-519
|
@Test // DATAES-519
|
||||||
void saveShouldComputeMultipleEntities() {
|
void saveShouldComputeMultipleEntities() {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user