DATAMONGO-1559 - Polishing.
Migrate off deprecated Cancellation API to Disposable.
This commit is contained in:
@@ -111,6 +111,13 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.projectreactor.addons</groupId>
|
||||
<artifactId>reactor-test</artifactId>
|
||||
<version>${reactor}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.reactivex</groupId>
|
||||
<artifactId>rxjava</artifactId>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.mongodb.repository;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
@@ -24,8 +23,6 @@ import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.data.annotation.QueryAnnotation;
|
||||
|
||||
import reactor.core.Cancellation;
|
||||
|
||||
/**
|
||||
* Annotation to declare an infinite stream using repository query methods. An infinite stream uses MongoDB's
|
||||
* {@link com.mongodb.CursorType#TailableAwait tailable} cursors to retrieve data from a capped collection and stream
|
||||
@@ -35,8 +32,8 @@ import reactor.core.Cancellation;
|
||||
* The stream may become dead, or invalid, if either the query returns no match or the cursor returns the document at
|
||||
* the "end" of the collection and then the application deletes that document.
|
||||
* <p>
|
||||
* A stream that is no longer in use must be {@link Cancellation#dispose()} disposed} otherwise the streams will linger
|
||||
* and exhaust resources.
|
||||
* A stream that is no longer in use must be {@link reactor.core.Disposable#dispose()} disposed} otherwise the streams
|
||||
* will linger and exhaust resources.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @see <a href="https://docs.mongodb.com/manual/core/tailable-cursors/">Tailable Cursors</a>
|
||||
|
||||
@@ -21,7 +21,7 @@ import static org.springframework.data.mongodb.core.query.Criteria.*;
|
||||
import static org.springframework.data.mongodb.core.query.Query.*;
|
||||
|
||||
import lombok.Data;
|
||||
import reactor.core.Cancellation;
|
||||
import reactor.core.Disposable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
@@ -812,12 +812,12 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
Flux<Document> capped = template.tail(null, Document.class, "capped");
|
||||
|
||||
Cancellation cancellation = capped.doOnNext(documents::add).subscribe();
|
||||
Disposable disposable = capped.doOnNext(documents::add).subscribe();
|
||||
|
||||
assertThat(documents.poll(5, TimeUnit.SECONDS), is(notNullValue()));
|
||||
assertThat(documents.isEmpty(), is(true));
|
||||
|
||||
cancellation.dispose();
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
@@ -834,7 +834,7 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
Flux<Document> capped = template.tail(null, Document.class, "capped");
|
||||
|
||||
Cancellation cancellation = capped.doOnNext(documents::add).subscribe();
|
||||
Disposable disposable = capped.doOnNext(documents::add).subscribe();
|
||||
|
||||
assertThat(documents.poll(5, TimeUnit.SECONDS), is(notNullValue()));
|
||||
assertThat(documents.isEmpty(), is(true));
|
||||
@@ -845,7 +845,7 @@ public class ReactiveMongoTemplateTests {
|
||||
|
||||
assertThat(documents.poll(5, TimeUnit.SECONDS), is(notNullValue()));
|
||||
|
||||
cancellation.dispose();
|
||||
disposable.dispose();
|
||||
|
||||
StepVerifier.create(template.insert(new Document("random", Math.random()).append("key", "value"), "capped")) //
|
||||
.expectNextCount(1) //
|
||||
|
||||
@@ -20,7 +20,7 @@ import static org.junit.Assert.*;
|
||||
import static org.springframework.data.domain.Sort.Direction.*;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
import reactor.core.Cancellation;
|
||||
import reactor.core.Disposable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
@@ -183,7 +183,7 @@ public class ReactiveMongoRepositoryTests implements BeanClassLoaderAware, BeanF
|
||||
|
||||
BlockingQueue<Capped> documents = new LinkedBlockingDeque<>(100);
|
||||
|
||||
Cancellation cancellation = cappedRepository.findByKey("value").doOnNext(documents::add).subscribe();
|
||||
Disposable disposable = cappedRepository.findByKey("value").doOnNext(documents::add).subscribe();
|
||||
|
||||
assertThat(documents.poll(5, TimeUnit.SECONDS), is(notNullValue()));
|
||||
|
||||
@@ -191,7 +191,7 @@ public class ReactiveMongoRepositoryTests implements BeanClassLoaderAware, BeanF
|
||||
assertThat(documents.poll(5, TimeUnit.SECONDS), is(notNullValue()));
|
||||
assertThat(documents.isEmpty(), is(true));
|
||||
|
||||
cancellation.dispose();
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
@@ -208,7 +208,7 @@ public class ReactiveMongoRepositoryTests implements BeanClassLoaderAware, BeanF
|
||||
|
||||
BlockingQueue<CappedProjection> documents = new LinkedBlockingDeque<>(100);
|
||||
|
||||
Cancellation cancellation = cappedRepository.findProjectionByKey("value").doOnNext(documents::add).subscribe();
|
||||
Disposable disposable = cappedRepository.findProjectionByKey("value").doOnNext(documents::add).subscribe();
|
||||
|
||||
CappedProjection projection1 = documents.poll(5, TimeUnit.SECONDS);
|
||||
assertThat(projection1, is(notNullValue()));
|
||||
@@ -222,7 +222,7 @@ public class ReactiveMongoRepositoryTests implements BeanClassLoaderAware, BeanF
|
||||
|
||||
assertThat(documents.isEmpty(), is(true));
|
||||
|
||||
cancellation.dispose();
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
|
||||
@@ -206,10 +206,10 @@ public interface PersonRepository extends ReactiveMongoRepository<Person, String
|
||||
|
||||
Flux<Person> stream = repository.findByFirstname("Joe");
|
||||
|
||||
Cancellation cancellation = stream.doOnNext(person -> System.out.println(person)).subscribe();
|
||||
Disposable subscription = stream.doOnNext(person -> System.out.println(person)).subscribe();
|
||||
|
||||
// …
|
||||
|
||||
// Later: Dispose the stream
|
||||
cancellation.dispose();
|
||||
subscription.dispose();
|
||||
----
|
||||
|
||||
@@ -466,12 +466,12 @@ By default, MongoDB will automatically close a cursor when the client has exhaus
|
||||
----
|
||||
Flux<Person> stream = template.tail(query(where("name").is("Joe")), Person.class);
|
||||
|
||||
Cancellation cancellation = stream.doOnNext(person -> System.out.println(person)).subscribe();
|
||||
Disposable subscription = stream.doOnNext(person -> System.out.println(person)).subscribe();
|
||||
|
||||
// …
|
||||
|
||||
// Later: Dispose the stream
|
||||
cancellation.dispose();
|
||||
subscription.dispose();
|
||||
----
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user