Skip to content

Commit

Permalink
Add RealtimeSyncOff and refactor interface of SyncMode (#170)
Browse files Browse the repository at this point in the history
* fix TC failures

* update codecov version

* Add RealtimeSyncOff and refactor interface of SyncMode

* fix TC failures

* downgrade codecov

* fix handling Unwatched event
  • Loading branch information
7hong13 authored Apr 15, 2024
1 parent 163fb39 commit 95a2fee
Show file tree
Hide file tree
Showing 13 changed files with 323 additions and 376 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.gson.Gson
import dev.yorkie.core.Client
import dev.yorkie.core.Client.SyncMode.Realtime
import dev.yorkie.core.Client.SyncMode.RealtimePushOnly
import dev.yorkie.core.PresenceInfo
import dev.yorkie.document.Document
import dev.yorkie.document.Document.Event.PresenceChange
Expand Down Expand Up @@ -137,11 +139,11 @@ class EditorViewModel(private val client: Client) : ViewModel(), YorkieEditText.
}

override fun handleHangulCompositionStart() {
client.pause(document)
client.changeSyncMode(document, RealtimePushOnly)
}

override fun handleHangulCompositionEnd() {
client.resume(document)
client.changeSyncMode(document, Realtime)
}

override fun onCleared() {
Expand Down
350 changes: 160 additions & 190 deletions yorkie/src/androidTest/kotlin/dev/yorkie/core/ClientTest.kt

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions yorkie/src/androidTest/kotlin/dev/yorkie/core/DocumentTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.yorkie.core

import androidx.test.ext.junit.runners.AndroidJUnit4
import dev.yorkie.assertJsonContentEquals
import dev.yorkie.core.Client.SyncMode.Manual
import dev.yorkie.document.Document
import dev.yorkie.document.Document.DocumentStatus
import dev.yorkie.document.Document.Event
Expand Down Expand Up @@ -152,11 +153,11 @@ class DocumentTest {
root["key"] = 1
}.await()
c1.activateAsync().await()
c1.attachAsync(d1, isRealTimeSync = false).await()
c1.attachAsync(d1, syncMode = Manual).await()
assertEquals("""{"key":1}""", d1.toJson())

c2.activateAsync().await()
c2.attachAsync(d2, isRealTimeSync = false).await()
c2.attachAsync(d2, syncMode = Manual).await()
assertEquals("""{"key":1}""", d2.toJson())

c1.removeAsync(d1).await()
Expand Down
19 changes: 10 additions & 9 deletions yorkie/src/androidTest/kotlin/dev/yorkie/core/GCTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.yorkie.core

import androidx.test.ext.junit.runners.AndroidJUnit4
import dev.yorkie.assertJsonContentEquals
import dev.yorkie.core.Client.SyncMode.Manual
import dev.yorkie.document.Document
import dev.yorkie.document.crdt.CrdtTreeNode
import dev.yorkie.document.json.JsonObject
Expand Down Expand Up @@ -208,7 +209,7 @@ class GCTest {

@Test
fun test_gc_with_tree_for_multi_client() {
withTwoClientsAndDocuments(realTimeSync = false) { c1, c2, d1, d2, _ ->
withTwoClientsAndDocuments(syncMode = Manual) { c1, c2, d1, d2, _ ->
d1.updateAsync { root, _ ->
root.setNewTree(
"t",
Expand Down Expand Up @@ -273,7 +274,7 @@ class GCTest {

@Test
fun test_gc_with_container_type_for_multi_client() {
withTwoClientsAndDocuments(realTimeSync = false) { c1, c2, d1, d2, _ ->
withTwoClientsAndDocuments(syncMode = Manual) { c1, c2, d1, d2, _ ->
d1.updateAsync { root, _ ->
root["1"] = 1
root.setNewArray("2").apply {
Expand Down Expand Up @@ -327,7 +328,7 @@ class GCTest {

@Test
fun test_gc_with_text_for_multi_client() {
withTwoClientsAndDocuments(realTimeSync = false) { c1, c2, d1, d2, _ ->
withTwoClientsAndDocuments(syncMode = Manual) { c1, c2, d1, d2, _ ->
d1.updateAsync { root, _ ->
root.setNewText("text").edit(0, 0, "Hello World")
root.setNewText("textWithAttr").edit(0, 0, "Hello World")
Expand Down Expand Up @@ -387,7 +388,7 @@ class GCTest {
fun test_gc_with_detached_document() {
withTwoClientsAndDocuments(
detachDocuments = false,
realTimeSync = false,
syncMode = Manual,
) { c1, c2, d1, d2, _ ->
d1.updateAsync { root, _ ->
root["1"] = 1
Expand Down Expand Up @@ -476,7 +477,7 @@ class GCTest {
val document = Document(documentKey)

client.activateAsync().await()
client.attachAsync(document, isRealTimeSync = false).await()
client.attachAsync(document, syncMode = Manual).await()

document.updateAsync { root, _ ->
root["point"] = gson.toJson(Point(0, 0))
Expand Down Expand Up @@ -513,7 +514,7 @@ class GCTest {
c1.activateAsync().await()
c2.activateAsync().await()

c1.attachAsync(d1, isRealTimeSync = false).await()
c1.attachAsync(d1, syncMode = Manual).await()
d1.updateAsync { root, _ ->
root.setNewObject("point").apply {
set("x", 0)
Expand All @@ -524,7 +525,7 @@ class GCTest {
assertEquals(1, d1.garbageLength)
c1.syncAsync().await()

c2.attachAsync(d2, isRealTimeSync = false).await()
c2.attachAsync(d2, syncMode = Manual).await()
assertEquals(1, d2.garbageLength)
d2.updateAsync { root, _ ->
root.getAs<JsonObject>("point")["x"] = 2
Expand Down Expand Up @@ -576,14 +577,14 @@ class GCTest {
c2.activateAsync().await()

// 1. initial state
c1.attachAsync(d1, isRealTimeSync = false).await()
c1.attachAsync(d1, syncMode = Manual).await()
d1.updateAsync { root, _ ->
val point = root.setNewObject("point")
point["x"] = 0
point["y"] = 0
}.await()
c1.syncAsync().await()
c2.attachAsync(d2, isRealTimeSync = false).await()
c2.attachAsync(d2, syncMode = Manual).await()

// 2. client1 updates doc
d1.updateAsync { root, _ ->
Expand Down
Loading

0 comments on commit 95a2fee

Please sign in to comment.