From e9c63dfb11f49d217082b5f288699ecf95ceb94d Mon Sep 17 00:00:00 2001 From: zhxnlai Date: Tue, 19 Jun 2018 17:13:25 +0200 Subject: [PATCH 01/17] Update README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 398c48e2..7f2e450e 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ This README is still **WIP**. Please see the [tutorial][tutorial] for more infor Tutorial --- - [Taming WebSocket with Scarlet][tutorial] +- [A talk][slides] at [Conference for Kotliners][kotliners] Usage --- @@ -144,3 +145,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [latest-jar]: https://tinder.jfrog.io/tinder/webapp/#/artifacts/browse/tree/General/libs-release-local/com/tinder/scarlet/scarlet [demo-app]: https://github.com/Tinder/Scarlet/tree/master/demo/src/main/java/com/tinder/app [tutorial]: https://tech.gotinder.com/taming-websocket-with-scarlet/ + [slides]: https://speakerdeck.com/zhxnlai/taming-websocket-with-scarlet + [kotliners]: + https://www.conferenceforkotliners.com/ From 65cf80820a4b60fd90be23bebfff54245e482a87 Mon Sep 17 00:00:00 2001 From: zhxnlai Date: Tue, 19 Jun 2018 17:13:29 +0200 Subject: [PATCH 02/17] Add Circle CI --- .circleci/config.yml | 21 +++++++++++++++++++++ README.md | 1 + 2 files changed, 22 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..fd050e36 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,21 @@ +version: 2 + +jobs: + build: + docker: + - image: circleci/android:api-27-alpha + environment: + TERM: dumb + GRADLE_OPTS: '-Dorg.gradle.jvmargs="-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap" -Dorg.gradle.parallel=false -Dorg.gradle.daemon=true' + CIRCLE_TEST_REPORTS: test-reports + resource_class: xlarge + parallelism: 4 + steps: + - checkout + - run: + name: Disable PreDexing + command: echo "disablePreDex" >> gradle.properties + - run: if [ -e ./gradlew ]; then ./gradlew dependencies;else gradle dependencies;fi + - run: ./gradlew test + - run: mkdir -p $CIRCLE_TEST_REPORTS/junit/ + - run: find . -type f -regex ".*/build/test-results/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \; diff --git a/README.md b/README.md index 7f2e450e..eed5c113 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ Scarlet === +[![CircleCI](https://circleci.com/gh/Tinder/Scarlet.svg?style=svg)](https://circleci.com/gh/Tinder/Scarlet) A Retrofit inspired WebSocket client for Kotlin, Java, and Android. From 66ea808cccb18166cc556463e75c1b8fd13eb805 Mon Sep 17 00:00:00 2001 From: zhxnlai Date: Tue, 19 Jun 2018 17:15:40 +0200 Subject: [PATCH 03/17] Update Group Id --- scarlet-core-internal/build.gradle | 2 +- scarlet-core/build.gradle | 2 +- scarlet-lifecycle-android/build.gradle | 2 +- scarlet-message-adapter-builtin/build.gradle | 2 +- scarlet-message-adapter-gson/build.gradle | 2 +- scarlet-message-adapter-moshi/build.gradle | 2 +- scarlet-message-adapter-protobuf/build.gradle | 2 +- scarlet-stream-adapter-builtin/build.gradle | 2 +- scarlet-stream-adapter-rxjava/build.gradle | 2 +- scarlet-stream-adapter-rxjava2/build.gradle | 2 +- scarlet-test-utils/build.gradle | 2 +- scarlet-websocket-mockwebserver/build.gradle | 2 +- scarlet-websocket-okhttp/build.gradle | 2 +- scarlet/build.gradle | 2 +- state-machine/build.gradle | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/scarlet-core-internal/build.gradle b/scarlet-core-internal/build.gradle index 04341c7f..98ab8041 100644 --- a/scarlet-core-internal/build.gradle +++ b/scarlet-core-internal/build.gradle @@ -27,7 +27,7 @@ artifacts { publishing { publications { mavenJava(MavenPublication) { - groupId 'com.tinder.scarlet' + groupId 'com.tinder' version version artifactId project.getName() artifact sourcesJar diff --git a/scarlet-core/build.gradle b/scarlet-core/build.gradle index 86813d44..3de8323a 100644 --- a/scarlet-core/build.gradle +++ b/scarlet-core/build.gradle @@ -38,7 +38,7 @@ artifacts { publishing { publications { mavenJava(MavenPublication) { - groupId 'com.tinder.scarlet' + groupId 'com.tinder' version version artifactId project.getName() artifact sourcesJar diff --git a/scarlet-lifecycle-android/build.gradle b/scarlet-lifecycle-android/build.gradle index 124d5168..80acb44c 100755 --- a/scarlet-lifecycle-android/build.gradle +++ b/scarlet-lifecycle-android/build.gradle @@ -63,7 +63,7 @@ task sourcesJar(type: Jar) { publishing { publications { aar(MavenPublication) { - groupId 'com.tinder.scarlet' + groupId 'com.tinder' version version artifactId project.getName() diff --git a/scarlet-message-adapter-builtin/build.gradle b/scarlet-message-adapter-builtin/build.gradle index 881e6aa2..0527cd6c 100644 --- a/scarlet-message-adapter-builtin/build.gradle +++ b/scarlet-message-adapter-builtin/build.gradle @@ -25,7 +25,7 @@ artifacts { publishing { publications { mavenJava(MavenPublication) { - groupId 'com.tinder.scarlet' + groupId 'com.tinder' version version artifactId project.getName() artifact sourcesJar diff --git a/scarlet-message-adapter-gson/build.gradle b/scarlet-message-adapter-gson/build.gradle index 1a777de9..b174d6b4 100755 --- a/scarlet-message-adapter-gson/build.gradle +++ b/scarlet-message-adapter-gson/build.gradle @@ -46,7 +46,7 @@ artifacts { publishing { publications { mavenJava(MavenPublication) { - groupId 'com.tinder.scarlet' + groupId 'com.tinder' version version artifactId project.getName() artifact sourcesJar diff --git a/scarlet-message-adapter-moshi/build.gradle b/scarlet-message-adapter-moshi/build.gradle index 905d0dee..f7836198 100755 --- a/scarlet-message-adapter-moshi/build.gradle +++ b/scarlet-message-adapter-moshi/build.gradle @@ -51,7 +51,7 @@ artifacts { publishing { publications { mavenJava(MavenPublication) { - groupId 'com.tinder.scarlet' + groupId 'com.tinder' version version artifactId project.getName() artifact sourcesJar diff --git a/scarlet-message-adapter-protobuf/build.gradle b/scarlet-message-adapter-protobuf/build.gradle index 0c7dc4cf..7d905bf3 100755 --- a/scarlet-message-adapter-protobuf/build.gradle +++ b/scarlet-message-adapter-protobuf/build.gradle @@ -45,7 +45,7 @@ artifacts { publishing { publications { mavenJava(MavenPublication) { - groupId 'com.tinder.scarlet' + groupId 'com.tinder' version version artifactId project.getName() artifact sourcesJar diff --git a/scarlet-stream-adapter-builtin/build.gradle b/scarlet-stream-adapter-builtin/build.gradle index 881e6aa2..0527cd6c 100644 --- a/scarlet-stream-adapter-builtin/build.gradle +++ b/scarlet-stream-adapter-builtin/build.gradle @@ -25,7 +25,7 @@ artifacts { publishing { publications { mavenJava(MavenPublication) { - groupId 'com.tinder.scarlet' + groupId 'com.tinder' version version artifactId project.getName() artifact sourcesJar diff --git a/scarlet-stream-adapter-rxjava/build.gradle b/scarlet-stream-adapter-rxjava/build.gradle index f4fbd2b7..1145c482 100755 --- a/scarlet-stream-adapter-rxjava/build.gradle +++ b/scarlet-stream-adapter-rxjava/build.gradle @@ -45,7 +45,7 @@ artifacts { publishing { publications { mavenJava(MavenPublication) { - groupId 'com.tinder.scarlet' + groupId 'com.tinder' version version artifactId project.getName() artifact sourcesJar diff --git a/scarlet-stream-adapter-rxjava2/build.gradle b/scarlet-stream-adapter-rxjava2/build.gradle index 97754282..52f79154 100755 --- a/scarlet-stream-adapter-rxjava2/build.gradle +++ b/scarlet-stream-adapter-rxjava2/build.gradle @@ -45,7 +45,7 @@ artifacts { publishing { publications { mavenJava(MavenPublication) { - groupId 'com.tinder.scarlet' + groupId 'com.tinder' version version artifactId project.getName() artifact sourcesJar diff --git a/scarlet-test-utils/build.gradle b/scarlet-test-utils/build.gradle index d633d7f0..9d7ae68b 100644 --- a/scarlet-test-utils/build.gradle +++ b/scarlet-test-utils/build.gradle @@ -37,7 +37,7 @@ artifacts { publishing { publications { mavenJava(MavenPublication) { - groupId 'com.tinder.scarlet' + groupId 'com.tinder' version version artifactId project.getName() artifact sourcesJar diff --git a/scarlet-websocket-mockwebserver/build.gradle b/scarlet-websocket-mockwebserver/build.gradle index b0c22ae0..d6ab5691 100644 --- a/scarlet-websocket-mockwebserver/build.gradle +++ b/scarlet-websocket-mockwebserver/build.gradle @@ -36,7 +36,7 @@ artifacts { publishing { publications { mavenJava(MavenPublication) { - groupId 'com.tinder.scarlet' + groupId 'com.tinder' version version artifactId project.getName() artifact sourcesJar diff --git a/scarlet-websocket-okhttp/build.gradle b/scarlet-websocket-okhttp/build.gradle index 0b5940ed..af62581d 100644 --- a/scarlet-websocket-okhttp/build.gradle +++ b/scarlet-websocket-okhttp/build.gradle @@ -47,7 +47,7 @@ artifacts { publishing { publications { mavenJava(MavenPublication) { - groupId 'com.tinder.scarlet' + groupId 'com.tinder' version version artifactId project.getName() artifact sourcesJar diff --git a/scarlet/build.gradle b/scarlet/build.gradle index f8895ec9..fc05b06c 100644 --- a/scarlet/build.gradle +++ b/scarlet/build.gradle @@ -53,7 +53,7 @@ artifacts { publishing { publications { mavenJava(MavenPublication) { - groupId 'com.tinder.scarlet' + groupId 'com.tinder' version version artifactId project.getName() artifact sourcesJar diff --git a/state-machine/build.gradle b/state-machine/build.gradle index a48f0bb1..f82245db 100644 --- a/state-machine/build.gradle +++ b/state-machine/build.gradle @@ -23,7 +23,7 @@ artifacts { publishing { publications { mavenJava(MavenPublication) { - groupId 'com.tinder.scarlet' + groupId 'com.tinder' version version artifactId project.getName() artifact sourcesJar From 5feec00afe9ebb82d140c152325e6e794e2af387 Mon Sep 17 00:00:00 2001 From: zhxnlai Date: Tue, 19 Jun 2018 20:10:57 +0200 Subject: [PATCH 04/17] Support Jitpack --- build.gradle | 3 ++- gradle.properties | 2 +- jitpack.yml | 4 ++++ publish-jitpack.sh | 28 ++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 jitpack.yml create mode 100755 publish-jitpack.sh diff --git a/build.gradle b/build.gradle index 55115d54..c3bd162e 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,8 @@ ktlint { allprojects { apply plugin: 'org.kordamp.gradle.stats' apply plugin: "com.jfrog.artifactory" - group = 'com.tinder.scarlet' + // group = 'com.tinder.scarlet' TODO use Bintray + group = 'com.github.tinder' repositories { mavenCentral() diff --git a/gradle.properties b/gradle.properties index de55ab65..a482420b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=0.1.0 +version=0.1.1 diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 00000000..7ce70da2 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,4 @@ +jdk: + - oraclejdk8 +install: + - ./publish-jitpack.sh diff --git a/publish-jitpack.sh b/publish-jitpack.sh new file mode 100755 index 00000000..4b7dad21 --- /dev/null +++ b/publish-jitpack.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +./gradlew clean + +./gradlew scarlet-core:build scarlet-core:publishToMavenLocal + +./gradlew scarlet-core-internal:build scarlet-core-internal:publishToMavenLocal + +./gradlew state-machine:build state-machine:publishToMavenLocal + +./gradlew scarlet:build scarlet:publishToMavenLocal + +./gradlew scarlet-test-utils:build scarlet-test-utils:publishToMavenLocal + +./gradlew scarlet-message-adapter-builtin:build scarlet-message-adapter-builtin:publishToMavenLocal + +./gradlew scarlet-message-adapter-protobuf:build scarlet-message-adapter-protobuf:publishToMavenLocal + +./gradlew scarlet-stream-adapter-builtin:build scarlet-stream-adapter-builtin:publishToMavenLocal + +./gradlew scarlet-stream-adapter-rxjava2:build scarlet-stream-adapter-rxjava2:publishToMavenLocal + +./gradlew scarlet-websocket-okhttp:build scarlet-websocket-okhttp:publishToMavenLocal + +./gradlew scarlet-websocket-mockwebserver:build scarlet-websocket-mockwebserver:publishToMavenLocal + +./gradlew scarlet-lifecycle-android:assemble scarlet-lifecycle-android:generatePomFileForAarPublication +./gradlew scarlet-lifecycle-android:publishToMavenLocal From 89886842accfbe0fb0e365d4f4c56ce06a4d7cda Mon Sep 17 00:00:00 2001 From: zhxnlai Date: Tue, 19 Jun 2018 20:28:54 +0200 Subject: [PATCH 05/17] Publish all packages --- publish-jitpack.sh | 6 ++++++ publish.sh | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/publish-jitpack.sh b/publish-jitpack.sh index 4b7dad21..54e6920c 100755 --- a/publish-jitpack.sh +++ b/publish-jitpack.sh @@ -16,10 +16,16 @@ ./gradlew scarlet-message-adapter-protobuf:build scarlet-message-adapter-protobuf:publishToMavenLocal +./gradlew scarlet-message-adapter-moshi:build scarlet-message-adapter-moshi:publishToMavenLocal + +./gradlew scarlet-message-adapter-gson:build scarlet-message-adapter-gson:publishToMavenLocal + ./gradlew scarlet-stream-adapter-builtin:build scarlet-stream-adapter-builtin:publishToMavenLocal ./gradlew scarlet-stream-adapter-rxjava2:build scarlet-stream-adapter-rxjava2:publishToMavenLocal +./gradlew scarlet-stream-adapter-rxjava:build scarlet-stream-adapter-rxjava:publishToMavenLocal + ./gradlew scarlet-websocket-okhttp:build scarlet-websocket-okhttp:publishToMavenLocal ./gradlew scarlet-websocket-mockwebserver:build scarlet-websocket-mockwebserver:publishToMavenLocal diff --git a/publish.sh b/publish.sh index da301066..8a715bf3 100755 --- a/publish.sh +++ b/publish.sh @@ -17,10 +17,16 @@ ./gradlew scarlet-message-adapter-builtin:build scarlet-message-adapter-builtin:artifactoryPublish +./gradlew scarlet-message-adapter-gson:build scarlet-message-adapter-gson:artifactoryPublish + +./gradlew scarlet-message-adapter-moshi:build scarlet-message-adapter-moshi:artifactoryPublish + ./gradlew scarlet-message-adapter-protobuf:build scarlet-message-adapter-protobuf:artifactoryPublish ./gradlew scarlet-stream-adapter-builtin:build scarlet-stream-adapter-builtin:artifactoryPublish +./gradlew scarlet-stream-adapter-rxjava:build scarlet-stream-adapter-rxjava:artifactoryPublish + ./gradlew scarlet-stream-adapter-rxjava2:build scarlet-stream-adapter-rxjava2:artifactoryPublish ./gradlew scarlet-websocket-okhttp:build scarlet-websocket-okhttp:artifactoryPublish From 8f5c1fac03aa33659d5e0ae953c9efd230d721a8 Mon Sep 17 00:00:00 2001 From: zhxnlai Date: Tue, 19 Jun 2018 21:16:45 +0200 Subject: [PATCH 06/17] Update README --- README.md | 110 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index eed5c113..2a6d53f3 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ Scarlet === [![CircleCI](https://circleci.com/gh/Tinder/Scarlet.svg?style=svg)](https://circleci.com/gh/Tinder/Scarlet) +[![Release](https://jitpack.io/v/tinder/scarlet.svg)](https://jitpack.io/#tinder/scarlet) A Retrofit inspired WebSocket client for Kotlin, Java, and Android. -This README is still **WIP**. Please see the [tutorial][tutorial] for more information. - Tutorial --- - [Taming WebSocket with Scarlet][tutorial] @@ -13,28 +12,25 @@ Tutorial Usage --- -In this example, we are reading the realtime Bitcoin price from [Gdax WebSocket Feed][gdax-websocket-feed]. +In this example, we read the realtime Bitcoin price from [Gdax WebSocket Feed][gdax-websocket-feed]. For more information, please check out the [demo app][demo-app]. -Declare a WebSocket client using an interface. +Declare a WebSocket client using an interface: ~~~ kotlin interface GdaxService { + @Receive + fun observeOnConnectionOpenedEvent(): Flowable> @Send fun sendSubscribe(subscribe: Subscribe) @Receive fun observeTicker(): Flowable - @Receive - fun observeOnConnectionOpenedEvent(): Flowable> } -val gdaxService = scarlet.create() ~~~ -Use Scarlet to create an implementation. +Use Scarlet to create an implementation: ~~~ kotlin -val okHttpClient = OkHttpClient.Builder().build() - val scarletInstance = Scarlet.Builder() .webSocketFactory(okHttpClient.newWebSocketFactory("wss://ws-feed.gdax.com")) .addMessageAdapterFactory(MoshiMessageAdapter.Factory()) @@ -44,7 +40,9 @@ val scarletInstance = Scarlet.Builder() val gdaxService = scarletInstance.create() ~~~ -Send a `Subscribe` message upon connection open so that the server will start streaming tickers, which contain the latest price. +Send a `Subscribe` message upon connection open and the server will start streaming tickers which contain the latest price. + + ~~~ kotlin val BITCOIN_TICKER_SUBSCRIBE_MESSAGE = Subscribe( productIds = listOf("BTC-USD"), @@ -55,64 +53,72 @@ gdaxService.observeOnConnectionOpenedEvent() .subscribe({ gdaxService.sendSubscribe(BITCOIN_TICKER_SUBSCRIBE_MESSAGE) }) -~~~ -Start observing realtime tickers. -~~~ kotlin gdaxService.observeTicker() .subscribe({ ticker -> Log.d("Bitcoin price is ${ticker.price} at ${ticker.time}") }) ~~~ -### Built-in Plugins -`WebSocket.Factory` -- `OkHttpClient` -- `MockHttpServer` - -`MessageAdapter.Factory` -- moshi -- gson -- protobuf - -`StreamAdapter.Factory` -- RxJava2 -- RxJava1 - -`Lifecycle` -- AndroidLifecycle - -`BackoffStrategy` -- Linear -- Exponential -- ExponentialWithJitter +### Android +Scarlet is driven by a [StateMachine](https://github.com/Tinder/StateMachine). -### Android -TODO: -- `AndroidLifecycle` + - -### State Machine -Scarlet is driven by a [StateMachine](https://github.com/Tinder/StateMachine). -![State Diagram](./example/scarlet-state-machine.png) +TODO Download -------- -**TODO: make the jar public** +While we are working on Bintray support, Scarlet is available via [JitPack](jitpack). -Download [the latest JAR][latest-jar] or grab via Maven: +##### Maven: ```xml + + jitpack.io + https://jitpack.io + - com.tinder.scarlet - scarlet - 0.1.0 + com.github.tinder.scarlet + scarlet + 0.1.2 ``` -or Gradle: + +##### Gradle: ```groovy -implementation 'com.tinder.scarlet:scarlet:0.1.0' +repositories { + // ... + maven { url "https://jitpack.io" } +} + +implementation 'com.github.tinder.scarlet:scarlet:0.1.2' ``` +### Roadmap +`WebSocket.Factory` +- [x] `OkHttpClient` +- [x] `MockHttpServer` + +`MessageAdapter.Factory` +- [x] `moshi` +- [x] `gson` +- [x] `protobuf` +- [ ] `jackson` +- [ ] `simple-xml` + +`StreamAdapter.Factory` +- [x] `RxJava2` +- [x] `RxJava1` +- [ ] `Kotlin Coroutine` + +`Lifecycle` +- [x] `AndroidLifecycle` + +`BackoffStrategy` +- [x] `Linear` +- [x] `Exponential` +- [x] `ExponentialWithJitter` + Copyright --- ~~~ @@ -144,8 +150,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [gdax-websocket-feed]: https://docs.gdax.com/#websocket-feed [latest-jar]: https://tinder.jfrog.io/tinder/webapp/#/artifacts/browse/tree/General/libs-release-local/com/tinder/scarlet/scarlet - [demo-app]: https://github.com/Tinder/Scarlet/tree/master/demo/src/main/java/com/tinder/app + [demo-app]: /demo/src/main/java/com/tinder/app [tutorial]: https://tech.gotinder.com/taming-websocket-with-scarlet/ [slides]: https://speakerdeck.com/zhxnlai/taming-websocket-with-scarlet - [kotliners]: - https://www.conferenceforkotliners.com/ + [kotliners]:https://www.conferenceforkotliners.com/ + [jitpack]: https://jitpack.io/ From 62a0631f6cc7c1abb07a9408befa041ec7ac9845 Mon Sep 17 00:00:00 2001 From: zhxnlai Date: Tue, 19 Jun 2018 21:19:55 +0200 Subject: [PATCH 07/17] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2a6d53f3..7c9d83e6 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ repositories { implementation 'com.github.tinder.scarlet:scarlet:0.1.2' ``` -### Roadmap +### Plug-in Roadmap `WebSocket.Factory` - [x] `OkHttpClient` - [x] `MockHttpServer` From e9c6e67a144eaa347950eecf869a6c94135a8fed Mon Sep 17 00:00:00 2001 From: Aaron Weaver Date: Fri, 22 Jun 2018 01:45:36 -0700 Subject: [PATCH 08/17] Adding coroutines adapter and factory + tests --- scarlet-stream-adapter-coroutines/.gitignore | 1 + .../build.gradle | 76 +++++++++ .../CoroutinesStreamAdapterFactory.kt | 19 +++ .../coroutines/ReceiveChannelStreamAdapter.kt | 13 ++ .../coroutines/ReceiveChannelTest.kt | 155 ++++++++++++++++++ 5 files changed, 264 insertions(+) create mode 100644 scarlet-stream-adapter-coroutines/.gitignore create mode 100644 scarlet-stream-adapter-coroutines/build.gradle create mode 100644 scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/CoroutinesStreamAdapterFactory.kt create mode 100644 scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelStreamAdapter.kt create mode 100644 scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt diff --git a/scarlet-stream-adapter-coroutines/.gitignore b/scarlet-stream-adapter-coroutines/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/scarlet-stream-adapter-coroutines/.gitignore @@ -0,0 +1 @@ +/build diff --git a/scarlet-stream-adapter-coroutines/build.gradle b/scarlet-stream-adapter-coroutines/build.gradle new file mode 100644 index 00000000..c96f46f3 --- /dev/null +++ b/scarlet-stream-adapter-coroutines/build.gradle @@ -0,0 +1,76 @@ +apply plugin: 'kotlin' +apply plugin: 'java-library' +apply plugin: 'org.jetbrains.dokka' +apply plugin: 'maven-publish' + +dependencies { + api rootProject.ext.kotlinCoroutines + api rootProject.ext.kotlinCoroutinesRxInterop + + implementation project(':scarlet-core') + implementation rootProject.ext.kotlinStdlib + + testImplementation project(':scarlet') + testImplementation project(':scarlet-websocket-mockwebserver') + testImplementation project(':scarlet-test-utils') + testImplementation rootProject.ext.junit + testImplementation rootProject.ext.mockito + testImplementation rootProject.ext.kotlinReflect + testImplementation rootProject.ext.assertJ +} + +kotlin { experimental { coroutines 'enable' } } + +dokka { + outputFormat = 'javadoc' + outputDirectory = "$buildDir/javadoc" +} + +task sourcesJar(type: Jar, dependsOn: classes) { + classifier = 'sources' + from sourceSets.main.allSource +} + +task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { + outputFormat = 'javadoc' + outputDirectory = javadoc.destinationDir +} + +task javadocJar(type: Jar, dependsOn: dokkaJavadoc) { + classifier = 'javadoc' + from javadoc.destinationDir +} + +artifacts { + archives sourcesJar, javadocJar +} + +publishing { + publications { + mavenJava(MavenPublication) { + groupId 'com.tinder' + version version + artifactId project.getName() + artifact sourcesJar + artifact javadocJar + from components.java + } + } +} + +artifactory { + contextUrl = 'https://tinder.jfrog.io/tinder' + publish { + repository { + repoKey = 'libs-release-local' + username = System.getenv("ARTIFACTORY_USER") + password = System.getenv("ARTIFACTORY_PASSWORD") + maven = true + } + defaults { + publications('mavenJava') + publishArtifacts = true + publishPom = true + } + } +} diff --git a/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/CoroutinesStreamAdapterFactory.kt b/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/CoroutinesStreamAdapterFactory.kt new file mode 100644 index 00000000..1fa69314 --- /dev/null +++ b/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/CoroutinesStreamAdapterFactory.kt @@ -0,0 +1,19 @@ +package com.tinder.streamadapter.coroutines + +import com.tinder.scarlet.StreamAdapter +import com.tinder.scarlet.utils.getRawType +import kotlinx.coroutines.experimental.channels.ReceiveChannel +import java.lang.reflect.Type + +/** + * A [stream adapter factory][StreamAdapter.Factory] that uses ReceiveChannel. + */ +class CoroutinesStreamAdapterFactory : StreamAdapter.Factory { + + override fun create(type: Type): StreamAdapter { + return when (type.getRawType()) { + ReceiveChannel::class.java -> ReceiveChannelStreamAdapter() + else -> throw IllegalArgumentException() + } + } +} \ No newline at end of file diff --git a/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelStreamAdapter.kt b/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelStreamAdapter.kt new file mode 100644 index 00000000..31313665 --- /dev/null +++ b/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelStreamAdapter.kt @@ -0,0 +1,13 @@ +package com.tinder.streamadapter.coroutines + +import com.tinder.scarlet.Stream +import com.tinder.scarlet.StreamAdapter +import kotlinx.coroutines.experimental.channels.ReceiveChannel +import kotlinx.coroutines.experimental.reactive.openSubscription + +class ReceiveChannelStreamAdapter : StreamAdapter> { + + override fun adapt(stream: Stream): ReceiveChannel { + return stream.openSubscription() + } +} \ No newline at end of file diff --git a/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt new file mode 100644 index 00000000..6bcd498f --- /dev/null +++ b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt @@ -0,0 +1,155 @@ +package com.tinder.scarlet.streamadapter.coroutines + +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.* +import com.tinder.scarlet.websocket.mockwebserver.newWebSocketFactory +import com.tinder.scarlet.websocket.okhttp.newWebSocketFactory +import com.tinder.scarlet.ws.Receive +import com.tinder.scarlet.ws.Send +import com.tinder.streamadapter.coroutines.CoroutinesStreamAdapterFactory +import kotlinx.coroutines.experimental.* +import kotlinx.coroutines.experimental.channels.* +import kotlinx.coroutines.experimental.reactive.publish +import kotlinx.coroutines.experimental.selects.select +import kotlinx.coroutines.experimental.test.withTestContext +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 + +class ReceiveChannelTest { + + @get:Rule + private val mockWebServer = MockWebServer() + private val serverUrlString by lazy { mockWebServer.url("/").toString() } + + private val serverLifecycleRegistry = LifecycleRegistry() + private lateinit var server: Service + private lateinit var serverEventObserver: TestStreamObserver + + private val clientLifecycleRegistry = LifecycleRegistry() + private lateinit var client: Service + private lateinit var clientEventObserver: TestStreamObserver + + @Test + fun send_givenConnectionIsEstablished_shouldBeReceivedByTheServer() { + runBlocking { + // Given + givenConnectionIsEstablished() + val textMessage1 = "Hello" + val textMessage2 = "Hi" + val bytesMessage1 = "Yo".toByteArray() + val bytesMessage2 = "Sup".toByteArray() + val testTextSubscriber = server.observeText() + val testBytesSubscriber = server.observeBytes() + + // When + client.sendText(textMessage1) + val isSendTextSuccessful = client.sendTextAndConfirm(textMessage2) + client.sendBytes(bytesMessage1) + val isSendBytesSuccessful = client.sendBytesAndConfirm(bytesMessage2) + + // Then + assertThat(isSendTextSuccessful).isTrue() + assertThat(isSendBytesSuccessful).isTrue() + serverEventObserver.awaitValues( + any>(), + any().containingText(textMessage1), + any().containingText(textMessage2), + any().containingBytes(bytesMessage1), + any().containingBytes(bytesMessage2) + ) + + withTestContext { + runBlocking(this) { + assertThat(testTextSubscriber.receiveOrNull()).isEqualTo(textMessage1) + assertThat(testTextSubscriber.receiveOrNull()).isEqualTo(textMessage2) + } + } + + var count = 0 + withTestContext { + runBlocking(this) { + assertThat(testBytesSubscriber.receiveOrNull()).isNotNull() + assertThat(testBytesSubscriber.receiveOrNull()).isNotNull() + } + } + } + } + + private fun givenConnectionIsEstablished() { + createClientAndServer() + serverLifecycleRegistry.onNext(Lifecycle.State.Started) + clientLifecycleRegistry.onNext(Lifecycle.State.Started) + blockUntilConnectionIsEstablish() + } + + private fun createClientAndServer() { + server = createServer() + serverEventObserver = server.observeEvents().test() + client = createClient() + clientEventObserver = client.observeEvents().test() + } + + private fun createServer(): Service { + val webSocketFactory = mockWebServer.newWebSocketFactory() + val scarlet = Scarlet.Builder() + .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() + val webSocketFactory = okHttpClient.newWebSocketFactory(serverUrlString) + val scarlet = Scarlet.Builder() + .webSocketFactory(webSocketFactory) + .lifecycle(clientLifecycleRegistry) + .addStreamAdapterFactory(CoroutinesStreamAdapterFactory()) + .build() + return scarlet.create() + } + + private fun blockUntilConnectionIsEstablish() { + clientEventObserver.awaitValues( + any>() + ) + serverEventObserver.awaitValues( + any>() + ) + } + + private interface Service { + @Receive + fun observeEvents(): Stream + + @Receive + fun observeText(): ReceiveChannel + + @Receive + fun observeBytes(): ReceiveChannel + + @Send + fun sendText(message: String) + + @Send + fun sendTextAndConfirm(message: String): Boolean + + @Send + fun sendBytes(message: ByteArray) + + @Send + fun sendBytesAndConfirm(message: ByteArray): Boolean + } +} \ No newline at end of file From bc91b169b6523ac6a384b283c791c99527164bb7 Mon Sep 17 00:00:00 2001 From: Aaron Weaver Date: Fri, 22 Jun 2018 01:55:18 -0700 Subject: [PATCH 09/17] Removing unnecessary gitignore file --- scarlet-stream-adapter-coroutines/.gitignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 scarlet-stream-adapter-coroutines/.gitignore diff --git a/scarlet-stream-adapter-coroutines/.gitignore b/scarlet-stream-adapter-coroutines/.gitignore deleted file mode 100644 index 796b96d1..00000000 --- a/scarlet-stream-adapter-coroutines/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build From 6a790d919ffe00c403ce8c3c70fa5cf11d29aa9b Mon Sep 17 00:00:00 2001 From: zhxnlai Date: Fri, 22 Jun 2018 15:31:18 -0700 Subject: [PATCH 10/17] Update header copyright --- demo/src/main/AndroidManifest.xml | 2 +- .../main/java/com/tinder/app/echo/api/BitmapMessageAdapter.kt | 2 +- demo/src/main/java/com/tinder/app/echo/api/EchoService.kt | 2 +- demo/src/main/java/com/tinder/app/echo/domain/AuthStatus.kt | 2 +- .../java/com/tinder/app/echo/domain/AuthStatusRepository.kt | 2 +- demo/src/main/java/com/tinder/app/echo/domain/ChatMessage.kt | 2 +- .../java/com/tinder/app/echo/domain/ChatMessageRepository.kt | 2 +- .../main/java/com/tinder/app/echo/domain/LoggedInLifecycle.kt | 2 +- .../main/java/com/tinder/app/echo/inject/EchoBotComponent.kt | 2 +- demo/src/main/java/com/tinder/app/echo/inject/EchoBotScope.kt | 2 +- .../main/java/com/tinder/app/echo/presenter/EchoBotPresenter.kt | 2 +- demo/src/main/java/com/tinder/app/echo/target/EchoBotTarget.kt | 2 +- demo/src/main/java/com/tinder/app/echo/view/EchoBotFragment.kt | 2 +- demo/src/main/java/com/tinder/app/gdax/api/GdaxService.kt | 2 +- demo/src/main/java/com/tinder/app/gdax/api/MoshiAdapters.kt | 2 +- demo/src/main/java/com/tinder/app/gdax/api/model/ProductId.kt | 2 +- demo/src/main/java/com/tinder/app/gdax/api/model/Subscribe.kt | 2 +- demo/src/main/java/com/tinder/app/gdax/api/model/Ticker.kt | 2 +- demo/src/main/java/com/tinder/app/gdax/domain/Product.kt | 2 +- demo/src/main/java/com/tinder/app/gdax/domain/Transaction.kt | 2 +- .../src/main/java/com/tinder/app/gdax/domain/TransactionBook.kt | 2 +- .../java/com/tinder/app/gdax/domain/TransactionRepository.kt | 2 +- demo/src/main/java/com/tinder/app/gdax/inject/GdaxComponent.kt | 2 +- demo/src/main/java/com/tinder/app/gdax/inject/GdaxScope.kt | 2 +- .../main/java/com/tinder/app/gdax/presenter/GdaxPresenter.kt | 2 +- demo/src/main/java/com/tinder/app/gdax/target/GdaxTarget.kt | 2 +- demo/src/main/java/com/tinder/app/gdax/view/GdaxFragment.kt | 2 +- .../src/main/java/com/tinder/app/root/ScarletDemoApplication.kt | 2 +- .../java/com/tinder/app/root/inject/ApplicationComponent.kt | 2 +- demo/src/main/java/com/tinder/app/root/inject/CommonModule.kt | 2 +- demo/src/main/java/com/tinder/app/root/inject/StethoModule.kt | 2 +- demo/src/main/java/com/tinder/app/root/view/DemoActivity.kt | 2 +- demo/src/main/res/drawable/ic_launcher_background.xml | 2 +- demo/src/main/res/layout/activity_demo.xml | 2 +- demo/src/main/res/layout/fragment_echo_bot.xml | 2 +- demo/src/main/res/layout/fragment_gdax.xml | 2 +- demo/src/main/res/layout/view_event_log.xml | 2 +- demo/src/main/res/mipmap-anydpi-v26/ic_launcher.xml | 2 +- demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml | 2 +- demo/src/main/res/values/colors.xml | 2 +- demo/src/main/res/values/dimens.xml | 2 +- demo/src/main/res/values/strings.xml | 2 +- demo/src/main/res/values/styles.xml | 2 +- .../main/java/com/tinder/scarlet/utils/EmptyStreamObserver.kt | 2 +- .../src/main/java/com/tinder/scarlet/utils/FlowableStream.kt | 2 +- .../src/main/java/com/tinder/scarlet/utils/FlowableUtils.kt | 2 +- .../test/java/com/tinder/scarlet/utils/FlowableStreamTest.kt | 2 +- .../src/main/java/com/tinder/scarlet/Deserialization.kt | 2 +- scarlet-core/src/main/java/com/tinder/scarlet/Lifecycle.kt | 2 +- scarlet-core/src/main/java/com/tinder/scarlet/Message.kt | 2 +- scarlet-core/src/main/java/com/tinder/scarlet/MessageAdapter.kt | 2 +- scarlet-core/src/main/java/com/tinder/scarlet/ShutdownReason.kt | 2 +- scarlet-core/src/main/java/com/tinder/scarlet/Stream.kt | 2 +- scarlet-core/src/main/java/com/tinder/scarlet/StreamAdapter.kt | 2 +- scarlet-core/src/main/java/com/tinder/scarlet/WebSocket.kt | 2 +- .../src/main/java/com/tinder/scarlet/utils/TypeUtils.kt | 2 +- scarlet-core/src/main/java/com/tinder/scarlet/utils/Utils.java | 2 +- .../src/test/java/com/tinder/scarlet/utils/TypeUtilsTest.kt | 2 +- scarlet-lifecycle-android/src/main/AndroidManifest.xml | 2 +- .../com/tinder/scarlet/lifecycle/android/AndroidLifecycle.kt | 2 +- .../scarlet/lifecycle/android/ApplicationResumedLifecycle.kt | 2 +- .../tinder/scarlet/lifecycle/android/ConnectivityOnLifecycle.kt | 2 +- .../scarlet/lifecycle/android/LifecycleOwnerResumedLifecycle.kt | 2 +- .../messageadapter/builtin/BuiltInMessageAdapterFactory.kt | 2 +- .../scarlet/messageadapter/builtin/ByteArrayMessageAdapter.kt | 2 +- .../tinder/scarlet/messageadapter/builtin/TextMessageAdapter.kt | 2 +- .../messageadapter/builtin/BuiltInMessageAdapterFactoryTest.kt | 2 +- .../messageadapter/builtin/ByteArrayMessageAdapterTest.kt | 2 +- .../scarlet/messageadapter/builtin/TextMessageAdapterTest.kt | 2 +- .../tinder/scarlet/messageadapter/gson/GsonMessageAdapter.kt | 2 +- .../scarlet/messageadapter/gson/GsonMessageAdapterTest.kt | 2 +- .../tinder/scarlet/messageadapter/moshi/MoshiMessageAdapter.kt | 2 +- .../scarlet/messageadapter/moshi/MoshiMessageAdapterTest.kt | 2 +- .../scarlet/messageadapter/protobuf/ProtobufMessageAdapter.kt | 2 +- .../com/tinder/scarlet/messageadapter/protobuf/PhoneProtos.java | 2 +- .../messageadapter/protobuf/ProtobufMessageAdapterTest.kt | 2 +- .../streamadapter/builtin/BuiltInStreamAdapterFactory.kt | 2 +- .../scarlet/streamadapter/builtin/IdentityStreamAdapter.kt | 2 +- .../streamadapter/builtin/BuiltInStreamAdapterFactoryTest.kt | 2 +- .../scarlet/streamadapter/builtin/IdentityStreamAdapterTest.kt | 2 +- .../scarlet/streamadapter/rxjava/ObservableStreamAdapter.kt | 2 +- .../scarlet/streamadapter/rxjava/RxJavaStreamAdapterFactory.kt | 2 +- .../com/tinder/scarlet/streamadapter/rxjava/ObservableTest.kt | 2 +- .../scarlet/streamadapter/rxjava2/FlowableStreamAdapter.kt | 2 +- .../scarlet/streamadapter/rxjava2/ObservableStreamAdapter.kt | 2 +- .../streamadapter/rxjava2/RxJava2StreamAdapterFactory.kt | 2 +- .../com/tinder/scarlet/streamadapter/rxjava2/FlowableTest.kt | 2 +- .../com/tinder/scarlet/streamadapter/rxjava2/ObservableTest.kt | 2 +- .../java/com/tinder/scarlet/testutils/TestStreamObserver.kt | 2 +- .../src/main/java/com/tinder/scarlet/testutils/TestUtils.kt | 2 +- .../src/main/java/com/tinder/scarlet/testutils/ValueAssert.kt | 2 +- .../MockWebServerOkHttpWebSocketConnectionEstablisher.kt | 2 +- .../scarlet/websocket/mockwebserver/MockWebServerUtils.kt | 2 +- .../com/tinder/scarlet/websocket/okhttp/OkHttpClientUtils.kt | 2 +- .../okhttp/OkHttpClientWebSocketConnectionEstablisher.kt | 2 +- .../java/com/tinder/scarlet/websocket/okhttp/OkHttpWebSocket.kt | 2 +- .../scarlet/websocket/okhttp/OkHttpWebSocketEventObserver.kt | 2 +- .../tinder/scarlet/websocket/okhttp/OkHttpWebSocketHolder.kt | 2 +- .../tinder/scarlet/websocket/okhttp/request/RequestFactory.kt | 2 +- .../scarlet/websocket/okhttp/request/StaticUrlRequestFactory.kt | 2 +- .../websocket/okhttp/OkHttpWebSocketEventObserverTest.kt | 2 +- .../scarlet/websocket/okhttp/OkHttpWebSocketHolderTest.kt | 2 +- .../scarlet/websocket/okhttp/OkHttpWebSocketIntegrationTest.kt | 2 +- .../com/tinder/scarlet/websocket/okhttp/OkHttpWebSocketTest.kt | 2 +- .../websocket/okhttp/request/StaticUrlRequestFactoryTest.kt | 2 +- scarlet/src/main/java/com/tinder/scarlet/Event.kt | 2 +- scarlet/src/main/java/com/tinder/scarlet/Scarlet.kt | 2 +- scarlet/src/main/java/com/tinder/scarlet/Session.kt | 2 +- scarlet/src/main/java/com/tinder/scarlet/State.kt | 2 +- scarlet/src/main/java/com/tinder/scarlet/internal/Service.kt | 2 +- .../java/com/tinder/scarlet/internal/connection/Connection.kt | 2 +- .../internal/connection/subscriber/LifecycleStateSubscriber.kt | 2 +- .../internal/connection/subscriber/RetryTimerSubscriber.kt | 2 +- .../internal/connection/subscriber/WebSocketEventSubscriber.kt | 2 +- .../com/tinder/scarlet/internal/servicemethod/EventMapper.kt | 2 +- .../scarlet/internal/servicemethod/MessageAdapterResolver.kt | 2 +- .../com/tinder/scarlet/internal/servicemethod/ServiceMethod.kt | 2 +- .../scarlet/internal/servicemethod/ServiceMethodExecutor.kt | 2 +- .../scarlet/internal/servicemethod/StreamAdapterResolver.kt | 2 +- .../java/com/tinder/scarlet/internal/utils/RuntimePlatform.kt | 2 +- .../main/java/com/tinder/scarlet/lifecycle/DefaultLifecycle.kt | 2 +- .../main/java/com/tinder/scarlet/lifecycle/FlowableLifecycle.kt | 2 +- .../main/java/com/tinder/scarlet/lifecycle/LifecycleRegistry.kt | 2 +- .../java/com/tinder/scarlet/lifecycle/LifecycleStateUtils.kt | 2 +- .../src/main/java/com/tinder/scarlet/retry/BackoffStrategy.kt | 2 +- .../java/com/tinder/scarlet/retry/ExponentialBackoffStrategy.kt | 2 +- .../scarlet/retry/ExponentialWithJitterBackoffStrategy.kt | 2 +- .../main/java/com/tinder/scarlet/retry/LinearBackoffStrategy.kt | 2 +- scarlet/src/main/java/com/tinder/scarlet/ws/Receive.java | 2 +- scarlet/src/main/java/com/tinder/scarlet/ws/Send.java | 2 +- scarlet/src/test/java/com/tinder/scarlet/ScarletTest.kt | 2 +- .../test/java/com/tinder/scarlet/internal/ServiceFactoryTest.kt | 2 +- .../src/test/java/com/tinder/scarlet/internal/ServiceTest.kt | 2 +- .../tinder/scarlet/internal/connection/ConnectionFactoryTest.kt | 2 +- .../scarlet/internal/connection/ConnectionStateManagerTest.kt | 2 +- .../com/tinder/scarlet/internal/connection/ConnectionTest.kt | 2 +- .../scarlet/internal/connection/LifecycleStateSubscriberTest.kt | 2 +- .../scarlet/internal/connection/RetryTimerSubscriberTest.kt | 2 +- .../scarlet/internal/connection/WebSocketEventSubscriberTest.kt | 2 +- .../scarlet/internal/servicemethod/EventMapperFactoryTest.kt | 2 +- .../tinder/scarlet/internal/servicemethod/EventMapperTest.kt | 2 +- .../internal/servicemethod/MessageAdapterResolverTest.kt | 2 +- .../internal/servicemethod/ReceiveServiceMethodFactoryTest.kt | 2 +- .../scarlet/internal/servicemethod/ReceiveServiceMethodTest.kt | 2 +- .../internal/servicemethod/SendServiceMethodFactoryTest.kt | 2 +- .../scarlet/internal/servicemethod/SendServiceMethodTest.kt | 2 +- .../internal/servicemethod/ServiceMethodExecutorFactoryTest.kt | 2 +- .../scarlet/internal/servicemethod/ServiceMethodExecutorTest.kt | 2 +- .../scarlet/internal/servicemethod/StreamAdapterResolverTest.kt | 2 +- .../java/com/tinder/scarlet/lifecycle/DefaultLifecycleTest.kt | 2 +- .../java/com/tinder/scarlet/lifecycle/FlowableLifecycleTest.kt | 2 +- .../scarlet/lifecycle/LifecycleRegistryBackpressureTest.kt | 2 +- .../java/com/tinder/scarlet/lifecycle/LifecycleRegistryTest.kt | 2 +- .../com/tinder/scarlet/retry/ExponentialBackoffStrategyTest.kt | 2 +- .../retry/ExponentialBackoffWithJitterBackoffStrategyTest.kt | 2 +- .../java/com/tinder/scarlet/retry/LinearBackoffStrategyTest.kt | 2 +- scarlet/src/test/java/com/tinder/scarlet/utils/ClassUtils.kt | 2 +- .../src/main/java/com/tinder/statemachine/StateMachine.kt | 2 +- .../src/test/java/com/tinder/statemachine/StateMachineTest.kt | 2 +- 159 files changed, 159 insertions(+), 159 deletions(-) diff --git a/demo/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml index ce97b0d2..b6cadabd 100755 --- a/demo/src/main/AndroidManifest.xml +++ b/demo/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ diff --git a/demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml index 4b776554..176e2843 100755 --- a/demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +++ b/demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -1,6 +1,6 @@ diff --git a/demo/src/main/res/values/colors.xml b/demo/src/main/res/values/colors.xml index 496c74c6..eab0c52a 100755 --- a/demo/src/main/res/values/colors.xml +++ b/demo/src/main/res/values/colors.xml @@ -1,6 +1,6 @@ diff --git a/demo/src/main/res/values/dimens.xml b/demo/src/main/res/values/dimens.xml index a92b8340..3e761681 100644 --- a/demo/src/main/res/values/dimens.xml +++ b/demo/src/main/res/values/dimens.xml @@ -1,6 +1,6 @@ diff --git a/demo/src/main/res/values/strings.xml b/demo/src/main/res/values/strings.xml index ebd1197e..8e09dfe4 100755 --- a/demo/src/main/res/values/strings.xml +++ b/demo/src/main/res/values/strings.xml @@ -1,5 +1,5 @@ diff --git a/demo/src/main/res/values/styles.xml b/demo/src/main/res/values/styles.xml index 796cf1ae..34343ba1 100755 --- a/demo/src/main/res/values/styles.xml +++ b/demo/src/main/res/values/styles.xml @@ -1,5 +1,5 @@ diff --git a/scarlet-core-internal/src/main/java/com/tinder/scarlet/utils/EmptyStreamObserver.kt b/scarlet-core-internal/src/main/java/com/tinder/scarlet/utils/EmptyStreamObserver.kt index 7a4dfb58..6127a1ae 100644 --- a/scarlet-core-internal/src/main/java/com/tinder/scarlet/utils/EmptyStreamObserver.kt +++ b/scarlet-core-internal/src/main/java/com/tinder/scarlet/utils/EmptyStreamObserver.kt @@ -1,5 +1,5 @@ /* - * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + * © 2018 Match Group, LLC. */ package com.tinder.scarlet.utils diff --git a/scarlet-core-internal/src/main/java/com/tinder/scarlet/utils/FlowableStream.kt b/scarlet-core-internal/src/main/java/com/tinder/scarlet/utils/FlowableStream.kt index 52e227c0..1cc810c2 100644 --- a/scarlet-core-internal/src/main/java/com/tinder/scarlet/utils/FlowableStream.kt +++ b/scarlet-core-internal/src/main/java/com/tinder/scarlet/utils/FlowableStream.kt @@ -1,5 +1,5 @@ /* - * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + * © 2018 Match Group, LLC. */ package com.tinder.scarlet.utils diff --git a/scarlet-core-internal/src/main/java/com/tinder/scarlet/utils/FlowableUtils.kt b/scarlet-core-internal/src/main/java/com/tinder/scarlet/utils/FlowableUtils.kt index f9c735bd..c36de72c 100644 --- a/scarlet-core-internal/src/main/java/com/tinder/scarlet/utils/FlowableUtils.kt +++ b/scarlet-core-internal/src/main/java/com/tinder/scarlet/utils/FlowableUtils.kt @@ -1,5 +1,5 @@ /* - * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + * © 2018 Match Group, LLC. */ @file:JvmName("FlowableUtils") diff --git a/scarlet-core-internal/src/test/java/com/tinder/scarlet/utils/FlowableStreamTest.kt b/scarlet-core-internal/src/test/java/com/tinder/scarlet/utils/FlowableStreamTest.kt index 7f4e2b71..a31d0e05 100644 --- a/scarlet-core-internal/src/test/java/com/tinder/scarlet/utils/FlowableStreamTest.kt +++ b/scarlet-core-internal/src/test/java/com/tinder/scarlet/utils/FlowableStreamTest.kt @@ -1,5 +1,5 @@ /* - * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + * © 2018 Match Group, LLC. */ package com.tinder.scarlet.utils diff --git a/scarlet-core/src/main/java/com/tinder/scarlet/Deserialization.kt b/scarlet-core/src/main/java/com/tinder/scarlet/Deserialization.kt index 23e7c480..421d2717 100644 --- a/scarlet-core/src/main/java/com/tinder/scarlet/Deserialization.kt +++ b/scarlet-core/src/main/java/com/tinder/scarlet/Deserialization.kt @@ -1,5 +1,5 @@ /* - * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + * © 2018 Match Group, LLC. */ package com.tinder.scarlet diff --git a/scarlet-core/src/main/java/com/tinder/scarlet/Lifecycle.kt b/scarlet-core/src/main/java/com/tinder/scarlet/Lifecycle.kt index c0952d95..23fc04f6 100644 --- a/scarlet-core/src/main/java/com/tinder/scarlet/Lifecycle.kt +++ b/scarlet-core/src/main/java/com/tinder/scarlet/Lifecycle.kt @@ -1,5 +1,5 @@ /* - * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + * © 2018 Match Group, LLC. */ package com.tinder.scarlet diff --git a/scarlet-core/src/main/java/com/tinder/scarlet/Message.kt b/scarlet-core/src/main/java/com/tinder/scarlet/Message.kt index aa751d0e..2fe20369 100644 --- a/scarlet-core/src/main/java/com/tinder/scarlet/Message.kt +++ b/scarlet-core/src/main/java/com/tinder/scarlet/Message.kt @@ -1,5 +1,5 @@ /* - * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + * © 2018 Match Group, LLC. */ package com.tinder.scarlet diff --git a/scarlet-core/src/main/java/com/tinder/scarlet/MessageAdapter.kt b/scarlet-core/src/main/java/com/tinder/scarlet/MessageAdapter.kt index 9fe7dab4..5a72ce1a 100644 --- a/scarlet-core/src/main/java/com/tinder/scarlet/MessageAdapter.kt +++ b/scarlet-core/src/main/java/com/tinder/scarlet/MessageAdapter.kt @@ -1,5 +1,5 @@ /* - * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + * © 2018 Match Group, LLC. */ package com.tinder.scarlet diff --git a/scarlet-core/src/main/java/com/tinder/scarlet/ShutdownReason.kt b/scarlet-core/src/main/java/com/tinder/scarlet/ShutdownReason.kt index 7f8f89f5..3434ac21 100644 --- a/scarlet-core/src/main/java/com/tinder/scarlet/ShutdownReason.kt +++ b/scarlet-core/src/main/java/com/tinder/scarlet/ShutdownReason.kt @@ -1,5 +1,5 @@ /* - * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + * © 2018 Match Group, LLC. */ package com.tinder.scarlet diff --git a/scarlet-core/src/main/java/com/tinder/scarlet/Stream.kt b/scarlet-core/src/main/java/com/tinder/scarlet/Stream.kt index ea206e1d..347dd75f 100644 --- a/scarlet-core/src/main/java/com/tinder/scarlet/Stream.kt +++ b/scarlet-core/src/main/java/com/tinder/scarlet/Stream.kt @@ -1,5 +1,5 @@ /* - * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + * © 2018 Match Group, LLC. */ package com.tinder.scarlet diff --git a/scarlet-core/src/main/java/com/tinder/scarlet/StreamAdapter.kt b/scarlet-core/src/main/java/com/tinder/scarlet/StreamAdapter.kt index ca128731..8a1947fe 100644 --- a/scarlet-core/src/main/java/com/tinder/scarlet/StreamAdapter.kt +++ b/scarlet-core/src/main/java/com/tinder/scarlet/StreamAdapter.kt @@ -1,5 +1,5 @@ /* - * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + * © 2018 Match Group, LLC. */ package com.tinder.scarlet diff --git a/scarlet-core/src/main/java/com/tinder/scarlet/WebSocket.kt b/scarlet-core/src/main/java/com/tinder/scarlet/WebSocket.kt index 40103adb..9449def1 100644 --- a/scarlet-core/src/main/java/com/tinder/scarlet/WebSocket.kt +++ b/scarlet-core/src/main/java/com/tinder/scarlet/WebSocket.kt @@ -1,5 +1,5 @@ /* - * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + * © 2018 Match Group, LLC. */ package com.tinder.scarlet diff --git a/scarlet-core/src/main/java/com/tinder/scarlet/utils/TypeUtils.kt b/scarlet-core/src/main/java/com/tinder/scarlet/utils/TypeUtils.kt index e302d2ed..1c130124 100644 --- a/scarlet-core/src/main/java/com/tinder/scarlet/utils/TypeUtils.kt +++ b/scarlet-core/src/main/java/com/tinder/scarlet/utils/TypeUtils.kt @@ -1,5 +1,5 @@ /* - * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + * © 2018 Match Group, LLC. */ @file:JvmName("TypeUtils") diff --git a/scarlet-core/src/main/java/com/tinder/scarlet/utils/Utils.java b/scarlet-core/src/main/java/com/tinder/scarlet/utils/Utils.java index cdf74d50..2073db34 100644 --- a/scarlet-core/src/main/java/com/tinder/scarlet/utils/Utils.java +++ b/scarlet-core/src/main/java/com/tinder/scarlet/utils/Utils.java @@ -1,5 +1,5 @@ /* - * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + * © 2018 Match Group, LLC. */ /* diff --git a/scarlet-core/src/test/java/com/tinder/scarlet/utils/TypeUtilsTest.kt b/scarlet-core/src/test/java/com/tinder/scarlet/utils/TypeUtilsTest.kt index 7c987af4..718ed28c 100644 --- a/scarlet-core/src/test/java/com/tinder/scarlet/utils/TypeUtilsTest.kt +++ b/scarlet-core/src/test/java/com/tinder/scarlet/utils/TypeUtilsTest.kt @@ -1,5 +1,5 @@ /* - * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + * © 2018 Match Group, LLC. */ package com.tinder.scarlet.utils diff --git a/scarlet-lifecycle-android/src/main/AndroidManifest.xml b/scarlet-lifecycle-android/src/main/AndroidManifest.xml index 4e2a5928..a9871764 100755 --- a/scarlet-lifecycle-android/src/main/AndroidManifest.xml +++ b/scarlet-lifecycle-android/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ Date: Fri, 22 Jun 2018 23:53:54 -0700 Subject: [PATCH 11/17] Commiting dependency changes + removing redundant test code --- dependencies.gradle | 2 ++ .../scarlet/streamadapter/coroutines/ReceiveChannelTest.kt | 3 --- settings.gradle | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 87031947..4baa997c 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -19,6 +19,8 @@ ext { rxAndroid = 'io.reactivex.rxjava2:rxandroid:2.0.1' rxKotlin = 'io.reactivex.rxjava2:rxkotlin:2.1.0' rxJava1 = 'io.reactivex:rxjava:1.3.4' + kotlinCoroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.3" + kotlinCoroutinesRxInterop = "org.jetbrains.kotlinx:kotlinx-coroutines-reactive:0.23.3" stetho = 'com.facebook.stetho:stetho:1.5.0' stethoOkHttp = 'com.facebook.stetho:stetho-okhttp3:1.5.0' diff --git a/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt index 6bcd498f..4c9bad33 100644 --- a/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt +++ b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt @@ -13,8 +13,6 @@ import com.tinder.scarlet.ws.Send import com.tinder.streamadapter.coroutines.CoroutinesStreamAdapterFactory import kotlinx.coroutines.experimental.* import kotlinx.coroutines.experimental.channels.* -import kotlinx.coroutines.experimental.reactive.publish -import kotlinx.coroutines.experimental.selects.select import kotlinx.coroutines.experimental.test.withTestContext import okhttp3.OkHttpClient import okhttp3.mockwebserver.MockWebServer @@ -73,7 +71,6 @@ class ReceiveChannelTest { } } - var count = 0 withTestContext { runBlocking(this) { assertThat(testBytesSubscriber.receiveOrNull()).isNotNull() diff --git a/settings.gradle b/settings.gradle index 083d08d2..a2d468d9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,5 +12,6 @@ include ':scarlet-message-adapter-protobuf' include ':scarlet-message-adapter-gson' include ':scarlet-stream-adapter-rxjava' include ':scarlet-stream-adapter-rxjava2' +include ':scarlet-stream-adapter-coroutines' include ':scarlet-lifecycle-android' include ':demo' From b32f4e3392fb459edb71c56965c70c8488d0215d Mon Sep 17 00:00:00 2001 From: Aaron Weaver Date: Sat, 23 Jun 2018 00:54:48 -0700 Subject: [PATCH 12/17] Refactoring tests --- .../coroutines/ReceiveChannelTest.kt | 86 +++++++++---------- 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt index 4c9bad33..0115028d 100644 --- a/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt +++ b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt @@ -1,9 +1,6 @@ package com.tinder.scarlet.streamadapter.coroutines -import com.tinder.scarlet.Lifecycle -import com.tinder.scarlet.Scarlet -import com.tinder.scarlet.Stream -import com.tinder.scarlet.WebSocket +import com.tinder.scarlet.* import com.tinder.scarlet.lifecycle.LifecycleRegistry import com.tinder.scarlet.testutils.* import com.tinder.scarlet.websocket.mockwebserver.newWebSocketFactory @@ -13,7 +10,8 @@ import com.tinder.scarlet.ws.Send import com.tinder.streamadapter.coroutines.CoroutinesStreamAdapterFactory import kotlinx.coroutines.experimental.* import kotlinx.coroutines.experimental.channels.* -import kotlinx.coroutines.experimental.test.withTestContext +import kotlinx.coroutines.experimental.reactive.asPublisher +import kotlinx.coroutines.experimental.selects.select import okhttp3.OkHttpClient import okhttp3.mockwebserver.MockWebServer import org.assertj.core.api.Assertions.assertThat @@ -37,46 +35,46 @@ class ReceiveChannelTest { @Test fun send_givenConnectionIsEstablished_shouldBeReceivedByTheServer() { + // Given + givenConnectionIsEstablished() + val textMessage1 = "Hello" + val textMessage2 = "Hi" + val bytesMessage1 = "Yo".toByteArray() + val bytesMessage2 = "Sup".toByteArray() + val testTextSubscriber = server.observeText() + val testBytesSubscriber = server.observeBytes() + + // When + client.sendText(textMessage1) + val isSendTextSuccessful = client.sendTextAndConfirm(textMessage2) + client.sendBytes(bytesMessage1) + val isSendBytesSuccessful = client.sendBytesAndConfirm(bytesMessage2) + + // Then + assertThat(isSendTextSuccessful).isTrue() + assertThat(isSendBytesSuccessful).isTrue() + serverEventObserver.awaitValues( + any>(), + any().containingText(textMessage1), + any().containingText(textMessage2), + any().containingBytes(bytesMessage1), + any().containingBytes(bytesMessage2) + ) + runBlocking { - // Given - givenConnectionIsEstablished() - val textMessage1 = "Hello" - val textMessage2 = "Hi" - val bytesMessage1 = "Yo".toByteArray() - val bytesMessage2 = "Sup".toByteArray() - val testTextSubscriber = server.observeText() - val testBytesSubscriber = server.observeBytes() - - // When - client.sendText(textMessage1) - val isSendTextSuccessful = client.sendTextAndConfirm(textMessage2) - client.sendBytes(bytesMessage1) - val isSendBytesSuccessful = client.sendBytesAndConfirm(bytesMessage2) - - // Then - assertThat(isSendTextSuccessful).isTrue() - assertThat(isSendBytesSuccessful).isTrue() - serverEventObserver.awaitValues( - any>(), - any().containingText(textMessage1), - any().containingText(textMessage2), - any().containingBytes(bytesMessage1), - any().containingBytes(bytesMessage2) - ) - - withTestContext { - runBlocking(this) { - assertThat(testTextSubscriber.receiveOrNull()).isEqualTo(textMessage1) - assertThat(testTextSubscriber.receiveOrNull()).isEqualTo(textMessage2) - } - } - - withTestContext { - runBlocking(this) { - assertThat(testBytesSubscriber.receiveOrNull()).isNotNull() - assertThat(testBytesSubscriber.receiveOrNull()).isNotNull() - } - } + assertThat(testTextSubscriber.receiveOrNull()).isEqualTo(textMessage1) + assertThat(testTextSubscriber.receiveOrNull()).isEqualTo(textMessage2) + val textTimeoutResult = withTimeoutOrNull(10, TimeUnit.MILLISECONDS, { + testTextSubscriber.receiveOrNull() + }) + assertThat(textTimeoutResult).isNull() + + assertThat(testBytesSubscriber.receiveOrNull()).isEqualTo(bytesMessage1) + assertThat(testBytesSubscriber.receiveOrNull()).isEqualTo(bytesMessage2) + val byteTimeoutResult = withTimeoutOrNull(10, TimeUnit.MILLISECONDS, { + testBytesSubscriber.receiveOrNull() + }) + assertThat(byteTimeoutResult).isNull() } } From 36d9017921e3932118519c4e08e17d40e70d4b9b Mon Sep 17 00:00:00 2001 From: Aaron Weaver Date: Sat, 23 Jun 2018 01:19:49 -0700 Subject: [PATCH 13/17] Removing unnecessary timeout additions in tests --- .../streamadapter/coroutines/ReceiveChannelTest.kt | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt index 0115028d..b4094ba1 100644 --- a/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt +++ b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt @@ -53,6 +53,7 @@ class ReceiveChannelTest { // Then assertThat(isSendTextSuccessful).isTrue() assertThat(isSendBytesSuccessful).isTrue() + serverEventObserver.awaitValues( any>(), any().containingText(textMessage1), @@ -64,17 +65,9 @@ class ReceiveChannelTest { runBlocking { assertThat(testTextSubscriber.receiveOrNull()).isEqualTo(textMessage1) assertThat(testTextSubscriber.receiveOrNull()).isEqualTo(textMessage2) - val textTimeoutResult = withTimeoutOrNull(10, TimeUnit.MILLISECONDS, { - testTextSubscriber.receiveOrNull() - }) - assertThat(textTimeoutResult).isNull() assertThat(testBytesSubscriber.receiveOrNull()).isEqualTo(bytesMessage1) assertThat(testBytesSubscriber.receiveOrNull()).isEqualTo(bytesMessage2) - val byteTimeoutResult = withTimeoutOrNull(10, TimeUnit.MILLISECONDS, { - testBytesSubscriber.receiveOrNull() - }) - assertThat(byteTimeoutResult).isNull() } } From e80624c2aa2e83e0451db7276992e58811567572 Mon Sep 17 00:00:00 2001 From: Aaron Weaver Date: Sat, 23 Jun 2018 01:27:29 -0700 Subject: [PATCH 14/17] Running ktlint and performing more cleanup --- .../coroutines/ReceiveChannelStreamAdapter.kt | 4 +--- .../coroutines/ReceiveChannelTest.kt | 17 +++++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelStreamAdapter.kt b/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelStreamAdapter.kt index 31313665..786f89b1 100644 --- a/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelStreamAdapter.kt +++ b/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelStreamAdapter.kt @@ -7,7 +7,5 @@ import kotlinx.coroutines.experimental.reactive.openSubscription class ReceiveChannelStreamAdapter : StreamAdapter> { - override fun adapt(stream: Stream): ReceiveChannel { - return stream.openSubscription() - } + override fun adapt(stream: Stream) = stream.openSubscription() } \ No newline at end of file diff --git a/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt index b4094ba1..a4a9d84b 100644 --- a/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt +++ b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt @@ -1,17 +1,22 @@ package com.tinder.scarlet.streamadapter.coroutines -import com.tinder.scarlet.* +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.* +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.websocket.mockwebserver.newWebSocketFactory import com.tinder.scarlet.websocket.okhttp.newWebSocketFactory import com.tinder.scarlet.ws.Receive import com.tinder.scarlet.ws.Send import com.tinder.streamadapter.coroutines.CoroutinesStreamAdapterFactory -import kotlinx.coroutines.experimental.* -import kotlinx.coroutines.experimental.channels.* -import kotlinx.coroutines.experimental.reactive.asPublisher -import kotlinx.coroutines.experimental.selects.select +import kotlinx.coroutines.experimental.runBlocking +import kotlinx.coroutines.experimental.channels.ReceiveChannel import okhttp3.OkHttpClient import okhttp3.mockwebserver.MockWebServer import org.assertj.core.api.Assertions.assertThat From 86bfdd769003290442bfd4155f75dd9017b80e64 Mon Sep 17 00:00:00 2001 From: Aaron Weaver Date: Sat, 23 Jun 2018 01:28:48 -0700 Subject: [PATCH 15/17] Changing test channel variable names to accurately reflect type --- .../streamadapter/coroutines/ReceiveChannelTest.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt index a4a9d84b..bf74362c 100644 --- a/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt +++ b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt @@ -46,8 +46,8 @@ class ReceiveChannelTest { val textMessage2 = "Hi" val bytesMessage1 = "Yo".toByteArray() val bytesMessage2 = "Sup".toByteArray() - val testTextSubscriber = server.observeText() - val testBytesSubscriber = server.observeBytes() + val testTextChannel = server.observeText() + val testBytesChannel = server.observeBytes() // When client.sendText(textMessage1) @@ -68,11 +68,11 @@ class ReceiveChannelTest { ) runBlocking { - assertThat(testTextSubscriber.receiveOrNull()).isEqualTo(textMessage1) - assertThat(testTextSubscriber.receiveOrNull()).isEqualTo(textMessage2) + assertThat(testTextChannel.receiveOrNull()).isEqualTo(textMessage1) + assertThat(testTextChannel.receiveOrNull()).isEqualTo(textMessage2) - assertThat(testBytesSubscriber.receiveOrNull()).isEqualTo(bytesMessage1) - assertThat(testBytesSubscriber.receiveOrNull()).isEqualTo(bytesMessage2) + assertThat(testBytesChannel.receiveOrNull()).isEqualTo(bytesMessage1) + assertThat(testBytesChannel.receiveOrNull()).isEqualTo(bytesMessage2) } } From 5f9fc5cd98f974602df456f550626171135df20c Mon Sep 17 00:00:00 2001 From: Aaron Weaver Date: Mon, 25 Jun 2018 19:09:33 -0700 Subject: [PATCH 16/17] Adding copyright to file headers + Updating Readme + Fixing dependencies convention --- README.md | 2 +- dependencies.gradle | 4 ++-- .../coroutines/CoroutinesStreamAdapterFactory.kt | 4 ++++ .../streamadapter/coroutines/ReceiveChannelStreamAdapter.kt | 4 ++++ .../scarlet/streamadapter/coroutines/ReceiveChannelTest.kt | 4 ++++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7c9d83e6..603c3db3 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ implementation 'com.github.tinder.scarlet:scarlet:0.1.2' `StreamAdapter.Factory` - [x] `RxJava2` - [x] `RxJava1` -- [ ] `Kotlin Coroutine` +- [x] `Kotlin Coroutine` `Lifecycle` - [x] `AndroidLifecycle` diff --git a/dependencies.gradle b/dependencies.gradle index 4baa997c..5f757027 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -19,8 +19,8 @@ ext { rxAndroid = 'io.reactivex.rxjava2:rxandroid:2.0.1' rxKotlin = 'io.reactivex.rxjava2:rxkotlin:2.1.0' rxJava1 = 'io.reactivex:rxjava:1.3.4' - kotlinCoroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.3" - kotlinCoroutinesRxInterop = "org.jetbrains.kotlinx:kotlinx-coroutines-reactive:0.23.3" + kotlinCoroutines = 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.3' + kotlinCoroutinesRxInterop = 'org.jetbrains.kotlinx:kotlinx-coroutines-reactive:0.23.3' stetho = 'com.facebook.stetho:stetho:1.5.0' stethoOkHttp = 'com.facebook.stetho:stetho-okhttp3:1.5.0' diff --git a/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/CoroutinesStreamAdapterFactory.kt b/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/CoroutinesStreamAdapterFactory.kt index 1fa69314..85816d4b 100644 --- a/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/CoroutinesStreamAdapterFactory.kt +++ b/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/CoroutinesStreamAdapterFactory.kt @@ -1,3 +1,7 @@ +/* + * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + */ + package com.tinder.streamadapter.coroutines import com.tinder.scarlet.StreamAdapter diff --git a/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelStreamAdapter.kt b/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelStreamAdapter.kt index 786f89b1..0cbe36be 100644 --- a/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelStreamAdapter.kt +++ b/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelStreamAdapter.kt @@ -1,3 +1,7 @@ +/* + * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + */ + package com.tinder.streamadapter.coroutines import com.tinder.scarlet.Stream diff --git a/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt index bf74362c..e39d44aa 100644 --- a/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt +++ b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt @@ -1,3 +1,7 @@ +/* + * © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED + */ + package com.tinder.scarlet.streamadapter.coroutines import com.tinder.scarlet.Lifecycle From b803f8fa11e336cafe07c2629442ee3c4c15adf1 Mon Sep 17 00:00:00 2001 From: zhxnlai Date: Tue, 26 Jun 2018 07:31:37 -0700 Subject: [PATCH 17/17] Prepare release 0.1.3 --- README.md | 2 +- publish-jitpack.sh | 2 ++ publish.sh | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 603c3db3..8d2a5301 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ While we are working on Bintray support, Scarlet is available via [JitPack](jitp com.github.tinder.scarlet scarlet - 0.1.2 + 0.1.3 ``` diff --git a/publish-jitpack.sh b/publish-jitpack.sh index 54e6920c..17d1c71e 100755 --- a/publish-jitpack.sh +++ b/publish-jitpack.sh @@ -26,6 +26,8 @@ ./gradlew scarlet-stream-adapter-rxjava:build scarlet-stream-adapter-rxjava:publishToMavenLocal +./gradlew scarlet-stream-adapter-coroutines:build scarlet-stream-adapter-coroutines:publishToMavenLocal + ./gradlew scarlet-websocket-okhttp:build scarlet-websocket-okhttp:publishToMavenLocal ./gradlew scarlet-websocket-mockwebserver:build scarlet-websocket-mockwebserver:publishToMavenLocal diff --git a/publish.sh b/publish.sh index 8a715bf3..8901706a 100755 --- a/publish.sh +++ b/publish.sh @@ -29,6 +29,8 @@ ./gradlew scarlet-stream-adapter-rxjava2:build scarlet-stream-adapter-rxjava2:artifactoryPublish +./gradlew scarlet-stream-adapter-coroutines:build scarlet-stream-adapter-coroutines:artifactoryPublish + ./gradlew scarlet-websocket-okhttp:build scarlet-websocket-okhttp:artifactoryPublish ./gradlew scarlet-websocket-mockwebserver:build scarlet-websocket-mockwebserver:artifactoryPublish