Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more GC tests to reflect current server modifications #143

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- run: chmod +x gradlew
- uses: gradle/gradle-build-action@v2
- name: Setup Docker on macOS
uses: douglascamata/setup-docker-macos-action@fix-python-dep
uses: douglascamata/setup-docker-macos-action@main
- run: |
docker system prune --all --force
docker-compose -f docker/docker-compose-ci.yml up --build -d
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
depends_on:
- yorkie
yorkie:
image: 'yorkieteam/yorkie:0.4.7'
image: 'yorkieteam/yorkie:0.4.8'
container_name: 'yorkie'
command: [
'server',
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
extra_hosts:
- "host.docker.internal:host-gateway"
yorkie:
image: 'yorkieteam/yorkie:0.4.7'
image: 'yorkieteam/yorkie:0.4.8'
container_name: 'yorkie'
command: [
'server',
Expand Down
58 changes: 58 additions & 0 deletions yorkie/src/androidTest/kotlin/dev/yorkie/core/GCTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import dev.yorkie.assertJsonContentEquals
import dev.yorkie.document.Document
import dev.yorkie.document.crdt.CrdtTreeNode
import dev.yorkie.document.json.JsonObject
import dev.yorkie.document.json.JsonText
import dev.yorkie.document.json.JsonTree
import dev.yorkie.document.json.JsonTree.TextNode
Expand Down Expand Up @@ -489,6 +490,63 @@ class GCTest {
assertEquals(3, document.garbageLengthFromClone)
}

@Test
fun test_delete_removed_elements_after_peers_cannot_access() {
runBlocking {
val c1 = createClient()
val c2 = createClient()
val documentKey = UUID.randomUUID().toString().toDocKey()
val d1 = Document(documentKey)
val d2 = Document(documentKey)

c1.activateAsync().await()
c2.activateAsync().await()

c1.attachAsync(d1, isRealTimeSync = false).await()
d1.updateAsync { root, _ ->
root.setNewObject("point").apply {
set("x", 0)
set("y", 0)
}
root.getAs<JsonObject>("point")["x"] = 1
}.await()
assertEquals(1, d1.garbageLength)
c1.syncAsync().await()

c2.attachAsync(d2, isRealTimeSync = false).await()
assertEquals(1, d2.garbageLength)
d2.updateAsync { root, _ ->
root.getAs<JsonObject>("point")["x"] = 2
}.await()
assertEquals(2, d2.garbageLength)

d1.updateAsync { root, _ ->
root.setNewObject("point").apply {
set("x", 3)
set("y", 3)
}
}.await()
assertEquals(4, d1.garbageLength)
c1.syncAsync().await()
assertEquals(4, d1.garbageLength)

c1.syncAsync().await()
assertEquals(4, d1.garbageLength)

c2.syncAsync().await()
assertEquals(4, d1.garbageLength)
c1.syncAsync().await()
assertEquals(5, d1.garbageLength)
c2.syncAsync().await()
assertEquals(5, d1.garbageLength)
c1.syncAsync().await()
assertEquals(0, d1.garbageLength)

c1.deactivateAsync().await()
c2.deactivateAsync().await()
}
}

private fun getNodeLength(root: IndexTreeNode<CrdtTreeNode>): Int {
return root.allChildren.fold(root.allChildren.size) { acc, child ->
acc + getNodeLength(child)
Expand Down
Loading