Skip to content

Commit b372c57

Browse files
committed
add comment on RxKotlin with 1 thread
1 parent 30d5ebd commit b372c57

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

core-kotlin-modules/core-kotlin-collections-6/src/test/kotlin/com/baeldung/parallelOperationsCollections/ParallelOperationCollectionsUnitTest.kt

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ class ParallelOperationCollectionsUnitTest {
4242
)
4343
}
4444

45-
private fun String.printAsHeader() {
46-
logger.info(this)
47-
}
48-
4945
private fun Person.setAdult() {
5046
this.isAdult = this.age >= 18
5147
logger.info(this.toString())
@@ -79,7 +75,7 @@ class ParallelOperationCollectionsUnitTest {
7975
@OptIn(ExperimentalCoroutinesApi::class)
8076
@Test
8177
fun `using coroutines for parallel operations with Flow`() = runBlocking {
82-
"Using Kotlin Flow".printAsHeader()
78+
logger.info("Using Kotlin Flow")
8379
val startTime = Instant.now()
8480

8581
val filteredPeople = people.asFlow()
@@ -103,7 +99,7 @@ class ParallelOperationCollectionsUnitTest {
10399

104100
@Test
105101
fun `using RxJava for parallel operations`() { // Observable.class from io.reactivex;
106-
"Using RxJava".printAsHeader()
102+
logger.info("Using RxJava")
107103
val startTime = Instant.now()
108104

109105
val observable = Observable.fromIterable(people)
@@ -126,7 +122,7 @@ class ParallelOperationCollectionsUnitTest {
126122

127123
@Test
128124
fun `using RxKotlin for parallel operations`() { // ObservableKt.kt.class from io.reactivex.rxkotlin
129-
"Using RxKotlin".printAsHeader()
125+
logger.info("Using RxKotlin")
130126
val startTime = Instant.now()
131127

132128
val observable = people.toObservable()
@@ -148,12 +144,12 @@ class ParallelOperationCollectionsUnitTest {
148144

149145
@Test
150146
fun `using RxKotlin but still use 1 thread`() { // ObservableKt.kt.class from io.reactivex.rxkotlin
151-
"Using RxKotlin 1 thread".printAsHeader()
147+
logger.info("Using RxKotlin 1 thread")
152148
val startTime = Instant.now()
153149

154150
val observable = people.toObservable()
155151
.subscribeOn(Schedulers.io())
156-
.flatMap { Observable.just(it) }
152+
.flatMap { Observable.just(it) } // Without using the maxConcurrency parameter, so it only uses 1 thread.
157153
.doOnNext { person -> person.setAdult() }
158154
.filter { it.age > 15 }.toList()
159155
.map { it.sortedBy { person -> person.age } }.blockingGet()
@@ -165,7 +161,7 @@ class ParallelOperationCollectionsUnitTest {
165161

166162
@Test
167163
fun `using parallelStream()`() {
168-
"Using Stream API".printAsHeader()
164+
logger.info("Using Stream API")
169165
val startTime = Instant.now()
170166

171167
val filteredPeople = people.parallelStream()
@@ -183,7 +179,7 @@ class ParallelOperationCollectionsUnitTest {
183179

184180
@Test
185181
fun `using ExecutorService for parallel operations`() {
186-
"Using ExecutorService".printAsHeader()
182+
logger.info("Using ExecutorService")
187183
val startTime = Instant.now()
188184

189185
val executor = Executors.newFixedThreadPool(people.size)

0 commit comments

Comments
 (0)