DATAMONGO-1907 - Polishing.

Rename test method to reflect test subject.

Switch from flatMap(…) to map(…) to avoid overhead of Mono creation.

Original pull request: #541.
This commit is contained in:
Mark Paluch
2018-03-21 09:47:54 +01:00
parent b47c5704e7
commit 54d2c122eb
2 changed files with 7 additions and 8 deletions

View File

@@ -92,12 +92,12 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
q.limit(2); q.limit(2);
return mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()).buffer(2) return mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()).buffer(2)
.flatMap(vals -> { .map(vals -> {
if (vals.size() > 1) { 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(); }).next();
} }
@@ -315,10 +315,9 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
Assert.notNull(entityStream, "The given Publisher of entities must not be null!"); Assert.notNull(entityStream, "The given Publisher of entities must not be null!");
return Flux.from(entityStream) return Flux.from(entityStream).flatMap(entity -> entityInformation.isNew(entity) ? //
.flatMap(entity -> entityInformation.isNew(entity) ? // mongoOperations.insert(entity, entityInformation.getCollectionName()).then(Mono.just(entity)) : //
mongoOperations.insert(entity, entityInformation.getCollectionName()).then(Mono.just(entity)) : // mongoOperations.save(entity, entityInformation.getCollectionName()).then(Mono.just(entity)));
mongoOperations.save(entity, entityInformation.getCollectionName()).then(Mono.just(entity)));
} }
/* /*

View File

@@ -443,7 +443,7 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware,
} }
@Test // DATAMONGO-1907 @Test // DATAMONGO-1907
public void existsByExampleShouldReturnNonExistingWithoutThrowException() { public void findOneByExampleWithoutResultShouldCompleteEmpty() {
Example<ReactivePerson> example = Example.of(new ReactivePerson("foo", "bar", -1)); Example<ReactivePerson> example = Example.of(new ReactivePerson("foo", "bar", -1));