Skip to content

Commit 40736f7

Browse files
committed
DATAMONGO-2255 - Polishing.
Add ticket references. Rename allAsFlow() to flow() to simplify naming. Remove extension for tail() as partial flow consumption for streams requires completion and a tailable cursor represents an infinite stream. Related ticket: Kotlin/kotlinx.coroutines#1077. Original pull request: #736.
1 parent 02931ec commit 40736f7

10 files changed

+26
-56
lines changed

spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/ExecutableFindOperationExtensions.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ inline fun <reified T : Any> ExecutableFindOperation.query(): ExecutableFindOper
3939
query(T::class.java)
4040

4141
/**
42-
* Extension for [ExecutableFindOperation.FindWithProjection. as] providing a [KClass] based variant.
42+
* Extension for [ExecutableFindOperation.FindWithProjection.as] providing a [KClass] based variant.
4343
*
4444
* @author Sebastien Deleuze
4545
* @author Mark Paluch
@@ -50,7 +50,7 @@ fun <T : Any> ExecutableFindOperation.FindWithProjection<*>.asType(resultType: K
5050
`as`(resultType.java)
5151

5252
/**
53-
* Extension for [ExecutableFindOperation.FindWithProjection. as] leveraging reified type parameters.
53+
* Extension for [ExecutableFindOperation.FindWithProjection.as] leveraging reified type parameters.
5454
*
5555
* @author Sebastien Deleuze
5656
* @author Mark Paluch
@@ -60,7 +60,7 @@ inline fun <reified T : Any> ExecutableFindOperation.FindWithProjection<*>.asTyp
6060
`as`(T::class.java)
6161

6262
/**
63-
* Extension for [ExecutableFindOperation.DistinctWithProjection. as] providing a [KClass] based variant.
63+
* Extension for [ExecutableFindOperation.DistinctWithProjection.as] providing a [KClass] based variant.
6464
*
6565
* @author Christoph Strobl
6666
* @since 2.1
@@ -70,7 +70,7 @@ fun <T : Any> ExecutableFindOperation.DistinctWithProjection.asType(resultType:
7070
`as`(resultType.java);
7171

7272
/**
73-
* Extension for [ExecutableFindOperation.DistinctWithProjection. as] leveraging reified type parameters.
73+
* Extension for [ExecutableFindOperation.DistinctWithProjection.as] leveraging reified type parameters.
7474
*
7575
* @author Christoph Strobl
7676
* @since 2.1

spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/ReactiveAggregationOperationExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ inline fun <reified T : Any> ReactiveAggregationOperation.aggregateAndReturn():
4949
* @since 2.2
5050
*/
5151
@FlowPreview
52-
fun <T : Any> ReactiveAggregationOperation.TerminatingAggregationOperation<T>.allAsFlow(batchSize: Int = 1): Flow<T> =
52+
fun <T : Any> ReactiveAggregationOperation.TerminatingAggregationOperation<T>.flow(batchSize: Int = 1): Flow<T> =
5353
all().asFlow(batchSize)

spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/ReactiveFindOperationExtensions.kt

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,9 @@ suspend fun <T : Any> ReactiveFindOperation.TerminatingFind<T>.awaitExists(): Bo
143143
* @author Sebastien Deleuze
144144
*/
145145
@FlowPreview
146-
fun <T : Any> ReactiveFindOperation.TerminatingFind<T>.allAsFlow(batchSize: Int = 1): Flow<T> =
146+
fun <T : Any> ReactiveFindOperation.TerminatingFind<T>.flow(batchSize: Int = 1): Flow<T> =
147147
all().asFlow(batchSize)
148148

149-
/**
150-
* Coroutines [Flow] variant of [ReactiveFindOperation.TerminatingFind.tail].
151-
*
152-
* Backpressure is controlled by [batchSize] parameter that controls the size of in-flight elements
153-
* and [org.reactivestreams.Subscription.request] size.
154-
*
155-
* @author Sebastien Deleuze
156-
*/
157-
@FlowPreview
158-
fun <T : Any> ReactiveFindOperation.TerminatingFind<T>.tailAsFlow(batchSize: Int = 1): Flow<T> =
159-
tail().asFlow(batchSize)
160-
161149
/**
162150
* Coroutines [Flow] variant of [ReactiveFindOperation.TerminatingFindNear.all].
163151
*
@@ -167,7 +155,7 @@ fun <T : Any> ReactiveFindOperation.TerminatingFind<T>.tailAsFlow(batchSize: Int
167155
* @author Sebastien Deleuze
168156
*/
169157
@FlowPreview
170-
fun <T : Any> ReactiveFindOperation.TerminatingFindNear<T>.allAsFlow(batchSize: Int = 1): Flow<GeoResult<T>> =
158+
fun <T : Any> ReactiveFindOperation.TerminatingFindNear<T>.flow(batchSize: Int = 1): Flow<GeoResult<T>> =
171159
all().asFlow(batchSize)
172160

173161
/**
@@ -180,5 +168,5 @@ fun <T : Any> ReactiveFindOperation.TerminatingFindNear<T>.allAsFlow(batchSize:
180168
* @since 2.2
181169
*/
182170
@FlowPreview
183-
fun <T : Any> ReactiveFindOperation.TerminatingDistinct<T>.allAsFlow(batchSize: Int = 1): Flow<T> =
171+
fun <T : Any> ReactiveFindOperation.TerminatingDistinct<T>.flow(batchSize: Int = 1): Flow<T> =
184172
all().asFlow(batchSize)

spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/ReactiveInsertOperationExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ suspend inline fun <reified T: Any> ReactiveInsertOperation.TerminatingInsert<T>
6060
* @since 2.2
6161
*/
6262
@FlowPreview
63-
fun <T : Any> ReactiveInsertOperation.TerminatingInsert<T>.allAsFlow(objects: Collection<T>, batchSize: Int = 1): Flow<T> =
63+
fun <T : Any> ReactiveInsertOperation.TerminatingInsert<T>.flow(objects: Collection<T>, batchSize: Int = 1): Flow<T> =
6464
all(objects).asFlow(batchSize)

spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/ReactiveMapReduceOperationExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ inline fun <reified T : Any> ReactiveMapReduceOperation.MapReduceWithProjection<
6969
* @since 2.2
7070
*/
7171
@FlowPreview
72-
fun <T : Any> ReactiveMapReduceOperation.TerminatingMapReduce<T>.allAsFlow(batchSize: Int = 1): Flow<T> =
72+
fun <T : Any> ReactiveMapReduceOperation.TerminatingMapReduce<T>.flow(batchSize: Int = 1): Flow<T> =
7373
all().asFlow(batchSize)

spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/ReactiveAggregationOperationExtensionsTests.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import io.mockk.verify
2222
import kotlinx.coroutines.FlowPreview
2323
import kotlinx.coroutines.flow.toList
2424
import kotlinx.coroutines.runBlocking
25-
import org.assertj.core.api.Assertions
25+
import org.assertj.core.api.Assertions.assertThat
2626
import org.junit.Test
2727
import reactor.core.publisher.Flux
2828

@@ -48,15 +48,15 @@ class ReactiveAggregationOperationExtensionsTests {
4848
verify { operation.aggregateAndReturn(First::class.java) }
4949
}
5050

51-
@Test
51+
@Test // DATAMONGO-2255
5252
@FlowPreview
5353
fun terminatingAggregationOperationAllAsFlow() {
5454

5555
val spec = mockk<ReactiveAggregationOperation.TerminatingAggregationOperation<String>>()
5656
every { spec.all() } returns Flux.just("foo", "bar", "baz")
5757

5858
runBlocking {
59-
Assertions.assertThat(spec.allAsFlow().toList()).contains("foo", "bar", "baz")
59+
assertThat(spec.flow().toList()).contains("foo", "bar", "baz")
6060
}
6161

6262
verify {

spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/ReactiveFindOperationExtensionsTests.kt

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import reactor.core.publisher.Mono
3434
* @author Mark Paluch
3535
* @author Sebastien Deleuze
3636
*/
37+
@FlowPreview
3738
class ReactiveFindOperationExtensionsTests {
3839

3940
val operation = mockk<ReactiveFindOperation>(relaxed = true)
@@ -234,40 +235,22 @@ class ReactiveFindOperationExtensionsTests {
234235
}
235236
}
236237

237-
@Test
238-
@FlowPreview
238+
@Test // DATAMONGO-2255
239239
fun terminatingFindAllAsFlow() {
240240

241241
val spec = mockk<ReactiveFindOperation.TerminatingFind<String>>()
242242
every { spec.all() } returns Flux.just("foo", "bar", "baz")
243243

244244
runBlocking {
245-
assertThat(spec.allAsFlow().toList()).contains("foo", "bar", "baz")
245+
assertThat(spec.flow().toList()).contains("foo", "bar", "baz")
246246
}
247247

248248
verify {
249249
spec.all()
250250
}
251251
}
252252

253-
@Test
254-
@FlowPreview
255-
fun terminatingFindTailAsFlow() {
256-
257-
val spec = mockk<ReactiveFindOperation.TerminatingFind<String>>()
258-
every { spec.tail() } returns Flux.just("foo", "bar", "baz")
259-
260-
runBlocking {
261-
assertThat(spec.tailAsFlow().toList()).contains("foo", "bar", "baz")
262-
}
263-
264-
verify {
265-
spec.tail()
266-
}
267-
}
268-
269-
@Test
270-
@FlowPreview
253+
@Test // DATAMONGO-2255
271254
fun terminatingFindNearAllAsFlow() {
272255

273256
val spec = mockk<ReactiveFindOperation.TerminatingFindNear<String>>()
@@ -277,23 +260,22 @@ class ReactiveFindOperationExtensionsTests {
277260
every { spec.all() } returns Flux.just(foo, bar, baz)
278261

279262
runBlocking {
280-
assertThat(spec.allAsFlow().toList()).contains(foo, bar, baz)
263+
assertThat(spec.flow().toList()).contains(foo, bar, baz)
281264
}
282265

283266
verify {
284267
spec.all()
285268
}
286269
}
287270

288-
@Test
289-
@FlowPreview
271+
@Test // DATAMONGO-2255
290272
fun terminatingDistinctAllAsFlow() {
291273

292274
val spec = mockk<ReactiveFindOperation.TerminatingDistinct<String>>()
293275
every { spec.all() } returns Flux.just("foo", "bar", "baz")
294276

295277
runBlocking {
296-
assertThat(spec.allAsFlow().toList()).contains("foo", "bar", "baz")
278+
assertThat(spec.flow().toList()).contains("foo", "bar", "baz")
297279
}
298280

299281
verify {

spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/ReactiveInsertOperationExtensionsTests.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ReactiveInsertOperationExtensionsTests {
6464
}
6565
}
6666

67-
@Test
67+
@Test // DATAMONGO-2255
6868
@FlowPreview
6969
fun terminatingInsertAllAsFlow() {
7070

@@ -73,7 +73,7 @@ class ReactiveInsertOperationExtensionsTests {
7373
every { insert.all(any()) } returns Flux.fromIterable(list)
7474

7575
runBlocking {
76-
assertThat(insert.allAsFlow(list).toList()).containsAll(list)
76+
assertThat(insert.flow(list).toList()).containsAll(list)
7777
}
7878

7979
verify {

spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/ReactiveMapReduceOperationExtensionsTests.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import io.mockk.verify
2222
import kotlinx.coroutines.FlowPreview
2323
import kotlinx.coroutines.flow.toList
2424
import kotlinx.coroutines.runBlocking
25-
import org.assertj.core.api.Assertions
25+
import org.assertj.core.api.Assertions.assertThat
2626
import org.junit.Test
2727
import reactor.core.publisher.Flux
2828

@@ -64,15 +64,15 @@ class ReactiveMapReduceOperationExtensionsTests {
6464
verify { operationWithProjection.`as`(User::class.java) }
6565
}
6666

67-
@Test
67+
@Test // DATAMONGO-2255
6868
@FlowPreview
6969
fun terminatingMapReduceAllAsFlow() {
7070

7171
val spec = mockk<ReactiveMapReduceOperation.TerminatingMapReduce<String>>()
7272
every { spec.all() } returns Flux.just("foo", "bar", "baz")
7373

7474
runBlocking {
75-
Assertions.assertThat(spec.allAsFlow().toList()).contains("foo", "bar", "baz")
75+
assertThat(spec.flow().toList()).contains("foo", "bar", "baz")
7676
}
7777

7878
verify {

spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/ReactiveRemoveOperationExtensionsTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ReactiveRemoveOperationExtensionsTests {
6666
}
6767
}
6868

69-
@Test
69+
@Test // DATAMONGO-2255
7070
@FlowPreview
7171
fun terminatingRemoveFindAndRemoveAsFlow() {
7272

0 commit comments

Comments
 (0)