|
39 | 39 | import java.util.stream.Collectors;
|
40 | 40 |
|
41 | 41 | import org.assertj.core.api.Assertions;
|
| 42 | +import org.bson.BsonDocument; |
| 43 | +import org.bson.BsonString; |
42 | 44 | import org.bson.Document;
|
43 | 45 | import org.bson.conversions.Bson;
|
44 | 46 | import org.bson.types.ObjectId;
|
|
110 | 112 | import com.mongodb.client.result.InsertOneResult;
|
111 | 113 | import com.mongodb.client.result.UpdateResult;
|
112 | 114 | import com.mongodb.reactivestreams.client.AggregatePublisher;
|
| 115 | +import com.mongodb.reactivestreams.client.ChangeStreamPublisher; |
113 | 116 | import com.mongodb.reactivestreams.client.DistinctPublisher;
|
114 | 117 | import com.mongodb.reactivestreams.client.FindPublisher;
|
115 | 118 | import com.mongodb.reactivestreams.client.MapReducePublisher;
|
@@ -145,6 +148,7 @@ public class ReactiveMongoTemplateUnitTests {
|
145 | 148 | @Mock DistinctPublisher distinctPublisher;
|
146 | 149 | @Mock Publisher deletePublisher;
|
147 | 150 | @Mock MapReducePublisher mapReducePublisher;
|
| 151 | + @Mock ChangeStreamPublisher changeStreamPublisher; |
148 | 152 |
|
149 | 153 | private MongoExceptionTranslator exceptionTranslator = new MongoExceptionTranslator();
|
150 | 154 | private MappingMongoConverter converter;
|
@@ -1455,6 +1459,22 @@ void createCollectionShouldSetUpTimeSeries() {
|
1455 | 1459 | .granularity(TimeSeriesGranularity.HOURS).toString());
|
1456 | 1460 | }
|
1457 | 1461 |
|
| 1462 | + @Test // GH-4167 |
| 1463 | + void changeStreamOptionStartAftershouldApplied() { |
| 1464 | + |
| 1465 | + when(factory.getMongoDatabase(anyString())).thenReturn(Mono.just(db)); |
| 1466 | + |
| 1467 | + when(collection.watch(any(Class.class))).thenReturn(changeStreamPublisher); |
| 1468 | + when(changeStreamPublisher.batchSize(anyInt())).thenReturn(changeStreamPublisher); |
| 1469 | + when(changeStreamPublisher.startAfter(any())).thenReturn(changeStreamPublisher); |
| 1470 | + when(changeStreamPublisher.fullDocument(any())).thenReturn(changeStreamPublisher); |
| 1471 | + |
| 1472 | + BsonDocument token = new BsonDocument("token", new BsonString("id")); |
| 1473 | + template.changeStream("database", "collection", ChangeStreamOptions.builder().startAfter(token).build(), Object.class).subscribe(); |
| 1474 | + |
| 1475 | + verify(changeStreamPublisher).startAfter(eq(token)); |
| 1476 | + } |
| 1477 | + |
1458 | 1478 | private void stubFindSubscribe(Document document) {
|
1459 | 1479 |
|
1460 | 1480 | Publisher<Document> realPublisher = Flux.just(document);
|
|
0 commit comments