Get rid of deprecated API where possible, add Channel.RENDEZVOUS
diff --git a/binary-compatibility-validator/reference-public-api/kotlinx-coroutines-core.txt b/binary-compatibility-validator/reference-public-api/kotlinx-coroutines-core.txt
index afb2184..cd60af1 100644
--- a/binary-compatibility-validator/reference-public-api/kotlinx-coroutines-core.txt
+++ b/binary-compatibility-validator/reference-public-api/kotlinx-coroutines-core.txt
@@ -716,11 +716,13 @@
public abstract interface class kotlinx/coroutines/experimental/channels/Channel : kotlinx/coroutines/experimental/channels/ReceiveChannel, kotlinx/coroutines/experimental/channels/SendChannel {
public static final field CONFLATED I
public static final field Factory Lkotlinx/coroutines/experimental/channels/Channel$Factory;
+ public static final field RENDEZVOUS I
public static final field UNLIMITED I
}
public final class kotlinx/coroutines/experimental/channels/Channel$Factory {
public static final field CONFLATED I
+ public static final field RENDEZVOUS I
public static final field UNLIMITED I
public final synthetic fun invoke (I)Lkotlinx/coroutines/experimental/channels/Channel;
public static synthetic fun invoke$default (Lkotlinx/coroutines/experimental/channels/Channel$Factory;IILjava/lang/Object;)Lkotlinx/coroutines/experimental/channels/Channel;
diff --git a/common/kotlinx-coroutines-core-common/src/Annotations.kt b/common/kotlinx-coroutines-core-common/src/Annotations.kt
index 7ba8b34..7aae365 100644
--- a/common/kotlinx-coroutines-core-common/src/Annotations.kt
+++ b/common/kotlinx-coroutines-core-common/src/Annotations.kt
@@ -15,10 +15,9 @@
// todo: Experimental WARNING
public annotation class ExperimentalCoroutinesApi
-
/**
* Marks declarations that are **obsolete** in coroutines API, which means that the design of the corresponding
- * declarations has serious known flaws and they must be redesigned in the future.
+ * declarations has serious known flaws and they will be redesigned in the future.
* Roughly speaking, these declarations will be deprecated in the future but there is no replacement for them yet,
* so they cannot be deprecated right away.
*/
@@ -36,4 +35,4 @@
*/
@Retention(value = AnnotationRetention.SOURCE)
// todo: Experimental ERROR
-public annotation class InternalCoroutinesApi
\ No newline at end of file
+public annotation class InternalCoroutinesApi
diff --git a/common/kotlinx-coroutines-core-common/src/Delay.kt b/common/kotlinx-coroutines-core-common/src/Delay.kt
index 96dd6a4..2a68c85 100644
--- a/common/kotlinx-coroutines-core-common/src/Delay.kt
+++ b/common/kotlinx-coroutines-core-common/src/Delay.kt
@@ -19,7 +19,7 @@
*/
@InternalCoroutinesApi // todo: Remove references from other docs
public interface Delay {
- @Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compat")
+ @Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compatibility")
suspend fun delay(time: Long, unit: TimeUnit = TimeUnit.MILLISECONDS) = delay(time.convertToMillis(unit))
/**
@@ -33,7 +33,7 @@
return suspendCancellableCoroutine { scheduleResumeAfterDelay(time, it) }
}
- @Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compat")
+ @Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compatibility")
fun scheduleResumeAfterDelay(time: Long, unit: TimeUnit, continuation: CancellableContinuation<Unit>) =
scheduleResumeAfterDelay(time.convertToMillis(unit), continuation)
@@ -54,7 +54,7 @@
*/
fun scheduleResumeAfterDelay(timeMillis: Long, continuation: CancellableContinuation<Unit>)
- @Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compat")
+ @Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compatibility")
fun invokeOnTimeout(time: Long, unit: TimeUnit, block: Runnable): DisposableHandle =
DefaultDelay.invokeOnTimeout(time.convertToMillis(unit), block)
@@ -69,7 +69,7 @@
DefaultDelay.invokeOnTimeout(timeMillis, block)
}
-@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compat")
+@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compatibility")
public suspend fun delay(timeMillis: Int) =
delay(timeMillis.toLong(), TimeUnit.MILLISECONDS)
diff --git a/common/kotlinx-coroutines-core-common/src/Scheduled.kt b/common/kotlinx-coroutines-core-common/src/Scheduled.kt
index 10e0306..aa3a285 100644
--- a/common/kotlinx-coroutines-core-common/src/Scheduled.kt
+++ b/common/kotlinx-coroutines-core-common/src/Scheduled.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.selects.*
import kotlinx.coroutines.experimental.timeunit.*
-@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compat")
+@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compatibility")
public suspend fun <T> withTimeout(time: Int, block: suspend CoroutineScope.() -> T): T =
withTimeout(time.toLong(), block)
@@ -39,7 +39,7 @@
public suspend fun <T> withTimeout(time: Long, unit: TimeUnit = TimeUnit.MILLISECONDS, block: suspend CoroutineScope.() -> T): T =
withTimeout(time.convertToMillis(unit), block)
-@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compat")
+@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compatibility")
public suspend fun <T> withTimeoutOrNull(time: Int, block: suspend CoroutineScope.() -> T): T? =
withTimeoutOrNull(time.toLong(), TimeUnit.MILLISECONDS, block)
diff --git a/common/kotlinx-coroutines-core-common/src/channels/Channel.kt b/common/kotlinx-coroutines-core-common/src/channels/Channel.kt
index 745f8c5..6c48c64 100644
--- a/common/kotlinx-coroutines-core-common/src/channels/Channel.kt
+++ b/common/kotlinx-coroutines-core-common/src/channels/Channel.kt
@@ -2,12 +2,14 @@
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
+@file:Suppress("FunctionName")
+
package kotlinx.coroutines.experimental.channels
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.Channel.Factory.CONFLATED
+import kotlinx.coroutines.experimental.channels.Channel.Factory.RENDEZVOUS
import kotlinx.coroutines.experimental.channels.Channel.Factory.UNLIMITED
-import kotlinx.coroutines.experimental.internal.*
import kotlinx.coroutines.experimental.selects.*
/**
@@ -350,14 +352,17 @@
*/
public companion object Factory {
/**
- * Requests channel with unlimited capacity buffer in `Channel(...)` factory function --
- * the [LinkedListChannel] gets created.
+ * Requests channel with unlimited capacity buffer in `Channel(...)` factory function
*/
public const val UNLIMITED = Int.MAX_VALUE
/**
- * Requests conflated channel in `Channel(...)` factory function --
- * the [ConflatedChannel] gets created.
+ * Requests rendezvous channel in `Channel(...)` factory function -- the `RendezvousChannel` gets created.
+ */
+ public const val RENDEZVOUS = 0
+
+ /**
+ * Requests conflated channel in `Channel(...)` factory function -- the `ConflatedChannel` gets created.
*/
public const val CONFLATED = -1
@@ -373,7 +378,7 @@
/**
* Creates a channel without a buffer -- [RendezvousChannel].
*/
-@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compat")
+@Deprecated(level = DeprecationLevel.HIDDEN, message = "binary compatibility")
public fun <E> Channel(): Channel<E> = RendezvousChannel<E>()
/**
@@ -384,7 +389,7 @@
*/
public fun <E> Channel(capacity: Int = 0): Channel<E> =
when (capacity) {
- 0 -> RendezvousChannel()
+ RENDEZVOUS -> RendezvousChannel()
UNLIMITED -> LinkedListChannel()
CONFLATED -> ConflatedChannel()
else -> ArrayChannel(capacity)
diff --git a/common/kotlinx-coroutines-core-common/src/channels/RendezvousChannel.kt b/common/kotlinx-coroutines-core-common/src/channels/RendezvousChannel.kt
index fec13d9..0c7f2d0 100644
--- a/common/kotlinx-coroutines-core-common/src/channels/RendezvousChannel.kt
+++ b/common/kotlinx-coroutines-core-common/src/channels/RendezvousChannel.kt
@@ -21,7 +21,7 @@
public open class RendezvousChannel<E>
@Deprecated(
"Replace with Channel factory function",
- replaceWith = ReplaceWith("Channel()")
+ replaceWith = ReplaceWith("Channel(Channel.RENDEZVOUS)")
)
constructor() : AbstractChannel<E>() {
protected final override val isBufferAlwaysEmpty: Boolean get() = true
diff --git a/common/kotlinx-coroutines-core-common/test/AsyncLazyTest.kt b/common/kotlinx-coroutines-core-common/test/AsyncLazyTest.kt
index 2278ae0..50ce50d 100644
--- a/common/kotlinx-coroutines-core-common/test/AsyncLazyTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/AsyncLazyTest.kt
@@ -19,10 +19,10 @@
}
expect(2)
assertTrue(!d.isActive && !d.isCompleted)
- assertTrue(d.await() == 42)
+ assertEquals(d.await(), 42)
assertTrue(!d.isActive && d.isCompleted && !d.isCompletedExceptionally)
expect(4)
- assertTrue(d.await() == 42) // second await -- same result
+ assertEquals(d.await(), 42) // second await -- same result
finish(5)
}
@@ -37,10 +37,10 @@
}
expect(2)
assertTrue(!d.isActive && !d.isCompleted)
- assertTrue(d.await() == 42)
+ assertEquals(d.await(), 42)
assertTrue(!d.isActive && d.isCompleted && !d.isCompletedExceptionally)
expect(5)
- assertTrue(d.await() == 42) // second await -- same result
+ assertEquals(d.await(), 42) // second await -- same result
finish(6)
}
@@ -66,7 +66,7 @@
yield() // yield to second child (lazy async is not computing yet)
expect(5)
assertTrue(!d.isActive && !d.isCompleted)
- assertTrue(d.await() == 42) // starts computing
+ assertEquals(d.await(), 42) // starts computing
assertTrue(!d.isActive && d.isCompleted && !d.isCompletedExceptionally)
finish(8)
}
@@ -135,13 +135,13 @@
yield() // yield to started coroutine
assertTrue(!d.isActive && d.isCompleted && !d.isCompletedExceptionally) // and it finishes
expect(5)
- assertTrue(d.await() == 42) // await sees result
+ assertEquals(d.await(), 42) // await sees result
finish(6)
}
@Test
fun testCancelBeforeStart() = runTest(
- expected = { it is JobCancellationException }
+ expected = { it is CancellationException }
) {
expect(1)
val d = async(start = CoroutineStart.LAZY) {
@@ -155,7 +155,7 @@
assertTrue(!d.cancel())
assertTrue(!d.start())
finish(3)
- assertTrue(d.await() == 42) // await shall throw CancellationException
+ assertEquals(d.await(), 42) // await shall throw CancellationException
expectUnreached()
}
@@ -183,7 +183,7 @@
assertTrue(d.cancel())
assertTrue(!d.isActive && !d.isCompletedExceptionally && d.isCancelled) // still cancelling
finish(6)
- assertTrue(d.await() == 42) // await shall throw CancellationException
+ assertEquals(d.await(), 42) // await shall throw CancellationException
expectUnreached()
}
diff --git a/common/kotlinx-coroutines-core-common/test/AsyncTest.kt b/common/kotlinx-coroutines-core-common/test/AsyncTest.kt
index 09910e0..5ccb97f 100644
--- a/common/kotlinx-coroutines-core-common/test/AsyncTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/AsyncTest.kt
@@ -232,7 +232,7 @@
try {
expect(1)
deferred.await()
- } catch (e: JobCancellationException) {
+ } catch (e: CancellationException) {
finish(3)
}
}
diff --git a/common/kotlinx-coroutines-core-common/test/CancellableContinuationTest.kt b/common/kotlinx-coroutines-core-common/test/CancellableContinuationTest.kt
index 6288607..c56cc17 100644
--- a/common/kotlinx-coroutines-core-common/test/CancellableContinuationTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/CancellableContinuationTest.kt
@@ -80,7 +80,7 @@
suspendCancellableCoroutine<Unit> { c ->
continuation = c
}
- } catch (e: JobCancellationException) {
+ } catch (e: CancellationException) {
expect(3)
}
}
@@ -105,7 +105,7 @@
suspendCancellableCoroutine<Unit> { c ->
continuation = c
}
- } catch (e: JobCancellationException) {
+ } catch (e: CancellationException) {
expect(3)
}
}
diff --git a/common/kotlinx-coroutines-core-common/test/CompletableDeferredTest.kt b/common/kotlinx-coroutines-core-common/test/CompletableDeferredTest.kt
index bc8c3dd..4b78b30 100644
--- a/common/kotlinx-coroutines-core-common/test/CompletableDeferredTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/CompletableDeferredTest.kt
@@ -2,7 +2,7 @@
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
-@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913
+@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED", "DEPRECATION") // KT-21913
package kotlinx.coroutines.experimental
diff --git a/common/kotlinx-coroutines-core-common/test/CoroutineScopeTest.kt b/common/kotlinx-coroutines-core-common/test/CoroutineScopeTest.kt
index ff1f987..875f49d 100644
--- a/common/kotlinx-coroutines-core-common/test/CoroutineScopeTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/CoroutineScopeTest.kt
@@ -118,7 +118,7 @@
try {
callJobScoped()
expectUnreached()
- } catch (e: JobCancellationException) {
+ } catch (e: CancellationException) {
expect(5)
assertNull(e.cause)
}
diff --git a/common/kotlinx-coroutines-core-common/test/CoroutinesTest.kt b/common/kotlinx-coroutines-core-common/test/CoroutinesTest.kt
index 8cdd396..d4da2fb 100644
--- a/common/kotlinx-coroutines-core-common/test/CoroutinesTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/CoroutinesTest.kt
@@ -240,9 +240,8 @@
try {
job.cancelAndJoin() // join should crash on child's exception but it will be wrapped into JobCancellationException
} catch (e: Throwable) {
- e as JobCancellationException // type assertion
+ e as CancellationException // type assertion
assertTrue(e.cause is TestException)
- assertTrue(e.job === coroutineContext[Job])
throw e
}
expectUnreached()
@@ -280,7 +279,7 @@
expect(3)
parent.cancelChildren()
expect(4)
- parent.joinChildren() // will yield to child
+ parent.children.forEach { it.join() } // will yield to child
assertTrue(parent.isActive) // make sure it did not cancel parent
finish(6)
}
diff --git a/common/kotlinx-coroutines-core-common/test/DelayTest.kt b/common/kotlinx-coroutines-core-common/test/DelayTest.kt
index b98f73f..69cb52e 100644
--- a/common/kotlinx-coroutines-core-common/test/DelayTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/DelayTest.kt
@@ -3,7 +3,7 @@
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
-@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913
+@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED", "DEPRECATION") // KT-21913
package kotlinx.coroutines.experimental
@@ -13,22 +13,22 @@
class DelayTest : TestBase() {
@Test
- fun testCancellation() = runTest(expected = {it is JobCancellationException}) {
+ fun testCancellation() = runTest(expected = {it is CancellationException }) {
runAndCancel(3600, TimeUnit.SECONDS)
}
@Test
- fun testMaxLongValue()= runTest(expected = {it is JobCancellationException}) {
+ fun testMaxLongValue()= runTest(expected = {it is CancellationException }) {
runAndCancel(Long.MAX_VALUE)
}
@Test
- fun testMaxIntValue()= runTest(expected = {it is JobCancellationException}) {
+ fun testMaxIntValue()= runTest(expected = {it is CancellationException }) {
runAndCancel(Int.MAX_VALUE.toLong())
}
@Test
- fun testOverflowOnUnitConversion()= runTest(expected = {it is JobCancellationException}) {
+ fun testOverflowOnUnitConversion()= runTest(expected = {it is CancellationException }) {
runAndCancel(Long.MAX_VALUE, TimeUnit.SECONDS)
}
diff --git a/common/kotlinx-coroutines-core-common/test/NonCancellableTest.kt b/common/kotlinx-coroutines-core-common/test/NonCancellableTest.kt
index 7a1dbfe..94050ee 100644
--- a/common/kotlinx-coroutines-core-common/test/NonCancellableTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/NonCancellableTest.kt
@@ -30,7 +30,7 @@
try {
job.await()
expectUnreached()
- } catch (e: JobCancellationException) {
+ } catch (e: CancellationException) {
assertNull(e.cause)
finish(6)
}
@@ -90,7 +90,7 @@
try {
job.await()
expectUnreached()
- } catch (e: JobCancellationException) {
+ } catch (e: CancellationException) {
finish(6)
}
}
@@ -119,7 +119,7 @@
try {
job.await()
expectUnreached()
- } catch (e: JobCancellationException) {
+ } catch (e: CancellationException) {
assertNull(e.cause)
finish(7)
}
diff --git a/common/kotlinx-coroutines-core-common/test/WithContextTest.kt b/common/kotlinx-coroutines-core-common/test/WithContextTest.kt
index 475c37e..d29e71c 100644
--- a/common/kotlinx-coroutines-core-common/test/WithContextTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/WithContextTest.kt
@@ -128,7 +128,7 @@
@Test
fun testRunCancellableDefault() = runTest(
- expected = { it is JobCancellationException }
+ expected = { it is CancellationException }
) {
val job = Job()
job.cancel() // cancel before it has a chance to run
@@ -150,7 +150,7 @@
yield() // but will cancel here
expectUnreached()
}
- } catch (e: JobCancellationException) {
+ } catch (e: CancellationException) {
// This block should be invoked *after* context body
finish(3)
}
@@ -158,7 +158,7 @@
@Test
fun testRunUndispatchedTryCancel() = runTest(
- expected = { it is JobCancellationException }
+ expected = { it is CancellationException }
) {
expect(1)
val job = Job()
@@ -218,7 +218,7 @@
} catch (e: Throwable) {
expect(7)
// make sure JCE is thrown
- assertTrue(e is JobCancellationException, "Caught $e")
+ assertTrue(e is CancellationException, "Caught $e")
}
}
diff --git a/common/kotlinx-coroutines-core-common/test/channels/ArrayBroadcastChannelTest.kt b/common/kotlinx-coroutines-core-common/test/channels/ArrayBroadcastChannelTest.kt
index 46db04e..eeed553 100644
--- a/common/kotlinx-coroutines-core-common/test/channels/ArrayBroadcastChannelTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/channels/ArrayBroadcastChannelTest.kt
@@ -11,7 +11,7 @@
@Test
fun testConcurrentModification() = runTest {
- val channel = ArrayBroadcastChannel<Int>(1)
+ val channel = BroadcastChannel<Int>(1)
val s1 = channel.openSubscription()
val s2 = channel.openSubscription()
@@ -35,7 +35,7 @@
@Test
fun testBasic() = runTest {
expect(1)
- val broadcast = ArrayBroadcastChannel<Int>(1)
+ val broadcast = BroadcastChannel<Int>(1)
assertFalse(broadcast.isClosedForSend)
val first = broadcast.openSubscription()
launch(start = CoroutineStart.UNDISPATCHED) {
@@ -81,7 +81,7 @@
@Test
fun testSendSuspend() = runTest {
expect(1)
- val broadcast = ArrayBroadcastChannel<Int>(1)
+ val broadcast = BroadcastChannel<Int>(1)
val first = broadcast.openSubscription()
launch {
expect(4)
@@ -100,7 +100,7 @@
@Test
fun testConcurrentSendCompletion() = runTest {
expect(1)
- val broadcast = ArrayBroadcastChannel<Int>(1)
+ val broadcast = BroadcastChannel<Int>(1)
val sub = broadcast.openSubscription()
// launch 3 concurrent senders (one goes buffer, two other suspend)
for (x in 1..3) {
@@ -126,7 +126,7 @@
@Test
fun testForgetUnsubscribed() = runTest {
expect(1)
- val broadcast = ArrayBroadcastChannel<Int>(1)
+ val broadcast = BroadcastChannel<Int>(1)
broadcast.send(1)
broadcast.send(2)
broadcast.send(3)
diff --git a/common/kotlinx-coroutines-core-common/test/channels/ArrayChannelTest.kt b/common/kotlinx-coroutines-core-common/test/channels/ArrayChannelTest.kt
index b2e4f05..dc6b047 100644
--- a/common/kotlinx-coroutines-core-common/test/channels/ArrayChannelTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/channels/ArrayChannelTest.kt
@@ -10,7 +10,7 @@
class ArrayChannelTest : TestBase() {
@Test
fun testSimple() = runTest {
- val q = ArrayChannel<Int>(1)
+ val q = Channel<Int>(1)
check(q.isEmpty && !q.isFull)
expect(1)
val sender = launch {
@@ -39,7 +39,7 @@
@Test
fun testClosedBufferedReceiveOrNull() = runTest {
- val q = ArrayChannel<Int>(1)
+ val q = Channel<Int>(1)
check(q.isEmpty && !q.isFull && !q.isClosedForSend && !q.isClosedForReceive)
expect(1)
launch {
@@ -64,7 +64,7 @@
@Test
fun testClosedExceptions() = runTest {
- val q = ArrayChannel<Int>(1)
+ val q = Channel<Int>(1)
expect(1)
launch {
expect(4)
@@ -87,7 +87,7 @@
@Test
fun testOfferAndPool() = runTest {
- val q = ArrayChannel<Int>(1)
+ val q = Channel<Int>(1)
assertTrue(q.offer(1))
expect(1)
launch {
@@ -117,7 +117,7 @@
@Test
fun testConsumeAll() = runTest {
- val q = ArrayChannel<Int>(5)
+ val q = Channel<Int>(5)
for (i in 1..10) {
if (i <= 5) {
expect(i)
@@ -140,7 +140,7 @@
@Test
fun testCancelWithCause() = runTest({ it is TestException }) {
- val channel = ArrayChannel<Int>(5)
+ val channel = Channel<Int>(5)
channel.cancel(TestException())
channel.receiveOrNull()
}
diff --git a/common/kotlinx-coroutines-core-common/test/channels/ChannelsTest.kt b/common/kotlinx-coroutines-core-common/test/channels/ChannelsTest.kt
index b956f6c..bf15962 100644
--- a/common/kotlinx-coroutines-core-common/test/channels/ChannelsTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/channels/ChannelsTest.kt
@@ -170,7 +170,7 @@
val channel = Channel<Nothing>()
channel.close()
- assertTrue(emptyList<Nothing>().asReceiveChannel().count() == 0)
+ assertEquals(emptyList<Nothing>().asReceiveChannel().count(), 0)
}
@Test
@@ -364,7 +364,8 @@
@Test
fun testFilterNotNull() = runTest {
repeat(3) { mod ->
- assertEquals(testList.map { it.takeIf { it % 2 == mod } }.filterNotNull(),
+ assertEquals(
+ testList.mapNotNull { it.takeIf { it % 2 == mod } },
testList.asReceiveChannel().map { it.takeIf { it % 2 == mod } }.filterNotNull().toList())
}
}
@@ -374,7 +375,7 @@
repeat(3) { mod ->
val c = mutableListOf<Int>()
testList.asReceiveChannel().map { it.takeIf { it % 2 == mod } }.filterNotNullTo(c)
- assertEquals(testList.map { it.takeIf { it % 2 == mod } }.filterNotNull(), c)
+ assertEquals(testList.mapNotNull { it.takeIf { it % 2 == mod } }, c)
}
}
@@ -384,7 +385,7 @@
val c = produce<Int> {
testList.asReceiveChannel().map { it.takeIf { it % 2 == mod } }.filterNotNullTo(channel)
}
- assertEquals(testList.map { it.takeIf { it % 2 == mod } }.filterNotNull(), c.toList())
+ assertEquals(testList.mapNotNull { it.takeIf { it % 2 == mod } }, c.toList())
}
}
diff --git a/common/kotlinx-coroutines-core-common/test/channels/ConflatedChannelTest.kt b/common/kotlinx-coroutines-core-common/test/channels/ConflatedChannelTest.kt
index ab78d4c..c6968db 100644
--- a/common/kotlinx-coroutines-core-common/test/channels/ConflatedChannelTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/channels/ConflatedChannelTest.kt
@@ -10,7 +10,7 @@
class ConflatedChannelTest : TestBase() {
@Test
fun testBasicConflationOfferPoll() {
- val q = ConflatedChannel<Int>()
+ val q = Channel<Int>(Channel.CONFLATED)
assertNull(q.poll())
assertTrue(q.offer(1))
assertTrue(q.offer(2))
@@ -29,7 +29,7 @@
@Test
fun testConflatedClose() = runTest {
- val q = ConflatedChannel<Int>()
+ val q = Channel<Int>(Channel.CONFLATED)
q.send(1)
q.close() // shall conflate sent item and become closed
assertNull(q.receiveOrNull())
@@ -37,7 +37,7 @@
@Test
fun testConflationSendReceive() = runTest {
- val q = ConflatedChannel<Int>()
+ val q = Channel<Int>(Channel.CONFLATED)
expect(1)
launch { // receiver coroutine
expect(4)
@@ -65,7 +65,7 @@
@Test
fun testConsumeAll() = runTest {
- val q = ConflatedChannel<Int>()
+ val q = Channel<Int>(Channel.CONFLATED)
expect(1)
for (i in 1..10) {
q.send(i) // stores as last
@@ -79,7 +79,7 @@
@Test
fun testCancelWithCause() = runTest({ it is TestException }) {
- val channel = ConflatedChannel<Int>()
+ val channel = Channel<Int>(Channel.CONFLATED)
channel.cancel(TestException())
channel.receiveOrNull()
}
diff --git a/common/kotlinx-coroutines-core-common/test/channels/LinkedListChannelTest.kt b/common/kotlinx-coroutines-core-common/test/channels/LinkedListChannelTest.kt
index 18a915a..4db28ab 100644
--- a/common/kotlinx-coroutines-core-common/test/channels/LinkedListChannelTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/channels/LinkedListChannelTest.kt
@@ -10,7 +10,7 @@
class LinkedListChannelTest : TestBase() {
@Test
fun testBasic() = runTest {
- val c = LinkedListChannel<Int>()
+ val c = Channel<Int>(Channel.UNLIMITED)
c.send(1)
check(c.offer(2))
c.send(3)
@@ -24,7 +24,7 @@
@Test
fun testConsumeAll() = runTest {
- val q = LinkedListChannel<Int>()
+ val q = Channel<Int>(Channel.UNLIMITED)
for (i in 1..10) {
q.send(i) // buffers
}
@@ -36,7 +36,7 @@
@Test
fun testCancelWithCause() = runTest({ it is TestException }) {
- val channel = LinkedListChannel<Int>()
+ val channel = Channel<Int>(Channel.UNLIMITED)
channel.cancel(TestException())
channel.receiveOrNull()
}
diff --git a/common/kotlinx-coroutines-core-common/test/channels/RendezvousChannelTest.kt b/common/kotlinx-coroutines-core-common/test/channels/RendezvousChannelTest.kt
index 95a4347..3f422c9 100644
--- a/common/kotlinx-coroutines-core-common/test/channels/RendezvousChannelTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/channels/RendezvousChannelTest.kt
@@ -10,7 +10,7 @@
class RendezvousChannelTest : TestBase() {
@Test
fun testSimple() = runTest {
- val q = RendezvousChannel<Int>()
+ val q = Channel<Int>(Channel.RENDEZVOUS)
check(q.isEmpty && q.isFull)
expect(1)
val sender = launch {
@@ -37,7 +37,7 @@
@Test
fun testClosedReceiveOrNull() = runTest {
- val q = RendezvousChannel<Int>()
+ val q = Channel<Int>(Channel.RENDEZVOUS)
check(q.isEmpty && q.isFull && !q.isClosedForSend && !q.isClosedForReceive)
expect(1)
launch {
@@ -59,7 +59,7 @@
@Test
fun testClosedExceptions() = runTest {
- val q = RendezvousChannel<Int>()
+ val q = Channel<Int>(Channel.RENDEZVOUS)
expect(1)
launch {
expect(4)
@@ -81,7 +81,7 @@
@Test
fun testOfferAndPool() = runTest {
- val q = RendezvousChannel<Int>()
+ val q = Channel<Int>(Channel.RENDEZVOUS)
assertFalse(q.offer(1))
expect(1)
launch {
@@ -109,7 +109,7 @@
@Test
fun testIteratorClosed() = runTest {
- val q = RendezvousChannel<Int>()
+ val q = Channel<Int>(Channel.RENDEZVOUS)
expect(1)
launch {
expect(3)
@@ -125,7 +125,7 @@
@Test
fun testIteratorOne() = runTest {
- val q = RendezvousChannel<Int>()
+ val q = Channel<Int>(Channel.RENDEZVOUS)
expect(1)
launch {
expect(3)
@@ -144,7 +144,7 @@
@Test
fun testIteratorOneWithYield() = runTest {
- val q = RendezvousChannel<Int>()
+ val q = Channel<Int>(Channel.RENDEZVOUS)
expect(1)
launch {
expect(3)
@@ -165,7 +165,7 @@
@Test
fun testIteratorTwo() = runTest {
- val q = RendezvousChannel<Int>()
+ val q = Channel<Int>(Channel.RENDEZVOUS)
expect(1)
launch {
expect(3)
@@ -189,7 +189,7 @@
@Test
fun testIteratorTwoWithYield() = runTest {
- val q = RendezvousChannel<Int>()
+ val q = Channel<Int>(Channel.RENDEZVOUS)
expect(1)
launch {
expect(3)
@@ -215,7 +215,7 @@
@Test
fun testSuspendSendOnClosedChannel() = runTest {
- val q = RendezvousChannel<Int>()
+ val q = Channel<Int>(Channel.RENDEZVOUS)
expect(1)
launch {
expect(4)
@@ -260,7 +260,7 @@
@Test
fun testConsumeAll() = runTest {
- val q = RendezvousChannel<Int>()
+ val q = Channel<Int>(Channel.RENDEZVOUS)
for (i in 1..10) {
launch(start = CoroutineStart.UNDISPATCHED) {
expect(i)
@@ -278,7 +278,7 @@
@Test
fun testCancelWithCause() = runTest({ it is TestException }) {
- val channel = RendezvousChannel<Int>()
+ val channel = Channel<Int>(Channel.RENDEZVOUS)
channel.cancel(TestException())
channel.receiveOrNull()
}
diff --git a/common/kotlinx-coroutines-core-common/test/channels/SendReceiveStressTest.kt b/common/kotlinx-coroutines-core-common/test/channels/SendReceiveStressTest.kt
index 9f08bb5..b48bf13 100644
--- a/common/kotlinx-coroutines-core-common/test/channels/SendReceiveStressTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/channels/SendReceiveStressTest.kt
@@ -5,7 +5,6 @@
package kotlinx.coroutines.experimental.channels
import kotlinx.coroutines.experimental.*
-import kotlin.coroutines.experimental.*
import kotlin.test.*
class SendReceiveStressTest : TestBase() {
@@ -14,17 +13,17 @@
@Test
fun testArrayChannel() = runTest {
- testStress(ArrayChannel(2))
+ testStress(Channel(2))
}
@Test
fun testLinkedListChannel() = runTest {
- testStress(LinkedListChannel())
+ testStress(Channel(Channel.UNLIMITED))
}
@Test
fun testRendezvousChannel() = runTest {
- testStress(RendezvousChannel())
+ testStress(Channel(Channel.RENDEZVOUS))
}
private suspend fun testStress(channel: Channel<Int>) = coroutineScope {
diff --git a/common/kotlinx-coroutines-core-common/test/channels/TestBroadcastChannelKind.kt b/common/kotlinx-coroutines-core-common/test/channels/TestBroadcastChannelKind.kt
index 41ca453..5c41f6f 100644
--- a/common/kotlinx-coroutines-core-common/test/channels/TestBroadcastChannelKind.kt
+++ b/common/kotlinx-coroutines-core-common/test/channels/TestBroadcastChannelKind.kt
@@ -6,11 +6,11 @@
enum class TestBroadcastChannelKind {
ARRAY_1 {
- override fun <T> create(): BroadcastChannel<T> = ArrayBroadcastChannel(1)
+ override fun <T> create(): BroadcastChannel<T> = BroadcastChannel(1)
override fun toString(): String = "ArrayBroadcastChannel(1)"
},
ARRAY_10 {
- override fun <T> create(): BroadcastChannel<T> = ArrayBroadcastChannel(10)
+ override fun <T> create(): BroadcastChannel<T> = BroadcastChannel(10)
override fun toString(): String = "ArrayBroadcastChannel(10)"
},
CONFLATED {
diff --git a/common/kotlinx-coroutines-core-common/test/channels/TestChannelKind.kt b/common/kotlinx-coroutines-core-common/test/channels/TestChannelKind.kt
index 7798b6b..e783120 100644
--- a/common/kotlinx-coroutines-core-common/test/channels/TestChannelKind.kt
+++ b/common/kotlinx-coroutines-core-common/test/channels/TestChannelKind.kt
@@ -8,32 +8,32 @@
enum class TestChannelKind {
RENDEZVOUS {
- override fun create(): Channel<Int> = RendezvousChannel()
+ override fun create(): Channel<Int> = Channel(Channel.RENDEZVOUS)
override fun toString(): String = "RendezvousChannel"
},
ARRAY_1 {
- override fun create(): Channel<Int> = ArrayChannel(1)
+ override fun create(): Channel<Int> = Channel(1)
override fun toString(): String = "ArrayChannel(1)"
},
ARRAY_10 {
- override fun create(): Channel<Int> = ArrayChannel(10)
+ override fun create(): Channel<Int> = Channel(10)
override fun toString(): String = "ArrayChannel(10)"
},
LINKED_LIST {
- override fun create(): Channel<Int> = LinkedListChannel()
+ override fun create(): Channel<Int> = Channel(Channel.UNLIMITED)
override fun toString(): String = "LinkedListChannel"
},
CONFLATED {
- override fun create(): Channel<Int> = ConflatedChannel()
+ override fun create(): Channel<Int> = Channel(Channel.CONFLATED)
override fun toString(): String = "ConflatedChannel"
override val isConflated: Boolean get() = true
},
ARRAY_BROADCAST_1 {
- override fun create(): Channel<Int> = ChannelViaBroadcast(ArrayBroadcastChannel<Int>(1))
+ override fun create(): Channel<Int> = ChannelViaBroadcast(BroadcastChannel(1))
override fun toString(): String = "ArrayBroadcastChannel(1)"
},
ARRAY_BROADCAST_10 {
- override fun create(): Channel<Int> = ChannelViaBroadcast(ArrayBroadcastChannel<Int>(10))
+ override fun create(): Channel<Int> = ChannelViaBroadcast(BroadcastChannel(10))
override fun toString(): String = "ArrayBroadcastChannel(10)"
},
CONFLATED_BROADCAST {
diff --git a/common/kotlinx-coroutines-core-common/test/selects/SelectArrayChannelTest.kt b/common/kotlinx-coroutines-core-common/test/selects/SelectArrayChannelTest.kt
index 0c8d85f..a20ce30 100644
--- a/common/kotlinx-coroutines-core-common/test/selects/SelectArrayChannelTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/selects/SelectArrayChannelTest.kt
@@ -14,7 +14,7 @@
@Test
fun testSelectSendSuccess() = runTest {
expect(1)
- val channel = ArrayChannel<String>(1)
+ val channel = Channel<String>(1)
launch {
expect(2)
assertEquals("OK", channel.receive())
@@ -33,7 +33,7 @@
@Test
fun testSelectSendSuccessWithDefault() = runTest {
expect(1)
- val channel = ArrayChannel<String>(1)
+ val channel = Channel<String>(1)
launch {
expect(2)
assertEquals("OK", channel.receive())
@@ -55,7 +55,7 @@
@Test
fun testSelectSendReceiveBuf() = runTest {
expect(1)
- val channel = ArrayChannel<String>(1)
+ val channel = Channel<String>(1)
select<Unit> {
channel.onSend("OK") {
expect(2)
@@ -74,7 +74,7 @@
@Test
fun testSelectSendWait() = runTest {
expect(1)
- val channel = ArrayChannel<String>(1)
+ val channel = Channel<String>(1)
launch {
expect(4)
assertEquals("BUF", channel.receive())
@@ -96,7 +96,7 @@
@Test
fun testSelectReceiveSuccess() = runTest {
expect(1)
- val channel = ArrayChannel<String>(1)
+ val channel = Channel<String>(1)
channel.send("OK")
expect(2)
select<Unit> {
@@ -111,7 +111,7 @@
@Test
fun testSelectReceiveSuccessWithDefault() = runTest {
expect(1)
- val channel = ArrayChannel<String>(1)
+ val channel = Channel<String>(1)
channel.send("OK")
expect(2)
select<Unit> {
@@ -129,7 +129,7 @@
@Test
fun testSelectReceiveWaitWithDefault() = runTest {
expect(1)
- val channel = ArrayChannel<String>(1)
+ val channel = Channel<String>(1)
select<Unit> {
channel.onReceive {
expectUnreached()
@@ -159,7 +159,7 @@
@Test
fun testSelectReceiveWait() = runTest {
expect(1)
- val channel = ArrayChannel<String>(1)
+ val channel = Channel<String>(1)
launch {
expect(3)
channel.send("OK")
@@ -178,7 +178,7 @@
@Test
fun testSelectReceiveClosed() = runTest({it is ClosedReceiveChannelException}) {
expect(1)
- val channel = ArrayChannel<String>(1)
+ val channel = Channel<String>(1)
channel.close()
finish(2)
select<Unit> {
@@ -192,7 +192,7 @@
@Test
fun testSelectReceiveWaitClosed() = runTest({it is ClosedReceiveChannelException}) {
expect(1)
- val channel = ArrayChannel<String>(1)
+ val channel = Channel<String>(1)
launch {
expect(3)
channel.close()
@@ -209,7 +209,7 @@
@Test
fun testSelectSendResourceCleanup() = runTest {
- val channel = ArrayChannel<Int>(1)
+ val channel = Channel<Int>(1)
val n = 1000
expect(1)
channel.send(-1) // fill the buffer, so all subsequent sends cannot proceed
@@ -224,7 +224,7 @@
@Test
fun testSelectReceiveResourceCleanup() = runTest {
- val channel = ArrayChannel<Int>(1)
+ val channel = Channel<Int>(1)
val n = 1000
expect(1)
repeat(n) { i ->
@@ -238,7 +238,7 @@
@Test
fun testSelectReceiveDispatchNonSuspending() = runTest {
- val channel = ArrayChannel<Int>(1)
+ val channel = Channel<Int>(1)
expect(1)
channel.send(42)
expect(2)
@@ -260,7 +260,7 @@
@Test
fun testSelectReceiveDispatchNonSuspending2() = runTest {
- val channel = ArrayChannel<Int>(1)
+ val channel = Channel<Int>(1)
expect(1)
channel.send(42)
expect(2)
diff --git a/common/kotlinx-coroutines-core-common/test/selects/SelectDeferredTest.kt b/common/kotlinx-coroutines-core-common/test/selects/SelectDeferredTest.kt
index d0f4056..c2e202c 100644
--- a/common/kotlinx-coroutines-core-common/test/selects/SelectDeferredTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/selects/SelectDeferredTest.kt
@@ -119,7 +119,7 @@
@Test
fun testSelectCancel() = runTest(
- expected = { it is JobCancellationException }
+ expected = { it is CancellationException }
) {
expect(1)
val d = CompletableDeferred<String>()
diff --git a/common/kotlinx-coroutines-core-common/test/selects/SelectRendezvousChannelTest.kt b/common/kotlinx-coroutines-core-common/test/selects/SelectRendezvousChannelTest.kt
index 7f3040e..5aa5a3f 100644
--- a/common/kotlinx-coroutines-core-common/test/selects/SelectRendezvousChannelTest.kt
+++ b/common/kotlinx-coroutines-core-common/test/selects/SelectRendezvousChannelTest.kt
@@ -15,7 +15,7 @@
@Test
fun testSelectSendSuccess() = runTest {
expect(1)
- val channel = RendezvousChannel<String>()
+ val channel = Channel<String>(Channel.RENDEZVOUS)
launch {
expect(2)
assertEquals("OK", channel.receive())
@@ -34,7 +34,7 @@
@Test
fun testSelectSendSuccessWithDefault() = runTest {
expect(1)
- val channel = RendezvousChannel<String>()
+ val channel = Channel<String>(Channel.RENDEZVOUS)
launch {
expect(2)
assertEquals("OK", channel.receive())
@@ -56,7 +56,7 @@
@Test
fun testSelectSendWaitWithDefault() = runTest {
expect(1)
- val channel = RendezvousChannel<String>()
+ val channel = Channel<String>(Channel.RENDEZVOUS)
select<Unit> {
channel.onSend("OK") {
expectUnreached()
@@ -82,7 +82,7 @@
@Test
fun testSelectSendWait() = runTest {
expect(1)
- val channel = RendezvousChannel<String>()
+ val channel = Channel<String>(Channel.RENDEZVOUS)
launch {
expect(3)
assertEquals("OK", channel.receive())
@@ -100,7 +100,7 @@
@Test
fun testSelectReceiveSuccess() = runTest {
expect(1)
- val channel = RendezvousChannel<String>()
+ val channel = Channel<String>(Channel.RENDEZVOUS)
launch {
expect(2)
channel.send("OK")
@@ -120,7 +120,7 @@
@Test
fun testSelectReceiveSuccessWithDefault() = runTest {
expect(1)
- val channel = RendezvousChannel<String>()
+ val channel = Channel<String>(Channel.RENDEZVOUS)
launch {
expect(2)
channel.send("OK")
@@ -143,7 +143,7 @@
@Test
fun testSelectReceiveWaitWithDefault() = runTest {
expect(1)
- val channel = RendezvousChannel<String>()
+ val channel = Channel<String>(Channel.RENDEZVOUS)
select<Unit> {
channel.onReceive {
expectUnreached()
@@ -169,7 +169,7 @@
@Test
fun testSelectReceiveWait() = runTest {
expect(1)
- val channel = RendezvousChannel<String>()
+ val channel = Channel<String>(Channel.RENDEZVOUS)
launch {
expect(3)
channel.send("OK")
@@ -188,7 +188,7 @@
@Test
fun testSelectReceiveClosed() = runTest(expected = { it is ClosedReceiveChannelException }) {
expect(1)
- val channel = RendezvousChannel<String>()
+ val channel = Channel<String>(Channel.RENDEZVOUS)
channel.close()
finish(2)
select<Unit> {
@@ -202,7 +202,7 @@
@Test
fun testSelectReceiveWaitClosed() = runTest(expected = {it is ClosedReceiveChannelException}) {
expect(1)
- val channel = RendezvousChannel<String>()
+ val channel = Channel<String>(Channel.RENDEZVOUS)
launch {
expect(3)
channel.close()
@@ -219,7 +219,7 @@
@Test
fun testSelectSendResourceCleanup() = runTest {
- val channel = RendezvousChannel<Int>()
+ val channel = Channel<Int>(Channel.RENDEZVOUS)
val n = 1_000
expect(1)
repeat(n) { i ->
@@ -233,7 +233,7 @@
@Test
fun testSelectReceiveResourceCleanup() = runTest {
- val channel = RendezvousChannel<Int>()
+ val channel = Channel<Int>(Channel.RENDEZVOUS)
val n = 1_000
expect(1)
repeat(n) { i ->
@@ -247,8 +247,8 @@
@Test
fun testSelectAtomicFailure() = runTest {
- val c1 = RendezvousChannel<Int>()
- val c2 = RendezvousChannel<Int>()
+ val c1 = Channel<Int>(Channel.RENDEZVOUS)
+ val c2 = Channel<Int>(Channel.RENDEZVOUS)
expect(1)
launch {
expect(3)
@@ -278,7 +278,7 @@
@Test
fun testSelectWaitDispatch() = runTest {
- val c = RendezvousChannel<Int>()
+ val c = Channel<Int>(Channel.RENDEZVOUS)
expect(1)
launch {
expect(3)
diff --git a/core/kotlinx-coroutines-core/src/Exceptions.kt b/core/kotlinx-coroutines-core/src/Exceptions.kt
index 43889c0..5869dbb 100644
--- a/core/kotlinx-coroutines-core/src/Exceptions.kt
+++ b/core/kotlinx-coroutines-core/src/Exceptions.kt
@@ -56,6 +56,8 @@
}
override fun toString(): String = "${super.toString()}; job=$job"
+
+ @Suppress("DEPRECATION")
override fun equals(other: Any?): Boolean =
other === this ||
other is JobCancellationException && other.message == message && other.job == job && other.cause == cause
diff --git a/core/kotlinx-coroutines-core/test/AtomicCancellationTest.kt b/core/kotlinx-coroutines-core/test/AtomicCancellationTest.kt
index 3de6015..c2292f7 100644
--- a/core/kotlinx-coroutines-core/test/AtomicCancellationTest.kt
+++ b/core/kotlinx-coroutines-core/test/AtomicCancellationTest.kt
@@ -9,6 +9,7 @@
import kotlin.test.*
class AtomicCancellationTest : TestBase() {
+
@Test
fun testSendAtomicCancel() = runBlocking {
expect(1)
diff --git a/core/kotlinx-coroutines-core/test/AwaitStressTest.kt b/core/kotlinx-coroutines-core/test/AwaitStressTest.kt
index 86569fb..b2683fe 100644
--- a/core/kotlinx-coroutines-core/test/AwaitStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/AwaitStressTest.kt
@@ -97,7 +97,7 @@
barrier.await()
try {
awaitAll(d1, d2)
- } catch (e: JobCancellationException) {
+ } catch (e: CancellationException) {
cancelledOnce = true
}
}
diff --git a/core/kotlinx-coroutines-core/test/CommonPoolTest.kt b/core/kotlinx-coroutines-core/test/CommonPoolTest.kt
index a9985f5..99d5bab 100644
--- a/core/kotlinx-coroutines-core/test/CommonPoolTest.kt
+++ b/core/kotlinx-coroutines-core/test/CommonPoolTest.kt
@@ -9,6 +9,7 @@
import java.lang.reflect.*
import java.util.concurrent.*
+@Suppress("DEPRECATION")
class CommonPoolTest {
private inline fun <T> Try(block: () -> T) = try { block() } catch (e: Throwable) { null }
@@ -40,7 +41,7 @@
println("CommonPool.isGoodCommonPool test passed")
}
- fun createFJP(
+ private fun createFJP(
parallelism: Int,
fjpCtor: Constructor<out Any>,
dwtfCtor: Constructor<out Any>
diff --git a/core/kotlinx-coroutines-core/test/DefaultExecutorStressTest.kt b/core/kotlinx-coroutines-core/test/DefaultExecutorStressTest.kt
index ba2b804..05efec2 100644
--- a/core/kotlinx-coroutines-core/test/DefaultExecutorStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/DefaultExecutorStressTest.kt
@@ -5,7 +5,6 @@
package kotlinx.coroutines.experimental
import org.junit.*
-import java.util.concurrent.*
class DefaultExecutorStressTest : TestBase() {
@Test
@@ -19,7 +18,7 @@
val deferred = async {
expect(++expected)
val largeArray = IntArray(10_000) { it }
- delay(Long.MAX_VALUE, TimeUnit.NANOSECONDS)
+ delay(Long.MAX_VALUE)
println(largeArray) // consume to avoid DCE, actually unreachable
}
@@ -28,7 +27,7 @@
deferred.cancel()
try {
deferred.await()
- } catch (e: JobCancellationException) {
+ } catch (e: CancellationException) {
expect(++expected)
}
}
diff --git a/core/kotlinx-coroutines-core/test/DelayJvmTest.kt b/core/kotlinx-coroutines-core/test/DelayJvmTest.kt
index f171281..a8d2515 100644
--- a/core/kotlinx-coroutines-core/test/DelayJvmTest.kt
+++ b/core/kotlinx-coroutines-core/test/DelayJvmTest.kt
@@ -61,7 +61,7 @@
Wrapper(pool, continuation)
}
- class Wrapper<T>(val pool: Executor, val cont: Continuation<T>) : Continuation<T> {
+ class Wrapper<T>(val pool: Executor, private val cont: Continuation<T>) : Continuation<T> {
override val context: CoroutineContext
get() = cont.context
diff --git a/core/kotlinx-coroutines-core/test/ExecutorsTest.kt b/core/kotlinx-coroutines-core/test/ExecutorsTest.kt
index 4d938f2..6d98bd6 100644
--- a/core/kotlinx-coroutines-core/test/ExecutorsTest.kt
+++ b/core/kotlinx-coroutines-core/test/ExecutorsTest.kt
@@ -8,7 +8,7 @@
import java.util.concurrent.Executors
class ExecutorsTest : TestBase() {
- fun checkThreadName(prefix: String) {
+ private fun checkThreadName(prefix: String) {
val name = Thread.currentThread().name
check(name.startsWith(prefix)) { "Expected thread name to start with '$prefix', found: '$name'" }
}
diff --git a/core/kotlinx-coroutines-core/test/RunBlockingTest.kt b/core/kotlinx-coroutines-core/test/RunBlockingTest.kt
index 5cc4d69..02b1002 100644
--- a/core/kotlinx-coroutines-core/test/RunBlockingTest.kt
+++ b/core/kotlinx-coroutines-core/test/RunBlockingTest.kt
@@ -99,7 +99,7 @@
}
}
expectUnreached()
- } catch (e: JobCancellationException) {
+ } catch (e: CancellationException) {
finish(4)
}
}
diff --git a/core/kotlinx-coroutines-core/test/TestBase.kt b/core/kotlinx-coroutines-core/test/TestBase.kt
index 8ce6671..325e76f 100644
--- a/core/kotlinx-coroutines-core/test/TestBase.kt
+++ b/core/kotlinx-coroutines-core/test/TestBase.kt
@@ -30,6 +30,7 @@
* }
* ```
*/
+@Suppress("DEPRECATION")
public actual open class TestBase actual constructor() {
/**
* Is `true` when nightly stress test is done.
@@ -68,7 +69,7 @@
* Throws [IllegalStateException] when `value` is false like `check` in stdlib, but also ensures that the
* test will not complete successfully even if this exception is consumed somewhere in the test.
*/
- public inline fun check(value: Boolean, lazyMessage: () -> Any): Unit {
+ public inline fun check(value: Boolean, lazyMessage: () -> Any) {
if (!value) error(lazyMessage())
}
diff --git a/core/kotlinx-coroutines-core/test/TestSecurityManager.kt b/core/kotlinx-coroutines-core/test/TestSecurityManager.kt
index 03c9386..f5280f0 100644
--- a/core/kotlinx-coroutines-core/test/TestSecurityManager.kt
+++ b/core/kotlinx-coroutines-core/test/TestSecurityManager.kt
@@ -6,6 +6,7 @@
import java.security.Permission
+@Suppress("unused")
class TestSecurityManager : SecurityManager() {
override fun checkPropertyAccess(key: String?) {
if (key?.startsWith("kotlinx.") == true)
diff --git a/core/kotlinx-coroutines-core/test/VirtualTimeSource.kt b/core/kotlinx-coroutines-core/test/VirtualTimeSource.kt
index 8b67535..370c871 100644
--- a/core/kotlinx-coroutines-core/test/VirtualTimeSource.kt
+++ b/core/kotlinx-coroutines-core/test/VirtualTimeSource.kt
@@ -24,7 +24,7 @@
}
}
-private val NOT_PARKED = -1L
+private const val NOT_PARKED = -1L
private class ThreadStatus {
@Volatile @JvmField
@@ -34,9 +34,9 @@
override fun toString(): String = "parkedTill = ${TimeUnit.NANOSECONDS.toMillis(parkedTill)} ms, permit = $permit"
}
-private val MAX_WAIT_NANOS = 10_000_000_000L // 10s
-private val REAL_TIME_STEP_NANOS = 200_000_000L // 200 ms
-private val REAL_PARK_NANOS = 10_000_000L // 10 ms -- park for a little to better track real-time
+private const val MAX_WAIT_NANOS = 10_000_000_000L // 10s
+private const val REAL_TIME_STEP_NANOS = 200_000_000L // 200 ms
+private const val REAL_PARK_NANOS = 10_000_000L // 10 ms -- park for a little to better track real-time
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
internal class VirtualTimeSource(
diff --git a/core/kotlinx-coroutines-core/test/channels/ActorTest.kt b/core/kotlinx-coroutines-core/test/channels/ActorTest.kt
index 70aa73f..a2eff95 100644
--- a/core/kotlinx-coroutines-core/test/channels/ActorTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/ActorTest.kt
@@ -127,7 +127,7 @@
try {
job.await()
expectUnreached()
- } catch (e: JobCancellationException) {
+ } catch (e: CancellationException) {
assertTrue(e.message?.contains("Job was cancelled normally") ?: false)
}
diff --git a/core/kotlinx-coroutines-core/test/channels/ArrayChannelStressTest.kt b/core/kotlinx-coroutines-core/test/channels/ArrayChannelStressTest.kt
index 450a42f..ad5014b 100644
--- a/core/kotlinx-coroutines-core/test/channels/ArrayChannelStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/ArrayChannelStressTest.kt
@@ -21,7 +21,7 @@
@Test
fun testStress() = runTest {
val n = 100_000 * stressTestMultiplier
- val q = ArrayChannel<Int>(capacity)
+ val q = Channel<Int>(capacity)
val sender = launch(kotlin.coroutines.experimental.coroutineContext) {
for (i in 1..n) {
q.send(i)
diff --git a/core/kotlinx-coroutines-core/test/channels/BroadcastChannelMultiReceiveStressTest.kt b/core/kotlinx-coroutines-core/test/channels/BroadcastChannelMultiReceiveStressTest.kt
index 8b9c346..83937c5 100644
--- a/core/kotlinx-coroutines-core/test/channels/BroadcastChannelMultiReceiveStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/BroadcastChannelMultiReceiveStressTest.kt
@@ -16,7 +16,7 @@
*/
@RunWith(Parameterized::class)
class BroadcastChannelMultiReceiveStressTest(
- val kind: TestBroadcastChannelKind
+ private val kind: TestBroadcastChannelKind
) : TestBase() {
companion object {
@Parameterized.Parameters(name = "{0}")
diff --git a/core/kotlinx-coroutines-core/test/channels/BroadcastChannelSubStressTest.kt b/core/kotlinx-coroutines-core/test/channels/BroadcastChannelSubStressTest.kt
index dbfd04e..a542aef 100644
--- a/core/kotlinx-coroutines-core/test/channels/BroadcastChannelSubStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/BroadcastChannelSubStressTest.kt
@@ -5,7 +5,6 @@
package kotlinx.coroutines.experimental.channels
import kotlinx.coroutines.experimental.*
-import kotlinx.coroutines.experimental.timeunit.*
import org.junit.*
import org.junit.runner.*
import org.junit.runners.*
@@ -18,7 +17,7 @@
*/
@RunWith(Parameterized::class)
class BroadcastChannelSubStressTest(
- val kind: TestBroadcastChannelKind
+ private val kind: TestBroadcastChannelKind
) : TestBase() {
companion object {
@Parameterized.Parameters(name = "{0}")
@@ -63,7 +62,7 @@
check(curSent > prevSent) { "Send stalled at $curSent events" }
prevSent = curSent
}
- withTimeout(5, TimeUnit.SECONDS) {
+ withTimeout(5000) {
sender.cancelAndJoin()
receiver.cancelAndJoin()
}
diff --git a/core/kotlinx-coroutines-core/test/channels/ChannelAtomicCancelStressTest.kt b/core/kotlinx-coroutines-core/test/channels/ChannelAtomicCancelStressTest.kt
index 1e61bf4..72f9bf4 100644
--- a/core/kotlinx-coroutines-core/test/channels/ChannelAtomicCancelStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/ChannelAtomicCancelStressTest.kt
@@ -17,27 +17,27 @@
* Tests cancel atomicity for channel send & receive operations, including their select versions.
*/
@RunWith(Parameterized::class)
-class ChannelAtomicCancelStressTest(val kind: TestChannelKind) : TestBase() {
+class ChannelAtomicCancelStressTest(private val kind: TestChannelKind) : TestBase() {
companion object {
@Parameterized.Parameters(name = "{0}")
@JvmStatic
fun params(): Collection<Array<Any>> = TestChannelKind.values().map { arrayOf<Any>(it) }
}
- val TEST_DURATION = 3000L * stressTestMultiplier
+ private val TEST_DURATION = 3000L * stressTestMultiplier
val channel = kind.create()
- val senderDone = ArrayChannel<Boolean>(1)
- val receiverDone = ArrayChannel<Boolean>(1)
+ private val senderDone = Channel<Boolean>(1)
+ private val receiverDone = Channel<Boolean>(1)
- var lastSent = 0
- var lastReceived = 0
+ private var lastSent = 0
+ private var lastReceived = 0
- var stoppedSender = 0
- var stoppedReceiver = 0
+ private var stoppedSender = 0
+ private var stoppedReceiver = 0
- var missedCnt = 0
- var dupCnt = 0
+ private var missedCnt = 0
+ private var dupCnt = 0
val failed = AtomicReference<Throwable>()
@@ -46,7 +46,7 @@
fun fail(e: Throwable) = failed.compareAndSet(null, e)
- inline fun cancellable(done: ArrayChannel<Boolean>, block: () -> Unit) {
+ private inline fun cancellable(done: Channel<Boolean>, block: () -> Unit) {
try {
block()
} catch (e: Throwable) {
@@ -59,7 +59,7 @@
}
@Test
- fun testAtomicCancelStress() = runBlocking<Unit> {
+ fun testAtomicCancelStress() = runBlocking {
println("--- ChannelAtomicCancelStressTest $kind")
val deadline = System.currentTimeMillis() + TEST_DURATION
launchSender()
@@ -94,7 +94,7 @@
}
}
- fun launchSender() {
+ private fun launchSender() {
sender = GlobalScope.launch(start = CoroutineStart.ATOMIC) {
val rnd = Random()
cancellable(senderDone) {
@@ -113,13 +113,13 @@
}
}
- suspend fun stopSender() {
+ private suspend fun stopSender() {
stoppedSender++
sender.cancel()
senderDone.receive()
}
- fun launchReceiver() {
+ private fun launchReceiver() {
receiver = GlobalScope.launch(start = CoroutineStart.ATOMIC) {
val rnd = Random()
cancellable(receiverDone) {
@@ -140,7 +140,7 @@
}
}
- suspend fun stopReceiver() {
+ private suspend fun stopReceiver() {
stoppedReceiver++
receiver.cancel()
receiverDone.receive()
diff --git a/core/kotlinx-coroutines-core/test/channels/ChannelIsClosedLinearizabilityTest.kt b/core/kotlinx-coroutines-core/test/channels/ChannelIsClosedLinearizabilityTest.kt
index f4cd7df..204dafb 100644
--- a/core/kotlinx-coroutines-core/test/channels/ChannelIsClosedLinearizabilityTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/ChannelIsClosedLinearizabilityTest.kt
@@ -2,6 +2,8 @@
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
+@file:Suppress("unused")
+
package kotlinx.coroutines.experimental.channels
import com.devexperts.dxlab.lincheck.*
diff --git a/core/kotlinx-coroutines-core/test/channels/ChannelLinearizabilityTest.kt b/core/kotlinx-coroutines-core/test/channels/ChannelLinearizabilityTest.kt
index a80defc..40eee20 100644
--- a/core/kotlinx-coroutines-core/test/channels/ChannelLinearizabilityTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/ChannelLinearizabilityTest.kt
@@ -2,6 +2,8 @@
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
+@file:Suppress("unused")
+
package kotlinx.coroutines.experimental.channels
import com.devexperts.dxlab.lincheck.*
diff --git a/core/kotlinx-coroutines-core/test/channels/ChannelSendReceiveStressTest.kt b/core/kotlinx-coroutines-core/test/channels/ChannelSendReceiveStressTest.kt
index 57e69ec..c00e60f 100644
--- a/core/kotlinx-coroutines-core/test/channels/ChannelSendReceiveStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/ChannelSendReceiveStressTest.kt
@@ -14,9 +14,9 @@
@RunWith(Parameterized::class)
class ChannelSendReceiveStressTest(
- val kind: TestChannelKind,
- val nSenders: Int,
- val nReceivers: Int
+ private val kind: TestChannelKind,
+ private val nSenders: Int,
+ private val nReceivers: Int
) : TestBase() {
companion object {
@Parameterized.Parameters(name = "{0}, nSenders={1}, nReceivers={2}")
@@ -24,24 +24,24 @@
fun params(): Collection<Array<Any>> =
listOf(1, 2, 10).flatMap { nSenders ->
listOf(1, 10).flatMap { nReceivers ->
- TestChannelKind.values().map { arrayOf<Any>(it, nSenders, nReceivers) }
+ TestChannelKind.values().map { arrayOf(it, nSenders, nReceivers) }
}
}
}
- val timeLimit = 30_000L * stressTestMultiplier // 30 sec
- val nEvents = 200_000 * stressTestMultiplier
+ private val timeLimit = 30_000L * stressTestMultiplier // 30 sec
+ private val nEvents = 200_000 * stressTestMultiplier
- val maxBuffer = 10_000 // artificial limit for LinkedListChannel
+ private val maxBuffer = 10_000 // artificial limit for LinkedListChannel
val channel = kind.create()
- val sendersCompleted = AtomicInteger()
- val receiversCompleted = AtomicInteger()
- val dupes = AtomicInteger()
- val sentTotal = AtomicInteger()
+ private val sendersCompleted = AtomicInteger()
+ private val receiversCompleted = AtomicInteger()
+ private val dupes = AtomicInteger()
+ private val sentTotal = AtomicInteger()
val received = AtomicIntegerArray(nEvents)
- val receivedTotal = AtomicInteger()
- val receivedBy = IntArray(nReceivers)
+ private val receivedTotal = AtomicInteger()
+ private val receivedBy = IntArray(nReceivers)
@Test
fun testSendReceiveStress() = runBlocking {
diff --git a/core/kotlinx-coroutines-core/test/channels/ChannelsConsumeTest.kt b/core/kotlinx-coroutines-core/test/channels/ChannelsConsumeTest.kt
index aa58e7a..9875b78 100644
--- a/core/kotlinx-coroutines-core/test/channels/ChannelsConsumeTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/ChannelsConsumeTest.kt
@@ -630,7 +630,7 @@
@Test
fun testWithIndex() {
- checkTransform(sourceList.withIndex().toList()) {
+ checkTransform(sourceList.asSequence().withIndex().toList()) {
withIndex()
}
}
diff --git a/core/kotlinx-coroutines-core/test/channels/ConflatedBroadcastChannelNotifyStressTest.kt b/core/kotlinx-coroutines-core/test/channels/ConflatedBroadcastChannelNotifyStressTest.kt
index 3e0729a..2ec11eb 100644
--- a/core/kotlinx-coroutines-core/test/channels/ConflatedBroadcastChannelNotifyStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/ConflatedBroadcastChannelNotifyStressTest.kt
@@ -11,20 +11,20 @@
import java.util.concurrent.atomic.*
class ConflatedBroadcastChannelNotifyStressTest : TestBase() {
- val nSenders = 2
- val nReceivers = 3
- val nEvents = 500_000 * stressTestMultiplier
- val timeLimit = 30_000L * stressTestMultiplier // 30 sec
+ private val nSenders = 2
+ private val nReceivers = 3
+ private val nEvents = 500_000 * stressTestMultiplier
+ private val timeLimit = 30_000L * stressTestMultiplier // 30 sec
- val broadcast = ConflatedBroadcastChannel<Int>()
+ private val broadcast = ConflatedBroadcastChannel<Int>()
- val sendersCompleted = AtomicInteger()
- val receiversCompleted = AtomicInteger()
- val sentTotal = AtomicInteger()
- val receivedTotal = AtomicInteger()
+ private val sendersCompleted = AtomicInteger()
+ private val receiversCompleted = AtomicInteger()
+ private val sentTotal = AtomicInteger()
+ private val receivedTotal = AtomicInteger()
@Test
- fun testStressNotify()= runBlocking<Unit> {
+ fun testStressNotify()= runBlocking {
println("--- ConflatedBroadcastChannelNotifyStressTest")
val senders = List(nSenders) { senderId ->
launch(Dispatchers.Default + CoroutineName("Sender$senderId")) {
@@ -81,7 +81,7 @@
assertThat(sentTotal.get(), IsEqual(nEvents))
}
- suspend fun waitForEvent(): Int =
+ private suspend fun waitForEvent(): Int =
with(broadcast.openSubscription()) {
val value = receive()
cancel()
diff --git a/core/kotlinx-coroutines-core/test/channels/ConflatedChannelCloseStressTest.kt b/core/kotlinx-coroutines-core/test/channels/ConflatedChannelCloseStressTest.kt
index 7d7b33c..a06224a 100644
--- a/core/kotlinx-coroutines-core/test/channels/ConflatedChannelCloseStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/ConflatedChannelCloseStressTest.kt
@@ -5,20 +5,17 @@
package kotlinx.coroutines.experimental.channels
import kotlinx.coroutines.experimental.*
-import org.junit.After
-import org.junit.Test
-import java.util.concurrent.atomic.AtomicInteger
-import java.util.concurrent.atomic.AtomicReference
-import kotlin.coroutines.experimental.*
+import org.junit.*
+import java.util.concurrent.atomic.*
class ConflatedChannelCloseStressTest : TestBase() {
- val nSenders = 2
- val testSeconds = 3 * stressTestMultiplier
+ private val nSenders = 2
+ private val testSeconds = 3 * stressTestMultiplier
- val curChannel = AtomicReference<ConflatedChannel<Int>>(ConflatedChannel())
- val sent = AtomicInteger()
- val closed = AtomicInteger()
+ private val curChannel = AtomicReference<Channel<Int>>(Channel(Channel.CONFLATED))
+ private val sent = AtomicInteger()
+ private val closed = AtomicInteger()
val received = AtomicInteger()
val pool = newFixedThreadPoolContext(nSenders + 2, "TestStressClose")
@@ -29,7 +26,7 @@
}
@Test
- fun testStressClose() = runBlocking<Unit> {
+ fun testStressClose() = runBlocking {
println("--- ConflatedChannelCloseStressTest with nSenders=$nSenders")
val senderJobs = List(nSenders) { Job() }
val senders = List(nSenders) { senderId ->
@@ -100,7 +97,7 @@
private fun flipChannel() {
val oldChannel = curChannel.get()
- val newChannel = ConflatedChannel<Int>()
+ val newChannel = Channel<Int>(Channel.CONFLATED)
curChannel.set(newChannel)
check(oldChannel.close())
}
diff --git a/core/kotlinx-coroutines-core/test/channels/InvokeOnCloseStressTest.kt b/core/kotlinx-coroutines-core/test/channels/InvokeOnCloseStressTest.kt
index 7c52df7..7203f1f 100644
--- a/core/kotlinx-coroutines-core/test/channels/InvokeOnCloseStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/InvokeOnCloseStressTest.kt
@@ -5,7 +5,6 @@
package kotlinx.coroutines.experimental.channels
import kotlinx.coroutines.experimental.*
-import kotlinx.coroutines.experimental.channels.*
import org.junit.*
import org.junit.Test
import java.util.concurrent.*
diff --git a/core/kotlinx-coroutines-core/test/channels/RandevouzChannelStressTest.kt b/core/kotlinx-coroutines-core/test/channels/RandevouzChannelStressTest.kt
index 1fc2c8f..2558c29 100644
--- a/core/kotlinx-coroutines-core/test/channels/RandevouzChannelStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/RandevouzChannelStressTest.kt
@@ -12,7 +12,7 @@
@Test
fun testStress() = runTest {
val n = 100_000 * stressTestMultiplier
- val q = RendezvousChannel<Int>()
+ val q = Channel<Int>(Channel.RENDEZVOUS)
val sender = launch {
for (i in 1..n) q.send(i)
expect(2)
diff --git a/core/kotlinx-coroutines-core/test/channels/SendReceiveJvmStressTest.kt b/core/kotlinx-coroutines-core/test/channels/SendReceiveJvmStressTest.kt
index 8c5b080..c1ed2b3 100644
--- a/core/kotlinx-coroutines-core/test/channels/SendReceiveJvmStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/SendReceiveJvmStressTest.kt
@@ -16,11 +16,11 @@
@Parameterized.Parameters(name = "{0}")
@JvmStatic
fun params(): Collection<Array<Any>> = listOf(
- ArrayChannel<Int>(1),
- ArrayChannel<Int>(10),
- ArrayChannel<Int>(1_000_000),
- LinkedListChannel<Int>(),
- RendezvousChannel<Int>()
+ Channel<Int>(1),
+ Channel (10),
+ Channel(1_000_000),
+ Channel(Channel.UNLIMITED),
+ Channel(Channel.RENDEZVOUS)
).map { arrayOf<Any>(it) }
}
diff --git a/core/kotlinx-coroutines-core/test/channels/SimpleSendReceiveJvmTest.kt b/core/kotlinx-coroutines-core/test/channels/SimpleSendReceiveJvmTest.kt
index 1198952..da5f7cd 100644
--- a/core/kotlinx-coroutines-core/test/channels/SimpleSendReceiveJvmTest.kt
+++ b/core/kotlinx-coroutines-core/test/channels/SimpleSendReceiveJvmTest.kt
@@ -10,11 +10,10 @@
import org.junit.Assert.*
import org.junit.runner.*
import org.junit.runners.*
-import kotlin.coroutines.experimental.*
@RunWith(Parameterized::class)
class SimpleSendReceiveJvmTest(
- val kind: TestChannelKind,
+ private val kind: TestChannelKind,
val n: Int,
val concurrent: Boolean
) {
diff --git a/core/kotlinx-coroutines-core/test/exceptions/JobExceptionHandlingTest.kt b/core/kotlinx-coroutines-core/test/exceptions/JobExceptionHandlingTest.kt
index 8243a05..4d50096 100644
--- a/core/kotlinx-coroutines-core/test/exceptions/JobExceptionHandlingTest.kt
+++ b/core/kotlinx-coroutines-core/test/exceptions/JobExceptionHandlingTest.kt
@@ -106,7 +106,7 @@
expect(3) // <- child's child is launched successfully
try {
yield()
- } catch (e: JobCancellationException) {
+ } catch (e: CancellationException) {
throw ArithmeticException()
}
}
@@ -169,7 +169,7 @@
expect(3) // <- child's child is launched successfully
try {
yield()
- } catch (e: JobCancellationException) {
+ } catch (e: CancellationException) {
throw ArithmeticException()
}
}
diff --git a/core/kotlinx-coroutines-core/test/exceptions/SuppresionTests.kt b/core/kotlinx-coroutines-core/test/exceptions/SuppresionTests.kt
index 51498e2..abbd56c 100644
--- a/core/kotlinx-coroutines-core/test/exceptions/SuppresionTests.kt
+++ b/core/kotlinx-coroutines-core/test/exceptions/SuppresionTests.kt
@@ -5,8 +5,6 @@
package kotlinx.coroutines.experimental.exceptions
import kotlinx.coroutines.experimental.*
-import kotlinx.coroutines.experimental.exceptions.*
-import kotlinx.coroutines.experimental.selects.*
import java.io.*
import kotlin.test.*
diff --git a/core/kotlinx-coroutines-core/test/exceptions/WithContextExceptionHandlingTest.kt b/core/kotlinx-coroutines-core/test/exceptions/WithContextExceptionHandlingTest.kt
index d6e2f74..dad64a3 100644
--- a/core/kotlinx-coroutines-core/test/exceptions/WithContextExceptionHandlingTest.kt
+++ b/core/kotlinx-coroutines-core/test/exceptions/WithContextExceptionHandlingTest.kt
@@ -111,7 +111,7 @@
assertEquals(1, thrown.suppressed().size)
val suppressed = thrown.suppressed()[0]
- assertTrue(suppressed is JobCancellationException)
+ assertTrue(suppressed is CancellationException)
assertTrue(suppressed.cause is IllegalStateException)
}
}
@@ -130,7 +130,7 @@
assertEquals(1, thrown.suppressed().size)
val suppressed = thrown.suppressed()[0]
- assertTrue(suppressed is JobCancellationException)
+ assertTrue(suppressed is CancellationException)
assertTrue(suppressed.cause is IllegalStateException)
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-02b.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-02b.kt
index 92b9367..fdaac97 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-02b.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-02b.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.*
-fun main(args: Array<String>) = runBlocking<Unit> { // start main coroutine
+fun main(args: Array<String>) = runBlocking { // start main coroutine
GlobalScope.launch { // launch new coroutine in background and continue
delay(1000L)
println("World!")
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-03.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-03.kt
index 8f12b7e..00af13d 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-03.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-03.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val job = GlobalScope.launch { // launch new coroutine and keep a reference to its Job
delay(1000L)
println("World!")
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-03s.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-03s.kt
index 94e0ee4..199237e 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-03s.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-03s.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.*
-fun main(args: Array<String>) = runBlocking<Unit> { // this: CoroutineScope
+fun main(args: Array<String>) = runBlocking { // this: CoroutineScope
launch { // launch new coroutine in the scope of runBlocking
delay(1000L)
println("World!")
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-04.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-04.kt
index 1ff45e9..00483a2 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-04.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-04.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.*
-fun main(args: Array<String>) = runBlocking<Unit> { // this: CoroutineScope
+fun main(args: Array<String>) = runBlocking { // this: CoroutineScope
launch {
delay(200L)
println("Task from runBlocking")
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-05.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-05.kt
index 1380254..6d25eca 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-05.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-05.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
launch { doWorld() }
println("Hello,")
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-05s.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-05s.kt
index c3df91d..62f5d71 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-05s.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-05s.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
launchDoWorld()
println("Hello,")
}
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-06.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-06.kt
index bcf4e37..8182934 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-06.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-06.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
repeat(100_000) { // launch a lot of coroutines
launch {
delay(1000L)
diff --git a/core/kotlinx-coroutines-core/test/guide/example-basic-07.kt b/core/kotlinx-coroutines-core/test/guide/example-basic-07.kt
index a5af1ab..829e7b9 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-basic-07.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-basic-07.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
GlobalScope.launch {
repeat(1000) { i ->
println("I'm sleeping $i ...")
diff --git a/core/kotlinx-coroutines-core/test/guide/example-cancel-01.kt b/core/kotlinx-coroutines-core/test/guide/example-cancel-01.kt
index 8760f37..5862235 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-cancel-01.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-cancel-01.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val job = launch {
repeat(1000) { i ->
println("I'm sleeping $i ...")
diff --git a/core/kotlinx-coroutines-core/test/guide/example-cancel-02.kt b/core/kotlinx-coroutines-core/test/guide/example-cancel-02.kt
index a175490..77206eb 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-cancel-02.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-cancel-02.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val startTime = timeSource.currentTimeMillis()
val job = launch(Dispatchers.Default) {
var nextPrintTime = startTime
diff --git a/core/kotlinx-coroutines-core/test/guide/example-cancel-03.kt b/core/kotlinx-coroutines-core/test/guide/example-cancel-03.kt
index e44e502..ff97f75 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-cancel-03.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-cancel-03.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val startTime = timeSource.currentTimeMillis()
val job = launch(Dispatchers.Default) {
var nextPrintTime = startTime
diff --git a/core/kotlinx-coroutines-core/test/guide/example-cancel-04.kt b/core/kotlinx-coroutines-core/test/guide/example-cancel-04.kt
index fa7da09..8533d50 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-cancel-04.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-cancel-04.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val job = launch {
try {
repeat(1000) { i ->
diff --git a/core/kotlinx-coroutines-core/test/guide/example-cancel-05.kt b/core/kotlinx-coroutines-core/test/guide/example-cancel-05.kt
index 268a4e9..bed20d5 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-cancel-05.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-cancel-05.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val job = launch {
try {
repeat(1000) { i ->
diff --git a/core/kotlinx-coroutines-core/test/guide/example-cancel-06.kt b/core/kotlinx-coroutines-core/test/guide/example-cancel-06.kt
index 7e6f046..c0c38c0 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-cancel-06.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-cancel-06.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
withTimeout(1300L) {
repeat(1000) { i ->
println("I'm sleeping $i ...")
diff --git a/core/kotlinx-coroutines-core/test/guide/example-cancel-07.kt b/core/kotlinx-coroutines-core/test/guide/example-cancel-07.kt
index 1dbe8f4..16b27e2 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-cancel-07.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-cancel-07.kt
@@ -7,7 +7,7 @@
import kotlinx.coroutines.experimental.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val result = withTimeoutOrNull(1300L) {
repeat(1000) { i ->
println("I'm sleeping $i ...")
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-01.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-01.kt
index 4758a86..95b8092 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-01.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-01.kt
@@ -8,7 +8,7 @@
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val channel = Channel<Int>()
launch {
// this might be heavy CPU-consuming computation or async logic, we'll just send five squares
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-02.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-02.kt
index 452401a..35d5a90 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-02.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-02.kt
@@ -8,7 +8,7 @@
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.*
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val channel = Channel<Int>()
launch {
for (x in 1..5) channel.send(x * x)
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-03.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-03.kt
index 0d52b32..a80cbab 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-03.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-03.kt
@@ -8,11 +8,11 @@
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.*
-fun CoroutineScope.produceSquares() = produce<Int> {
+fun CoroutineScope.produceSquares(): ReceiveChannel<Int> = produce {
for (x in 1..5) send(x * x)
}
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val squares = produceSquares()
squares.consumeEach { println(it) }
println("Done!")
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-04.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-04.kt
index 197b5d0..50e04ec 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-04.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-04.kt
@@ -13,11 +13,11 @@
while (true) send(x++) // infinite stream of integers starting from 1
}
-fun CoroutineScope.square(numbers: ReceiveChannel<Int>) = produce<Int> {
+fun CoroutineScope.square(numbers: ReceiveChannel<Int>): ReceiveChannel<Int> = produce {
for (x in numbers) send(x * x)
}
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val numbers = produceNumbers() // produces integers from 1 and on
val squares = square(numbers) // squares integers
for (i in 1..5) println(squares.receive()) // print first five
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-05.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-05.kt
index 5534e0f..0ef3e78 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-05.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-05.kt
@@ -18,7 +18,7 @@
for (x in numbers) if (x % prime != 0) send(x)
}
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
var cur = numbersFrom(2)
for (i in 1..10) {
val prime = cur.receive()
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-07.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-07.kt
index 4c1ae65..191c505 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-07.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-07.kt
@@ -16,7 +16,7 @@
}
}
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val channel = Channel<String>()
launch { sendString(channel, "foo", 200L) }
launch { sendString(channel, "BAR!", 500L) }
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-09.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-09.kt
index cf6421a..4eabebe 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-09.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-09.kt
@@ -11,7 +11,7 @@
data class Ball(var hits: Int)
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val table = Channel<Ball>() // a shared table
launch { player("ping", table) }
launch { player("pong", table) }
diff --git a/core/kotlinx-coroutines-core/test/guide/example-channel-10.kt b/core/kotlinx-coroutines-core/test/guide/example-channel-10.kt
index 258f658..6d3622c 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-channel-10.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-channel-10.kt
@@ -9,7 +9,7 @@
import kotlinx.coroutines.experimental.channels.*
fun main(args: Array<String>) = runBlocking<Unit> {
- val tickerChannel = ticker(delay = 100, initialDelay = 0) // create ticker channel
+ val tickerChannel = ticker(delayMillis = 100, initialDelayMillis = 0) // create ticker channel
var nextElement = withTimeoutOrNull(1) { tickerChannel.receive() }
println("Initial element is available immediately: $nextElement") // initial delay hasn't passed yet
diff --git a/core/kotlinx-coroutines-core/test/guide/example-exceptions-06.kt b/core/kotlinx-coroutines-core/test/guide/example-exceptions-06.kt
index 6d95e3f..d08c57a 100644
--- a/core/kotlinx-coroutines-core/test/guide/example-exceptions-06.kt
+++ b/core/kotlinx-coroutines-core/test/guide/example-exceptions-06.kt
@@ -23,8 +23,8 @@
}
try {
inner.join()
- } catch (e: JobCancellationException) {
- println("Rethrowing JobCancellationException with original cause")
+ } catch (e: CancellationException) {
+ println("Rethrowing CancellationException with original cause")
throw e
}
}
diff --git a/core/kotlinx-coroutines-core/test/guide/test/ExceptionsGuideTest.kt b/core/kotlinx-coroutines-core/test/guide/test/ExceptionsGuideTest.kt
index b9a46fc..5b2ae61 100644
--- a/core/kotlinx-coroutines-core/test/guide/test/ExceptionsGuideTest.kt
+++ b/core/kotlinx-coroutines-core/test/guide/test/ExceptionsGuideTest.kt
@@ -52,7 +52,7 @@
@Test
fun testKotlinxCoroutinesExperimentalGuideExceptions06() {
test("KotlinxCoroutinesExperimentalGuideExceptions06") { kotlinx.coroutines.experimental.guide.exceptions06.main(emptyArray()) }.verifyLines(
- "Rethrowing JobCancellationException with original cause",
+ "Rethrowing CancellationException with original cause",
"Caught original java.io.IOException"
)
}
diff --git a/core/kotlinx-coroutines-core/test/guide/test/TestUtil.kt b/core/kotlinx-coroutines-core/test/guide/test/TestUtil.kt
index c1e55c8..8b3c051 100644
--- a/core/kotlinx-coroutines-core/test/guide/test/TestUtil.kt
+++ b/core/kotlinx-coroutines-core/test/guide/test/TestUtil.kt
@@ -24,6 +24,7 @@
private const val SHUTDOWN_TIMEOUT = 5000L // 5 sec at most to wait
private val OUT_ENABLED = systemProp("guide.tests.sout", false)
+@Suppress("DEPRECATION")
fun test(name: String, block: () -> Unit): List<String> = outputException(name) {
val sout = System.out
val oldOut = if (OUT_ENABLED) System.out else NullOut
diff --git a/core/kotlinx-coroutines-core/test/internal/LockFreeLinkedListAtomicStressLFTest.kt b/core/kotlinx-coroutines-core/test/internal/LockFreeLinkedListAtomicStressLFTest.kt
index a29af3d..832d6e6 100644
--- a/core/kotlinx-coroutines-core/test/internal/LockFreeLinkedListAtomicStressLFTest.kt
+++ b/core/kotlinx-coroutines-core/test/internal/LockFreeLinkedListAtomicStressLFTest.kt
@@ -23,15 +23,15 @@
private val TEST_DURATION_SEC = 5 * stressTestMultiplier
- val nLists = 4
- val nAdderThreads = 4
- val nRemoverThreads = 4
+ private val nLists = 4
+ private val nAdderThreads = 4
+ private val nRemoverThreads = 4
- val lists = Array(nLists) { LockFreeLinkedListHead() }
+ private val lists = Array(nLists) { LockFreeLinkedListHead() }
- val undone = AtomicLong()
- val missed = AtomicLong()
- val removed = AtomicLong()
+ private val undone = AtomicLong()
+ private val missed = AtomicLong()
+ private val removed = AtomicLong()
val error = AtomicReference<Throwable>()
@Test
diff --git a/core/kotlinx-coroutines-core/test/internal/LockFreeLinkedListLongStressTest.kt b/core/kotlinx-coroutines-core/test/internal/LockFreeLinkedListLongStressTest.kt
index 92a7457..e005327 100644
--- a/core/kotlinx-coroutines-core/test/internal/LockFreeLinkedListLongStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/internal/LockFreeLinkedListLongStressTest.kt
@@ -21,13 +21,13 @@
val list = LockFreeLinkedListHead()
val threads = mutableListOf<Thread>()
- val nAdded = 10_000_000 // should not stress more, because that'll run out of memory
- val nAddThreads = 4 // must be power of 2 (!!!)
- val nRemoveThreads = 6
- val removeProbability = 0.2
- val workingAdders = AtomicInteger(nAddThreads)
+ private val nAdded = 10_000_000 // should not stress more, because that'll run out of memory
+ private val nAddThreads = 4 // must be power of 2 (!!!)
+ private val nRemoveThreads = 6
+ private val removeProbability = 0.2
+ private val workingAdders = AtomicInteger(nAddThreads)
- fun shallRemove(i: Int) = i and 63 != 42
+ private fun shallRemove(i: Int) = i and 63 != 42
@Test
fun testStress() {
diff --git a/core/kotlinx-coroutines-core/test/internal/LockFreeLinkedListShortStressTest.kt b/core/kotlinx-coroutines-core/test/internal/LockFreeLinkedListShortStressTest.kt
index f85702c..49c3e17 100644
--- a/core/kotlinx-coroutines-core/test/internal/LockFreeLinkedListShortStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/internal/LockFreeLinkedListShortStressTest.kt
@@ -20,17 +20,17 @@
data class IntNode(val i: Int) : LockFreeLinkedListNode()
val list = LockFreeLinkedListHead()
- val TEST_DURATION = 5000L * stressTestMultiplier
+ private val TEST_DURATION = 5000L * stressTestMultiplier
val threads = mutableListOf<Thread>()
- val nAdderThreads = 6
- val nRemoverThreads = 4
- val completedAdder = AtomicInteger()
- val completedRemover = AtomicInteger()
+ private val nAdderThreads = 6
+ private val nRemoverThreads = 4
+ private val completedAdder = AtomicInteger()
+ private val completedRemover = AtomicInteger()
- val undone = AtomicInteger()
- val missed = AtomicInteger()
- val removed = AtomicInteger()
+ private val undone = AtomicInteger()
+ private val missed = AtomicInteger()
+ private val removed = AtomicInteger()
@Test
fun testStress() {
diff --git a/core/kotlinx-coroutines-core/test/internal/LockFreeListLinearizabilityTest.kt b/core/kotlinx-coroutines-core/test/internal/LockFreeListLinearizabilityTest.kt
index ce3e299..2464458 100644
--- a/core/kotlinx-coroutines-core/test/internal/LockFreeListLinearizabilityTest.kt
+++ b/core/kotlinx-coroutines-core/test/internal/LockFreeListLinearizabilityTest.kt
@@ -2,6 +2,8 @@
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
+@file:Suppress("unused")
+
package kotlinx.coroutines.experimental.internal
import com.devexperts.dxlab.lincheck.*
@@ -15,7 +17,7 @@
class LockFreeListLinearizabilityTest : TestBase() {
class Node(val value: Int): LockFreeLinkedListNode()
- lateinit var q: LockFreeLinkedListHead
+ private lateinit var q: LockFreeLinkedListHead
@Reset
fun resetList() {
@@ -44,7 +46,7 @@
return node.value
}
- fun Any.isSame(value: Int) = this is Node && this.value == value
+ private fun Any.isSame(value: Int) = this is Node && this.value == value
@Test
fun testAddRemoveLinearizability() {
diff --git a/core/kotlinx-coroutines-core/test/internal/LockFreeMPSCQueueLinearizabilityTest.kt b/core/kotlinx-coroutines-core/test/internal/LockFreeMPSCQueueLinearizabilityTest.kt
index 69e24ad..befbc19 100644
--- a/core/kotlinx-coroutines-core/test/internal/LockFreeMPSCQueueLinearizabilityTest.kt
+++ b/core/kotlinx-coroutines-core/test/internal/LockFreeMPSCQueueLinearizabilityTest.kt
@@ -2,6 +2,8 @@
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
+@file:Suppress("unused")
+
package kotlinx.coroutines.experimental.internal
import com.devexperts.dxlab.lincheck.*
diff --git a/core/kotlinx-coroutines-core/test/internal/ThreadSafeHeapTest.kt b/core/kotlinx-coroutines-core/test/internal/ThreadSafeHeapTest.kt
index 74e593c..12a24a5 100644
--- a/core/kotlinx-coroutines-core/test/internal/ThreadSafeHeapTest.kt
+++ b/core/kotlinx-coroutines-core/test/internal/ThreadSafeHeapTest.kt
@@ -87,7 +87,7 @@
assertTrue(h.remove(rndNode))
// remove head and validate
val headNode = h.removeFirstOrNull()!! // must not be null!!!
- assertTrue(headNode === set.first(), "Expected ${set.first()}, but found $headNode, remaining size ${h.size}")
+ assertSame(headNode, set.first(), "Expected ${set.first()}, but found $headNode, remaining size ${h.size}")
assertTrue(set.remove(headNode))
assertEquals(set.size, h.size)
}
diff --git a/core/kotlinx-coroutines-core/test/linearizability/FixedBehaviourExecutionGenerator.kt b/core/kotlinx-coroutines-core/test/linearizability/FixedBehaviourExecutionGenerator.kt
index b223bba..644a7b0 100644
--- a/core/kotlinx-coroutines-core/test/linearizability/FixedBehaviourExecutionGenerator.kt
+++ b/core/kotlinx-coroutines-core/test/linearizability/FixedBehaviourExecutionGenerator.kt
@@ -68,6 +68,7 @@
}
// Ad-hoc fixed execution injection for lin-checker
+@Suppress("unused")
class FixedBehaviourExecutionGenerator(testConfiguration: CTestConfiguration, testStructure: CTestStructure)
: ExecutionGenerator(testConfiguration, testStructure) {
diff --git a/core/kotlinx-coroutines-core/test/linearizability/LinTesting.kt b/core/kotlinx-coroutines-core/test/linearizability/LinTesting.kt
index d417d59..e45fa7b 100644
--- a/core/kotlinx-coroutines-core/test/linearizability/LinTesting.kt
+++ b/core/kotlinx-coroutines-core/test/linearizability/LinTesting.kt
@@ -65,9 +65,10 @@
) : Verifier(actorsPerThread, testInstance, resetMethod) {
private val possibleResultsSet: Set<List<List<Result>>> =
generateAllLinearizableExecutions(actorsPerThread)
+ .asSequence()
.map { linEx: List<Actor> ->
val res: List<Result> = executeActors(testInstance, linEx)
- val actorIds = linEx.withIndex().associateBy({ it.value}, { it.index })
+ val actorIds = linEx.asSequence().withIndex().associateBy({ it.value}, { it.index })
actorsPerThread.map { actors -> actors.map { actor -> res[actorIds[actor]!!] } }
}.toSet()
diff --git a/core/kotlinx-coroutines-core/test/scheduling/BlockingCoroutineDispatcherStressTest.kt b/core/kotlinx-coroutines-core/test/scheduling/BlockingCoroutineDispatcherStressTest.kt
index 79ec6d4..5c79f8b 100644
--- a/core/kotlinx-coroutines-core/test/scheduling/BlockingCoroutineDispatcherStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/scheduling/BlockingCoroutineDispatcherStressTest.kt
@@ -2,6 +2,8 @@
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
+@file:Suppress("DeferredResultUnused")
+
package kotlinx.coroutines.experimental.scheduling
import kotlinx.coroutines.experimental.*
@@ -109,7 +111,7 @@
repeat(iterations) {
// Overwhelm global queue with external CPU tasks
- val cpuTasks = (1..CORES_COUNT).map { async(dispatcher) { while (true) delay(1, TimeUnit.NANOSECONDS) } }
+ val cpuTasks = (1..CORES_COUNT).map { async(dispatcher) { while (true) delay(1) } }
val barrier = CyclicBarrier(blockingLimit + 1)
// Should eat all limit * 3 cpu without any starvation
diff --git a/core/kotlinx-coroutines-core/test/scheduling/BlockingIOTerminationStressTest.kt b/core/kotlinx-coroutines-core/test/scheduling/BlockingIOTerminationStressTest.kt
index 48e2653..f43f546 100644
--- a/core/kotlinx-coroutines-core/test/scheduling/BlockingIOTerminationStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/scheduling/BlockingIOTerminationStressTest.kt
@@ -29,7 +29,7 @@
while (System.currentTimeMillis() < deadline) {
Thread.sleep(rnd.nextInt(30).toLong())
repeat(rnd.nextInt(5) + 1) {
- launch(ioDispatcher) {
+ GlobalScope.launch(ioDispatcher) {
Thread.sleep(rnd.nextInt(5).toLong())
}
}
diff --git a/core/kotlinx-coroutines-core/test/scheduling/CoroutineSchedulerShrinkTest.kt b/core/kotlinx-coroutines-core/test/scheduling/CoroutineSchedulerShrinkTest.kt
index ab40311..e68361b 100644
--- a/core/kotlinx-coroutines-core/test/scheduling/CoroutineSchedulerShrinkTest.kt
+++ b/core/kotlinx-coroutines-core/test/scheduling/CoroutineSchedulerShrinkTest.kt
@@ -35,7 +35,7 @@
val blockingTasks = launchBlocking()
checkBlockingTasks(blockingTasks)
- delay(2, TimeUnit.SECONDS)
+ delay(2000)
// Pool should shrink to core size +- eps
checkPoolThreadsExist(CORES_COUNT..CORES_COUNT + 3)
}
@@ -61,7 +61,7 @@
// Check blocking tasks succeeded properly
checkBlockingTasks(blockingTasks)
- delay(2, TimeUnit.SECONDS)
+ delay(2000)
// Pool should shrink to core size
checkPoolThreadsExist(CORES_COUNT..CORES_COUNT + 3)
}
@@ -99,7 +99,7 @@
checkBlockingTasks(blockingTasks)
- delay(2, TimeUnit.SECONDS)
+ delay(2000)
// Pool should shrink almost to core size (+/- eps)
checkPoolThreadsExist(CORES_COUNT..CORES_COUNT + 3)
diff --git a/core/kotlinx-coroutines-core/test/scheduling/CoroutineSchedulerStressTest.kt b/core/kotlinx-coroutines-core/test/scheduling/CoroutineSchedulerStressTest.kt
index fb2947e..b4164bf 100644
--- a/core/kotlinx-coroutines-core/test/scheduling/CoroutineSchedulerStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/scheduling/CoroutineSchedulerStressTest.kt
@@ -36,6 +36,7 @@
}
@Test
+ @Suppress("DEPRECATION")
fun testExternalTasksSubmission() {
stressTest(CommonPool)
}
diff --git a/core/kotlinx-coroutines-core/test/scheduling/SchedulerTestBase.kt b/core/kotlinx-coroutines-core/test/scheduling/SchedulerTestBase.kt
index ac403e8..a48590e 100644
--- a/core/kotlinx-coroutines-core/test/scheduling/SchedulerTestBase.kt
+++ b/core/kotlinx-coroutines-core/test/scheduling/SchedulerTestBase.kt
@@ -37,12 +37,12 @@
* Asserts that any number of pool worker threads in [range] exists at the time of method invocation
*/
fun checkPoolThreadsExist(range: IntRange) {
- val threads = Thread.getAllStackTraces().keys.filter { it is CoroutineScheduler.Worker }.count()
+ val threads = Thread.getAllStackTraces().keys.asSequence().filter { it is CoroutineScheduler.Worker }.count()
require(threads in range) { "Expected threads in $range interval, but has $threads" }
}
private fun maxSequenceNumber(): Int? {
- return Thread.getAllStackTraces().keys.filter { it is CoroutineScheduler.Worker }
+ return Thread.getAllStackTraces().keys.asSequence().filter { it is CoroutineScheduler.Worker }
.map { sequenceNumber(it.name) }.max()
}
@@ -94,8 +94,6 @@
return _dispatcher!!.limited(parallelism) + handler
}
- fun initialPoolSize() = corePoolSize.coerceAtMost(2)
-
@After
fun after() {
runBlocking {
diff --git a/core/kotlinx-coroutines-core/test/selects/SelectChannelStressTest.kt b/core/kotlinx-coroutines-core/test/selects/SelectChannelStressTest.kt
index a83b1c4..e842256 100644
--- a/core/kotlinx-coroutines-core/test/selects/SelectChannelStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/selects/SelectChannelStressTest.kt
@@ -13,7 +13,7 @@
@Test
fun testSelectSendResourceCleanupArrayChannel() = runTest {
- val channel = ArrayChannel<Int>(1)
+ val channel = Channel<Int>(1)
val n = 10_000_000 * stressTestMultiplier
expect(1)
channel.send(-1) // fill the buffer, so all subsequent sends cannot proceed
@@ -28,7 +28,7 @@
@Test
fun testSelectReceiveResourceCleanupArrayChannel() = runTest {
- val channel = ArrayChannel<Int>(1)
+ val channel = Channel<Int>(1)
val n = 10_000_000 * stressTestMultiplier
expect(1)
repeat(n) { i ->
@@ -42,7 +42,7 @@
@Test
fun testSelectSendResourceCleanupRendezvousChannel() = runTest {
- val channel = RendezvousChannel<Int>()
+ val channel = Channel<Int>(Channel.RENDEZVOUS)
val n = 1_000_000 * stressTestMultiplier
expect(1)
repeat(n) { i ->
@@ -56,7 +56,7 @@
@Test
fun testSelectReceiveResourceRendezvousChannel() = runTest {
- val channel = RendezvousChannel<Int>()
+ val channel = Channel<Int>(Channel.RENDEZVOUS)
val n = 1_000_000 * stressTestMultiplier
expect(1)
repeat(n) { i ->
diff --git a/core/kotlinx-coroutines-core/test/selects/SelectPhilosophersStressTest.kt b/core/kotlinx-coroutines-core/test/selects/SelectPhilosophersStressTest.kt
index f49da71..7559406 100644
--- a/core/kotlinx-coroutines-core/test/selects/SelectPhilosophersStressTest.kt
+++ b/core/kotlinx-coroutines-core/test/selects/SelectPhilosophersStressTest.kt
@@ -10,12 +10,12 @@
import org.junit.Assert.*
class SelectPhilosophersStressTest : TestBase() {
- val TEST_DURATION = 3000L * stressTestMultiplier
+ private val TEST_DURATION = 3000L * stressTestMultiplier
val n = 10 // number of philosophers
- val forks = Array<Mutex>(n) { Mutex() }
+ private val forks = Array(n) { Mutex() }
- suspend fun eat(id: Int, desc: String) {
+ private suspend fun eat(id: Int, desc: String) {
val left = forks[id]
val right = forks[(id + 1) % n]
while (true) {
diff --git a/docs/basics.md b/docs/basics.md
index 30c4fdf..443a31f 100644
--- a/docs/basics.md
+++ b/docs/basics.md
@@ -115,7 +115,7 @@
the execution of the main function:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> { // start main coroutine
+fun main(args: Array<String>) = runBlocking { // start main coroutine
GlobalScope.launch { // launch new coroutine in background and continue
delay(1000L)
println("World!")
@@ -154,7 +154,7 @@
wait (in a non-blocking way) until the background [Job] that we have launched is complete:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val job = GlobalScope.launch { // launch new coroutine and keep a reference to its Job
delay(1000L)
println("World!")
@@ -194,7 +194,7 @@
in its scope complete. Thus, we can make our example simpler:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> { // this: CoroutineScope
+fun main(args: Array<String>) = runBlocking { // this: CoroutineScope
launch { // launch new coroutine in the scope of runBlocking
delay(1000L)
println("World!")
@@ -217,7 +217,7 @@
while waiting for all children to complete.
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> { // this: CoroutineScope
+fun main(args: Array<String>) = runBlocking { // this: CoroutineScope
launch {
delay(200L)
println("Task from runBlocking")
@@ -255,7 +255,7 @@
use other suspending functions, like `delay` in this example, to _suspend_ execution of a coroutine.
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
launch { doWorld() }
println("Hello,")
}
@@ -281,7 +281,7 @@
[currentScope] builder comes to help: it inherits current [CoroutineScope] from the coroutine context it is invoked.
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
launchDoWorld()
println("Hello,")
}
@@ -306,7 +306,7 @@
Run the following code:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
repeat(100_000) { // launch a lot of coroutines
launch {
delay(1000L)
@@ -329,7 +329,7 @@
returns from the main function after some delay:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
GlobalScope.launch {
repeat(1000) { i ->
println("I'm sleeping $i ...")
diff --git a/docs/cancellation-and-timeouts.md b/docs/cancellation-and-timeouts.md
index b2373f4..a026fd4 100644
--- a/docs/cancellation-and-timeouts.md
+++ b/docs/cancellation-and-timeouts.md
@@ -43,7 +43,7 @@
The [launch] function returns a [Job] that can be used to cancel running coroutine:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val job = launch {
repeat(1000) { i ->
println("I'm sleeping $i ...")
@@ -85,7 +85,7 @@
example shows:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val startTime = System.currentTimeMillis()
val job = launch(Dispatchers.Default) {
var nextPrintTime = startTime
@@ -129,7 +129,7 @@
Replace `while (i < 5)` in the previous example with `while (isActive)` and rerun it.
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val startTime = System.currentTimeMillis()
val job = launch(Dispatchers.Default) {
var nextPrintTime = startTime
@@ -169,7 +169,7 @@
finalization actions normally when coroutine is cancelled:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val job = launch {
try {
repeat(1000) { i ->
@@ -213,7 +213,7 @@
`withContext(NonCancellable) {...}` using [withContext] function and [NonCancellable] context as the following example shows:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val job = launch {
try {
repeat(1000) { i ->
@@ -256,7 +256,7 @@
Look at the following example:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
withTimeout(1300L) {
repeat(1000) { i ->
println("I'm sleeping $i ...")
@@ -290,7 +290,7 @@
that is similar to [withTimeout], but returns `null` on timeout instead of throwing an exception:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val result = withTimeoutOrNull(1300L) {
repeat(1000) { i ->
println("I'm sleeping $i ...")
diff --git a/docs/channels.md b/docs/channels.md
index 70a4614..adf89ed 100644
--- a/docs/channels.md
+++ b/docs/channels.md
@@ -56,7 +56,7 @@
a blocking `take` operation it has a suspending [receive][ReceiveChannel.receive].
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val channel = Channel<Int>()
launch {
// this might be heavy CPU-consuming computation or async logic, we'll just send five squares
@@ -94,7 +94,7 @@
that all previously sent elements before the close are received:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val channel = Channel<Int>()
launch {
for (x in 1..5) channel.send(x * x)
@@ -128,11 +128,11 @@
and an extension function [consumeEach], that replaces a `for` loop on the consumer side:
```kotlin
-fun CoroutineScope.produceSquares() = produce<Int> {
+fun CoroutineScope.produceSquares(): ReceiveChannel<Int> = produce {
for (x in 1..5) send(x * x)
}
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val squares = produceSquares()
squares.consumeEach { println(it) }
println("Done!")
@@ -165,7 +165,7 @@
In the below example the numbers are just squared:
```kotlin
-fun CoroutineScope.square(numbers: ReceiveChannel<Int>) = produce<Int> {
+fun CoroutineScope.square(numbers: ReceiveChannel<Int>): ReceiveChannel<Int> = produce {
for (x in numbers) send(x * x)
}
```
@@ -173,7 +173,7 @@
The main code starts and connects the whole pipeline:
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val numbers = produceNumbers() // produces integers from 1 and on
val squares = square(numbers) // squares integers
for (i in 1..5) println(squares.receive()) // print first five
@@ -238,7 +238,7 @@
the first ten prime numbers.
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
var cur = numbersFrom(2)
for (i in 1..10) {
val prime = cur.receive()
@@ -370,7 +370,7 @@
(in this example we launch them in the context of the main thread as main coroutine's children):
```kotlin
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val channel = Channel<String>()
launch { sendString(channel, "foo", 200L) }
launch { sendString(channel, "BAR!", 500L) }
@@ -457,7 +457,7 @@
```kotlin
data class Ball(var hits: Int)
-fun main(args: Array<String>) = runBlocking<Unit> {
+fun main(args: Array<String>) = runBlocking {
val table = Channel<Ball>() // a shared table
launch { player("ping", table) }
launch { player("pong", table) }
@@ -508,7 +508,7 @@
```kotlin
fun main(args: Array<String>) = runBlocking<Unit> {
- val tickerChannel = ticker(delay = 100, initialDelay = 0) // create ticker channel
+ val tickerChannel = ticker(delayMillis = 100, initialDelayMillis = 0) // create ticker channel
var nextElement = withTimeoutOrNull(1) { tickerChannel.receive() }
println("Initial element is available immediately: $nextElement") // initial delay hasn't passed yet
diff --git a/docs/exception-handling.md b/docs/exception-handling.md
index 9d024ac..e754bc3 100644
--- a/docs/exception-handling.md
+++ b/docs/exception-handling.md
@@ -300,8 +300,8 @@
}
try {
inner.join()
- } catch (e: JobCancellationException) {
- println("Rethrowing JobCancellationException with original cause")
+ } catch (e: CancellationException) {
+ println("Rethrowing CancellationException with original cause")
throw e
}
}
@@ -314,7 +314,7 @@
The output of this code is:
```text
-Rethrowing JobCancellationException with original cause
+Rethrowing CancellationException with original cause
Caught original java.io.IOException
```
<!--- TEST-->
diff --git a/integration/kotlinx-coroutines-jdk8/test/channels8/ChannelsTest.kt b/integration/kotlinx-coroutines-jdk8/test/channels8/ChannelsTest.kt
index 005bb16..6839003 100644
--- a/integration/kotlinx-coroutines-jdk8/test/channels8/ChannelsTest.kt
+++ b/integration/kotlinx-coroutines-jdk8/test/channels8/ChannelsTest.kt
@@ -27,6 +27,7 @@
@Test
fun testReceiveChannelAsStream() {
- assertEquals(testList, testList.asReceiveChannel().asStream().collect(Collectors.toList()))
+ testList.asReceiveChannel()
+ assertEquals(testList, toList().stream().collect(Collectors.toList()))
}
}
diff --git a/integration/kotlinx-coroutines-jdk8/test/examples/ToFuture-example.kt b/integration/kotlinx-coroutines-jdk8/test/examples/ToFuture-example.kt
index abf5fe1..d2b2178 100644
--- a/integration/kotlinx-coroutines-jdk8/test/examples/ToFuture-example.kt
+++ b/integration/kotlinx-coroutines-jdk8/test/examples/ToFuture-example.kt
@@ -12,7 +12,7 @@
log("Started")
val deferred = GlobalScope.async {
log("Busy...")
- delay(1, TimeUnit.SECONDS)
+ delay(1000)
log("Done...")
42
}