Skip to content

Commit

Permalink
Merge commit 'ce040e7fe635c7dc2afd2942ef092579a7695e20' into ct/sync_…
Browse files Browse the repository at this point in the history
…migration_2
  • Loading branch information
clementetb committed Jun 28, 2024
2 parents fa96c03 + ce040e7 commit e5fa6a5
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 38 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ object Versions {
const val nexusPublishPlugin = "1.1.0" // https://github.com/gradle-nexus/publish-plugin
const val okio = "3.2.0" // https://square.github.io/okio/#releases
const val relinker = "1.4.5" // https://github.com/KeepSafe/ReLinker
const val serialization = "1.7.0" // https://kotlinlang.org/docs/releases.html#release-details
const val serialization = "1.7.1" // https://kotlinlang.org/docs/releases.html#release-details
const val shadowJar = "6.1.0" // https://mvnrepository.com/artifact/com.github.johnrengelman.shadow/com.github.johnrengelman.shadow.gradle.plugin?repo=gradle-plugins
const val snakeYaml = "1.33" // https://github.com/snakeyaml/snakeyaml
val sourceCompatibilityVersion = JavaVersion.VERSION_1_8 // Language level of any Java source code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import io.realm.kotlin.types.annotations.PrimaryKey
import org.mongodb.kbson.ObjectId

class JsonStyleRealmObject : RealmObject {
// Act as partition key to separate individual test runs
var selector: String = "DEFAULT"
@PrimaryKey
@PersistedName("_id")
var id: String = ObjectId().toHexString()
var selector: String = "DEFAULT"
var id: ObjectId = ObjectId()
var value: RealmAny? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import io.realm.kotlin.internal.platform.runBlocking
import io.realm.kotlin.test.common.utils.assertFailsWithMessage
import io.realm.kotlin.test.platform.PlatformUtils
import io.realm.kotlin.types.RealmAny
import org.mongodb.kbson.ObjectId
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
Expand Down Expand Up @@ -527,26 +528,26 @@ class RealmAnyNestedCollectionTests {

@Test
fun query() = runBlocking<Unit> {
var listId: ObjectId? = null
var dictId: ObjectId? = null
var embeddedId: ObjectId? = null
realm.write {
copyToRealm(
listId = copyToRealm(
JsonStyleRealmObject().apply {
id = "LIST"
value = realmAnyListOf(4, 5, 6)
}
)
copyToRealm(
).id
dictId = copyToRealm(
JsonStyleRealmObject().apply {
id = "DICT"
value = realmAnyDictionaryOf(
"key1" to 7,
"key2" to 8,
"key3" to 9,
)
}
)
copyToRealm(
).id
embeddedId = copyToRealm(
JsonStyleRealmObject().apply {
id = "EMBEDDED"
value = realmAnyListOf(
listOf(4, 5, 6),
mapOf(
Expand All @@ -556,35 +557,35 @@ class RealmAnyNestedCollectionTests {
)
)
}
)
).id
}

assertEquals(3, realm.query<JsonStyleRealmObject>().find().size)

// Matching lists
realm.query<JsonStyleRealmObject>("value[0] == 4").find().single().run {
assertEquals("LIST", id)
assertEquals(listId, id)
}
realm.query<JsonStyleRealmObject>("value[*] == 4").find().single().run {
assertEquals("LIST", id)
assertEquals(listId, id)
}
realm.query<JsonStyleRealmObject>("value[*] == {4, 5, 6}").find().single().run {
assertEquals("LIST", id)
assertEquals(listId, id)
}

// Matching dictionaries
realm.query<JsonStyleRealmObject>("value.key1 == 7").find().single().run {
assertEquals("DICT", id)
assertEquals(dictId, id)
}
realm.query<JsonStyleRealmObject>("value['key1'] == 7").find().single().run {
assertEquals("DICT", id)
assertEquals(dictId, id)
}
realm.query<JsonStyleRealmObject>("value[*] == 7").find().single().run {
assertEquals("DICT", id)
assertEquals(dictId, id)
}
assertEquals(0, realm.query<JsonStyleRealmObject>("value.unknown == 3").find().size)
realm.query<JsonStyleRealmObject>("value.@keys == 'key1'").find().single().run {
assertEquals("DICT", id)
assertEquals(dictId, id)
}
assertEquals(0, realm.query<JsonStyleRealmObject>("value.@keys == 'unknown'").find().size)

Expand All @@ -593,19 +594,19 @@ class RealmAnyNestedCollectionTests {

// Matching across all elements and in nested structures
realm.query<JsonStyleRealmObject>("value[*][*] == 4").find().single().run {
assertEquals("EMBEDDED", id)
assertEquals(embeddedId, id)
}
realm.query<JsonStyleRealmObject>("value[*][*] == 7").find().single().run {
assertEquals("EMBEDDED", id)
assertEquals(embeddedId, id)
}
realm.query<JsonStyleRealmObject>("value[*].@keys == 'key1'").find().single().run {
assertEquals("EMBEDDED", id)
assertEquals(embeddedId, id)
}
realm.query<JsonStyleRealmObject>("value[*].key3[0] == 9").find().single().run {
assertEquals("EMBEDDED", id)
assertEquals(embeddedId, id)
}
realm.query<JsonStyleRealmObject>("value[0][*] == {4, 5, 6}").find().single().run {
assertEquals("EMBEDDED", id)
assertEquals(embeddedId, id)
}
// FIXME Core issue https://github.com/realm/realm-core/issues/7393
// realm.query<JsonStyleRealmObject>("value[*][*] == {4, 5, 6}").find().single().run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class RealmAnyNestedCollectionNotificationTest {
val o: JsonStyleRealmObject = realm.write {
copyToRealm(
JsonStyleRealmObject().apply {
id = "SET"
value = realmAnyListOf(realmAnyListOf(1, 2, 3))
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class RealmAnyNestedDictionaryNotificationTest : FlowableTests, DeletableEntityN
val o: JsonStyleRealmObject = realm.write {
copyToRealm(
JsonStyleRealmObject().apply {
id = "DICTIONARY"
value = realmAnyDictionaryOf(
"root" to realmAnyDictionaryOf(
"key1" to 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class RealmAnyNestedListNotificationTest : FlowableTests, DeletableEntityNotific
val o: JsonStyleRealmObject = realm.write {
copyToRealm(
JsonStyleRealmObject().apply {
id = "LIST"
value = realmAnyListOf(realmAnyListOf(1, 2, 3))
}
)
Expand Down Expand Up @@ -281,7 +280,7 @@ class RealmAnyNestedListNotificationTest : FlowableTests, DeletableEntityNotific
val asList = findLatest(parent)!!.value!!.asList()
println(asList.size)
asList.add(
RealmAny.create(JsonStyleRealmObject().apply { id = "CHILD" })
RealmAny.create(JsonStyleRealmObject())
)
}
channel.receiveOrFail(message = "List add").let {
Expand Down
1 change: 1 addition & 0 deletions packages/test-sync/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ kotlin {
implementation("io.ktor:ktor-client-logging:${Versions.ktor}")
implementation("io.ktor:ktor-serialization-kotlinx-json:${Versions.ktor}")
implementation("io.ktor:ktor-client-content-negotiation:${Versions.ktor}")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:${Versions.serialization}")

implementation("com.squareup.okio:okio:${Versions.okio}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,8 @@ class SyncedRealmTests {

// Create object with all types
val selector = ObjectId().toString()
var parentId: ObjectId? = null
var childId: ObjectId? = null

createFlexibleSyncConfig(
user = user1,
Expand All @@ -738,14 +740,13 @@ class SyncedRealmTests {
realm.write {
val child = (
JsonStyleRealmObject().apply {
this.id = "CHILD"
this.selector = selector
}
)
childId = child.id

copyToRealm(
parentId = copyToRealm(
JsonStyleRealmObject().apply {
this.id = "PARENT"
this.selector = selector
value = realmAnyDictionaryOf(
"primitive" to 1,
Expand All @@ -754,7 +755,7 @@ class SyncedRealmTests {
"dictionary" to realmAnyDictionaryOf("dictkey1" to 1, "dictkey2" to "Realm", "dictkey3" to child, "dictkey4" to realmAnyListOf(1, 2, 3))
)
}
)
).id
}
realm.syncSession.uploadAllLocalChangesOrFail()
}
Expand All @@ -766,31 +767,37 @@ class SyncedRealmTests {
}
).let { config ->
Realm.open(config).use { realm ->
println("download changes")
realm.syncSession.downloadAllServerChanges(10.seconds)
val flow = realm.query<JsonStyleRealmObject>("_id = $0", "PARENT").asFlow()
println("downloaded changes")
val flow = realm.query<JsonStyleRealmObject>("_id = $0", parentId).asFlow()
val parent = withTimeout(10.seconds) {
flow.first {
println("get object")
val x = flow.first {
it.list.size >= 1
}.list[0]
println("x")
x
}
println("get parent")
parent.let {
val value = it.value!!.asDictionary()
assertEquals(RealmAny.Companion.create(1), value["primitive"])
value["list"]!!.asList().let {
assertEquals(1, it[0]!!.asInt())
assertEquals("Realm", it[1]!!.asString())
assertEquals("CHILD", it[2]!!.asRealmObject<JsonStyleRealmObject>().id)
assertEquals(childId, it[2]!!.asRealmObject<JsonStyleRealmObject>().id)
it[3]!!.asDictionary().let { dict ->
assertEquals(1, dict["listkey1"]!!.asInt())
assertEquals("Realm", dict["listkey2"]!!.asString())
assertEquals("CHILD", dict["listkey3"]!!.asRealmObject<JsonStyleRealmObject>().id)
assertEquals(childId, dict["listkey3"]!!.asRealmObject<JsonStyleRealmObject>().id)
}
assertEquals("CHILD", it[2]!!.asRealmObject<JsonStyleRealmObject>().id)
assertEquals(childId, it[2]!!.asRealmObject<JsonStyleRealmObject>().id)
}
value["dictionary"]!!.asDictionary().let {
assertEquals(1, it["dictkey1"]!!.asInt())
assertEquals("Realm", it["dictkey2"]!!.asString())
assertEquals("CHILD", it["dictkey3"]!!.asRealmObject<JsonStyleRealmObject>().id)
assertEquals(childId, it["dictkey3"]!!.asRealmObject<JsonStyleRealmObject>().id)
it["dictkey4"]!!.asList().let {
assertEquals(realmAnyListOf(1, 2, 3).asList(), it)
}
Expand Down

0 comments on commit e5fa6a5

Please sign in to comment.