Skip to content

Commit

Permalink
Updated coroutines to 1.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
greggiacovelli committed Dec 18, 2021
1 parent e5bbbe9 commit 952bdba
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
7 changes: 5 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ext.versions = [
rxAndroid: '2.0.2',
rxKotlin: '2.2.0',
rxJava1: '1.3.4',
kotlinxCoroutines: '1.4.3',
kotlinxCoroutines: '1.5.2',

stetho: '1.5.0',
stethoOkHttp: '1.5.0',
Expand Down Expand Up @@ -42,6 +42,7 @@ ext.versions = [

junit: '4.12',
assertJ: '3.8.0',
truth: '1.1.3',

stateMachine: "0.2.0"
]
Expand All @@ -61,7 +62,8 @@ ext.libs = [
kotlinx: [
coroutines: [
core: "org.jetbrains.kotlinx:kotlinx-coroutines-core:$versions.kotlinxCoroutines",
reactive: "org.jetbrains.kotlinx:kotlinx-coroutines-reactive:$versions.kotlinxCoroutines"
reactive: "org.jetbrains.kotlinx:kotlinx-coroutines-reactive:$versions.kotlinxCoroutines",
test: "org.jetbrains.kotlinx:kotlinx-coroutines-test:$versions.kotlinxCoroutines"
]
],

Expand Down Expand Up @@ -100,6 +102,7 @@ ext.libs = [
junit: "junit:junit:$versions.junit",
mockito: "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0",
assertJ: "org.assertj:assertj-core:$versions.assertJ",
truth: "com.google.truth:truth:$versions.truth",

kotlin: [
stdlib: "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version",
Expand Down
3 changes: 2 additions & 1 deletion scarlet-stream-adapter-coroutines/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ dependencies {
testImplementation libs.junit
testImplementation libs.mockito
testImplementation libs.kotlin.reflect
testImplementation libs.assertJ
testImplementation libs.kotlinx.coroutines.test
testImplementation libs.truth
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ReceiveChannelAdapter<T> : StreamAdapter<T, ReceiveChannel<T>> {
}

override fun onNext(data: T) {
println("$data is ")
_channel.sendBlocking(data)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

package com.tinder.scarlet.streamadapter.coroutines

import com.google.common.truth.Truth.assertThat
import com.tinder.scarlet.Lifecycle
import com.tinder.scarlet.Scarlet
import com.tinder.scarlet.Stream
import com.tinder.scarlet.WebSocket
import com.tinder.scarlet.lifecycle.LifecycleRegistry
import com.tinder.scarlet.testutils.TestStreamObserver
import com.tinder.scarlet.testutils.any
import com.tinder.scarlet.testutils.test
import com.tinder.scarlet.testutils.containingText
import com.tinder.scarlet.testutils.containingBytes
import com.tinder.scarlet.testutils.containingText
import com.tinder.scarlet.testutils.test
import com.tinder.scarlet.websocket.mockwebserver.newWebSocketFactory
import com.tinder.scarlet.websocket.okhttp.newWebSocketFactory
import com.tinder.scarlet.ws.Receive
Expand All @@ -23,7 +24,6 @@ import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.runBlocking
import okhttp3.OkHttpClient
import okhttp3.mockwebserver.MockWebServer
import org.assertj.core.api.Assertions.assertThat
import org.junit.Rule
import org.junit.Test
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -63,19 +63,19 @@ class ReceiveChannelTest {
assertThat(isSendBytesSuccessful).isTrue()

serverEventObserver.awaitValues(
any<WebSocket.Event.OnConnectionOpened<*>>(),
any<WebSocket.Event.OnMessageReceived>().containingText(textMessage1),
any<WebSocket.Event.OnMessageReceived>().containingText(textMessage2),
any<WebSocket.Event.OnMessageReceived>().containingBytes(bytesMessage1),
any<WebSocket.Event.OnMessageReceived>().containingBytes(bytesMessage2)
any<WebSocket.Event.OnConnectionOpened<*>>(),
any<WebSocket.Event.OnMessageReceived>().containingText(textMessage1),
any<WebSocket.Event.OnMessageReceived>().containingText(textMessage2),
any<WebSocket.Event.OnMessageReceived>().containingBytes(bytesMessage1),
any<WebSocket.Event.OnMessageReceived>().containingBytes(bytesMessage2)
)

runBlocking {
assertThat(testTextChannel.receiveOrNull()).isEqualTo(textMessage1)
assertThat(testTextChannel.receiveOrNull()).isEqualTo(textMessage2)
assertThat(testTextChannel.receive()).isEqualTo(textMessage1)
assertThat(testTextChannel.receive()).isEqualTo(textMessage2)

assertThat(testBytesChannel.receiveOrNull()).isEqualTo(bytesMessage1)
assertThat(testBytesChannel.receiveOrNull()).isEqualTo(bytesMessage2)
assertThat(testBytesChannel.receive()).isEqualTo(bytesMessage1)
assertThat(testBytesChannel.receive()).isEqualTo(bytesMessage2)
}
}

Expand All @@ -96,33 +96,33 @@ class ReceiveChannelTest {
private fun createServer(): Service {
val webSocketFactory = mockWebServer.newWebSocketFactory()
val scarlet = Scarlet.Builder()
.webSocketFactory(webSocketFactory)
.lifecycle(serverLifecycleRegistry)
.addStreamAdapterFactory(CoroutinesStreamAdapterFactory())
.build()
.webSocketFactory(webSocketFactory)
.lifecycle(serverLifecycleRegistry)
.addStreamAdapterFactory(CoroutinesStreamAdapterFactory())
.build()
return scarlet.create()
}

private fun createClient(): Service {
val okHttpClient = OkHttpClient.Builder()
.writeTimeout(500, TimeUnit.MILLISECONDS)
.readTimeout(500, TimeUnit.MILLISECONDS)
.build()
.writeTimeout(500, TimeUnit.MILLISECONDS)
.readTimeout(500, TimeUnit.MILLISECONDS)
.build()
val webSocketFactory = okHttpClient.newWebSocketFactory(serverUrlString)
val scarlet = Scarlet.Builder()
.webSocketFactory(webSocketFactory)
.lifecycle(clientLifecycleRegistry)
.addStreamAdapterFactory(CoroutinesStreamAdapterFactory())
.build()
.webSocketFactory(webSocketFactory)
.lifecycle(clientLifecycleRegistry)
.addStreamAdapterFactory(CoroutinesStreamAdapterFactory())
.build()
return scarlet.create()
}

private fun blockUntilConnectionIsEstablish() {
clientEventObserver.awaitValues(
any<WebSocket.Event.OnConnectionOpened<*>>()
any<WebSocket.Event.OnConnectionOpened<*>>()
)
serverEventObserver.awaitValues(
any<WebSocket.Event.OnConnectionOpened<*>>()
any<WebSocket.Event.OnConnectionOpened<*>>()
)
}

Expand All @@ -148,4 +148,4 @@ class ReceiveChannelTest {
@Send
fun sendBytesAndConfirm(message: ByteArray): Boolean
}
}
}

0 comments on commit 952bdba

Please sign in to comment.