From 1ad975de0a91a60fec198bfd1535e3fa4cbe047f Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 21 Mar 2018 09:47:54 +0100 Subject: [PATCH] DATAMONGO-1907 - Polishing. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename test method to reflect test subject. Switch from flatMap(…) to map(…) to avoid overhead of Mono creation. Original pull request: #541. --- .../support/SimpleReactiveMongoRepository.java | 13 ++++++------- .../SimpleReactiveMongoRepositoryTests.java | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java index ff412f9be..5dcfdec8f 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java @@ -92,12 +92,12 @@ public class SimpleReactiveMongoRepository implement q.limit(2); return mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()).buffer(2) - .flatMap(vals -> { + .map(vals -> { if (vals.size() > 1) { - return Mono.error(new IncorrectResultSizeDataAccessException(1)); + throw new IncorrectResultSizeDataAccessException(1); } - return Mono.just(vals.iterator().next()); + return vals.iterator().next(); }).next(); } @@ -315,10 +315,9 @@ public class SimpleReactiveMongoRepository implement Assert.notNull(entityStream, "The given Publisher of entities must not be null!"); - return Flux.from(entityStream) - .flatMap(entity -> entityInformation.isNew(entity) ? // - mongoOperations.insert(entity, entityInformation.getCollectionName()).then(Mono.just(entity)) : // - mongoOperations.save(entity, entityInformation.getCollectionName()).then(Mono.just(entity))); + return Flux.from(entityStream).flatMap(entity -> entityInformation.isNew(entity) ? // + mongoOperations.insert(entity, entityInformation.getCollectionName()).then(Mono.just(entity)) : // + mongoOperations.save(entity, entityInformation.getCollectionName()).then(Mono.just(entity))); } /* diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/SimpleReactiveMongoRepositoryTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/SimpleReactiveMongoRepositoryTests.java index f01f53a33..9da351d62 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/SimpleReactiveMongoRepositoryTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/SimpleReactiveMongoRepositoryTests.java @@ -443,7 +443,7 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware, } @Test // DATAMONGO-1907 - public void existsByExampleShouldReturnNonExistingWithoutThrowException() { + public void findOneByExampleWithoutResultShouldCompleteEmpty() { Example example = Example.of(new ReactivePerson("foo", "bar", -1));