Skip to content

Commit 16aa611

Browse files
DATAMONGO-2080 - Polishing.
Remove obsolete classes, update Javadoc and fix tests calling all() instead of tail(). Original Pull Request: #608
1 parent 13e29eb commit 16aa611

File tree

5 files changed

+40
-46
lines changed

5 files changed

+40
-46
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveFindOperation.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,18 @@ interface TerminatingFind<T> {
8686
Flux<T> all();
8787

8888
/**
89-
* Get all matching elements using a tailable cursor.
89+
* Get all matching elements using a {@link com.mongodb.CursorType#TailableAwait tailable cursor}. The stream will
90+
* not be completed unless the {@link org.reactivestreams.Subscription} is
91+
* {@link org.reactivestreams.Subscription#cancel() canceled}.
92+
* <p />
93+
* However, the stream may become dead, or invalid, if either the query returns no match or the cursor returns the
94+
* document at the "end" of the collection and then the application deletes that document.
9095
* <p />
91-
* The stream may become dead, or invalid, if either the query returns no match or the cursor returns the document
92-
* at the "end" of the collection and then the application deletes that document.
93-
* <p/>
9496
* A stream that is no longer in use must be {@link reactor.core.Disposable#dispose()} disposed} otherwise the
9597
* streams will linger and exhaust resources. <br/>
9698
* <strong>NOTE:</strong> Requires a capped collection.
9799
*
98-
* @return never {@literal null}.
100+
* @return the {@link Flux} emitting converted objects.
99101
* @since 2.1
100102
*/
101103
Flux<T> tail();

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractReactiveMongoQuery.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private Object execute(MongoParameterAccessor parameterAccessor) {
119119

120120
String collection = method.getEntityInformation().getCollectionName();
121121

122-
ReactiveMongoQueryExecution execution = getExecution(query, parameterAccessor,
122+
ReactiveMongoQueryExecution execution = getExecution(parameterAccessor,
123123
new ResultProcessingConverter(processor, operations, instantiators), find);
124124

125125
return execution.execute(query, processor.getReturnedType().getDomainType(), collection);
@@ -128,12 +128,11 @@ private Object execute(MongoParameterAccessor parameterAccessor) {
128128
/**
129129
* Returns the execution instance to use.
130130
*
131-
* @param query must not be {@literal null}.
132131
* @param accessor must not be {@literal null}.
133132
* @param resultProcessing must not be {@literal null}.
134133
* @return
135134
*/
136-
private ReactiveMongoQueryExecution getExecution(Query query, MongoParameterAccessor accessor,
135+
private ReactiveMongoQueryExecution getExecution(MongoParameterAccessor accessor,
137136
Converter<Object, Object> resultProcessing, FindWithQuery<?> operation) {
138137
return new ResultProcessingExecution(getExecutionToWrap(accessor, operation), resultProcessing);
139138
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ReactiveMongoQueryExecution.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,6 @@ interface ReactiveMongoQueryExecution {
5151

5252
Object execute(Query query, Class<?> type, String collection);
5353

54-
/**
55-
* {@link ReactiveMongoQueryExecution} for collection returning queries using tailable cursors.
56-
*
57-
* @author Mark Paluch
58-
*/
59-
@RequiredArgsConstructor
60-
final class TailExecution implements ReactiveMongoQueryExecution {
61-
62-
private final @NonNull ReactiveMongoOperations operations;
63-
private final Pageable pageable;
64-
65-
@Override
66-
public Object execute(Query query, Class<?> type, String collection) {
67-
return operations.tail(query.with(pageable), type, collection);
68-
}
69-
}
70-
7154
/**
7255
* {@link MongoQueryExecution} to execute geo-near queries.
7356
*

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveFindOperationSupportTests.java

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ public class ReactiveFindOperationSupportTests {
7171
public void setUp() {
7272

7373
blocking = new MongoTemplate(new SimpleMongoDbFactory(new MongoClient(), "ExecutableFindOperationSupportTests"));
74-
blocking.dropCollection(STAR_WARS);
74+
recreateCollection(STAR_WARS, false);
7575

7676
insertObjects();
7777

7878
template = new ReactiveMongoTemplate(MongoClients.create(), "ExecutableFindOperationSupportTests");
7979
}
8080

8181
void insertObjects() {
82+
8283
han = new Person();
8384
han.firstname = "han";
8485
han.lastname = "solo";
@@ -93,6 +94,18 @@ void insertObjects() {
9394
blocking.save(luke);
9495
}
9596

97+
void recreateCollection(String collectionName, boolean capped) {
98+
99+
blocking.dropCollection(STAR_WARS);
100+
101+
CollectionOptions options = CollectionOptions.empty();
102+
if (capped) {
103+
options = options.capped().size(1024 * 1024);
104+
}
105+
106+
blocking.createCollection(STAR_WARS, options);
107+
}
108+
96109
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1719
97110
public void domainTypeIsRequired() {
98111
template.query(null);
@@ -304,8 +317,7 @@ public void findAllNearByReturningGeoResultContentAsOpenInterfaceProjection() {
304317
@Test // DATAMONGO-2080
305318
public void tail() throws InterruptedException {
306319

307-
blocking.dropCollection(STAR_WARS);
308-
blocking.createCollection(STAR_WARS, CollectionOptions.empty().capped().size(1024 * 1024));
320+
recreateCollection(STAR_WARS, true);
309321
insertObjects();
310322

311323
BlockingQueue<Person> collector = new LinkedBlockingQueue<>();
@@ -325,20 +337,19 @@ public void tail() throws InterruptedException {
325337

326338
blocking.save(chewbacca);
327339

328-
assertThat(collector.poll(10, TimeUnit.SECONDS)).isEqualTo(chewbacca);
340+
assertThat(collector.poll(1, TimeUnit.SECONDS)).isEqualTo(chewbacca);
329341

330342
subscription.dispose();
331343
}
332344

333345
@Test // DATAMONGO-2080
334346
public void tailWithProjection() {
335347

336-
blocking.dropCollection(STAR_WARS);
337-
blocking.createCollection(STAR_WARS, CollectionOptions.empty().capped().size(1024 * 1024));
348+
recreateCollection(STAR_WARS, true);
338349
insertObjects();
339350

340-
StepVerifier
341-
.create(template.query(Person.class).as(Jedi.class).matching(query(where("firstname").is("luke"))).tail())
351+
template.query(Person.class).as(Jedi.class).matching(query(where("firstname").is("luke"))).tail()
352+
.as(StepVerifier::create) //
342353
.consumeNextWith(it -> assertThat(it).isInstanceOf(Jedi.class)) //
343354
.thenCancel() //
344355
.verify();
@@ -347,12 +358,11 @@ public void tailWithProjection() {
347358
@Test // DATAMONGO-2080
348359
public void tailWithClosedInterfaceProjection() {
349360

350-
blocking.dropCollection(STAR_WARS);
351-
blocking.createCollection(STAR_WARS, CollectionOptions.empty().capped().size(1024 * 1024));
361+
recreateCollection(STAR_WARS, true);
352362
insertObjects();
353363

354-
StepVerifier.create(
355-
template.query(Person.class).as(PersonProjection.class).matching(query(where("firstname").is("luke"))).all())
364+
template.query(Person.class).as(PersonProjection.class).matching(query(where("firstname").is("luke"))).tail()
365+
.as(StepVerifier::create) //
356366
.consumeNextWith(it -> {
357367

358368
assertThat(it).isInstanceOf(PersonProjection.class);
@@ -365,12 +375,12 @@ public void tailWithClosedInterfaceProjection() {
365375
@Test // DATAMONGO-2080
366376
public void tailWithOpenInterfaceProjection() {
367377

368-
blocking.dropCollection(STAR_WARS);
369-
blocking.createCollection(STAR_WARS, CollectionOptions.empty().capped().size(1024 * 1024));
378+
recreateCollection(STAR_WARS, true);
370379
insertObjects();
371380

372-
StepVerifier.create(template.query(Person.class).as(PersonSpELProjection.class)
373-
.matching(query(where("firstname").is("luke"))).tail()).consumeNextWith(it -> {
381+
template.query(Person.class).as(PersonSpELProjection.class).matching(query(where("firstname").is("luke"))).tail()
382+
.as(StepVerifier::create) //
383+
.consumeNextWith(it -> {
374384

375385
assertThat(it).isInstanceOf(PersonSpELProjection.class);
376386
assertThat(it.getName()).isEqualTo("luke");

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ReactiveMongoRepositoryTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,14 @@ public void shouldUseTailableCursorWithProjection() throws Exception {
231231
@Test // DATAMONGO-2080
232232
public void shouldUseTailableCursorWithDtoProjection() {
233233

234-
StepVerifier.create(template.dropCollection(Capped.class) //
234+
template.dropCollection(Capped.class) //
235235
.then(template.createCollection(Capped.class, //
236-
CollectionOptions.empty().size(1000).maxDocuments(100).capped()))) //
237-
.expectNextCount(1) //
236+
CollectionOptions.empty().size(1000).maxDocuments(100).capped())) //
237+
.as(StepVerifier::create).expectNextCount(1) //
238238
.verifyComplete();
239239

240-
StepVerifier.create(template.insert(new Capped("value", Math.random()))).expectNextCount(1).verifyComplete();
241-
StepVerifier.create(cappedRepository.findDtoProjectionByKey("value")).expectNextCount(1).thenCancel().verify();
240+
template.insert(new Capped("value", Math.random())).as(StepVerifier::create).expectNextCount(1).verifyComplete();
241+
cappedRepository.findDtoProjectionByKey("value").as(StepVerifier::create).expectNextCount(1).thenCancel().verify();
242242
}
243243

244244
@Test // DATAMONGO-1444

0 commit comments

Comments
 (0)