-
Notifications
You must be signed in to change notification settings - Fork 5
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
Sync android-sdk with js-sdk: Implement updates to v0.4.27 #212
Changes from 17 commits
1a279a5
8b92b71
726e57a
44ce553
9af7217
c6ae388
56c97d9
657782f
97322ad
7713dd4
c74ac17
d26d565
0555d69
b1970e3
80df75c
4a58b48
74fe3be
6f98ad6
6966671
a7166d3
698e0ec
6c6e41b
3524c6b
0aaa758
10dea5e
64c55bc
a0abc7a
cbd8272
e1f6de8
f0bd230
d30bbfc
ba2229f
12aa5ef
45f1c71
358c8ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,11 @@ import dev.yorkie.document.json.JsonTreeTest.Companion.rootTree | |
import dev.yorkie.document.json.TreeBuilder.element | ||
import dev.yorkie.document.json.TreeBuilder.text | ||
import dev.yorkie.document.operation.OperationInfo | ||
import dev.yorkie.util.YorkieException | ||
import dev.yorkie.util.YorkieException.Code.* | ||
import java.util.UUID | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFailsWith | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertIs | ||
import kotlin.test.assertNotEquals | ||
|
@@ -890,4 +893,72 @@ class ClientTest { | |
collectJobs.forEach(Job::cancel) | ||
} | ||
} | ||
|
||
@Test | ||
fun test_should_throw_exceptions_attach_and_detach_document() { | ||
runBlocking { | ||
val c1 = createClient() | ||
val key = UUID.randomUUID().toString().toDocKey() | ||
val d1 = Document(key) | ||
|
||
// Test that attaching an already attached document throws an error | ||
val activatedException = assertFailsWith<YorkieException> { | ||
c1.attachAsync(d1).await() | ||
} | ||
assertEquals(ErrClientNotActivated, activatedException.code) | ||
|
||
c1.activateAsync().await() | ||
|
||
c1.attachAsync(d1).await() | ||
|
||
// Test that attaching an already attached document throws an error | ||
val attachException = assertFailsWith<YorkieException> { | ||
c1.attachAsync(d1).await() | ||
} | ||
assertEquals(ErrDocumentNotDetached, attachException.code) | ||
|
||
c1.detachAsync(d1).await() | ||
|
||
// Test that detaching an already detached document throws an error | ||
val detachException = assertFailsWith<YorkieException> { | ||
c1.detachAsync(d1).await() | ||
} | ||
assertEquals(ErrDocumentNotAttached, detachException.code) | ||
|
||
c1.deactivateAsync().await() | ||
d1.close() | ||
c1.close() | ||
} | ||
} | ||
|
||
@Test | ||
fun test_should_handle_local_changes_correctly_when_receiving_snapshot() { | ||
withTwoClientsAndDocuments(syncMode = Manual) { c1, c2, d1, d2, _ -> | ||
d1.updateAsync { root, _ -> | ||
root.setNewCounter("counter", 0) | ||
}.await() | ||
|
||
c1.syncAsync().await() | ||
c2.syncAsync().await() | ||
|
||
// 01. c1 increases the counter for creating snapshot. | ||
repeat(500) { | ||
d1.updateAsync { root, _ -> | ||
root.getAs<JsonCounter>("counter").increase(1) | ||
}.await() | ||
} | ||
c1.syncAsync().await() | ||
|
||
// 02. c2 receives the snapshot and increases the counter simultaneously. | ||
// The tc in js-sdk, it performed the sync before update, but it is not necessary. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we talked in the offline conversation, calling the |
||
// so, it is not implemented in android sdk. | ||
d2.updateAsync { root, _ -> | ||
root.getAs<JsonCounter>("counter").increase(1) | ||
}.await() | ||
|
||
c2.syncAsync().await() | ||
c1.syncAsync().await() | ||
assertEquals(d1.toJson(), d2.toJson()) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I set the RC version because even after the merge this PR, there are still specs to discuss.
yorkie-team/yorkie-js-sdk#865