You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core-kotlin-modules/core-kotlin-collections-6/src/test/kotlin/com/baeldung/parallelOperationsCollections/ParallelOperationCollectionsUnitTest.kt
+7-11Lines changed: 7 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -42,10 +42,6 @@ class ParallelOperationCollectionsUnitTest {
42
42
)
43
43
}
44
44
45
-
privatefun String.printAsHeader() {
46
-
logger.info(this)
47
-
}
48
-
49
45
privatefun Person.setAdult() {
50
46
this.isAdult =this.age >=18
51
47
logger.info(this.toString())
@@ -79,7 +75,7 @@ class ParallelOperationCollectionsUnitTest {
79
75
@OptIn(ExperimentalCoroutinesApi::class)
80
76
@Test
81
77
fun`using coroutines for parallel operations with Flow`() = runBlocking {
82
-
"Using Kotlin Flow".printAsHeader()
78
+
logger.info("Using Kotlin Flow")
83
79
val startTime =Instant.now()
84
80
85
81
val filteredPeople = people.asFlow()
@@ -103,7 +99,7 @@ class ParallelOperationCollectionsUnitTest {
103
99
104
100
@Test
105
101
fun`using RxJava for parallel operations`() { // Observable.class from io.reactivex;
106
-
"Using RxJava".printAsHeader()
102
+
logger.info("Using RxJava")
107
103
val startTime =Instant.now()
108
104
109
105
val observable =Observable.fromIterable(people)
@@ -126,7 +122,7 @@ class ParallelOperationCollectionsUnitTest {
126
122
127
123
@Test
128
124
fun`using RxKotlin for parallel operations`() { // ObservableKt.kt.class from io.reactivex.rxkotlin
129
-
"Using RxKotlin".printAsHeader()
125
+
logger.info("Using RxKotlin")
130
126
val startTime =Instant.now()
131
127
132
128
val observable = people.toObservable()
@@ -148,12 +144,12 @@ class ParallelOperationCollectionsUnitTest {
148
144
149
145
@Test
150
146
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")
152
148
val startTime =Instant.now()
153
149
154
150
val observable = people.toObservable()
155
151
.subscribeOn(Schedulers.io())
156
-
.flatMap { Observable.just(it) }
152
+
.flatMap { Observable.just(it) }// Without using the maxConcurrency parameter, so it only uses 1 thread.
157
153
.doOnNext { person -> person.setAdult() }
158
154
.filter { it.age >15 }.toList()
159
155
.map { it.sortedBy { person -> person.age } }.blockingGet()
@@ -165,7 +161,7 @@ class ParallelOperationCollectionsUnitTest {
165
161
166
162
@Test
167
163
fun`using parallelStream()`() {
168
-
"Using Stream API".printAsHeader()
164
+
logger.info("Using Stream API")
169
165
val startTime =Instant.now()
170
166
171
167
val filteredPeople = people.parallelStream()
@@ -183,7 +179,7 @@ class ParallelOperationCollectionsUnitTest {
183
179
184
180
@Test
185
181
fun`using ExecutorService for parallel operations`() {
186
-
"Using ExecutorService".printAsHeader()
182
+
logger.info("Using ExecutorService")
187
183
val startTime =Instant.now()
188
184
189
185
val executor =Executors.newFixedThreadPool(people.size)
0 commit comments