Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into nh/mixing_sdks
Browse files Browse the repository at this point in the history
  • Loading branch information
nhachicha committed Jul 6, 2024
2 parents 3603177 + 5e41c65 commit 8c5fcc1
Show file tree
Hide file tree
Showing 40 changed files with 667 additions and 623 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
* Minimum R8: 8.0.34.

### Internal
- None.
- Reworked test app initializer framework.


## 2.0.1 (YYYY-MM-DD)
## 2.0.1-SNAPSHOT (YYYY-MM-DD)

### Breaking changes
* None.
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ import io.realm.kotlin.mongodb.User
import io.realm.kotlin.mongodb.internal.AppConfigurationImpl
import io.realm.kotlin.test.mongodb.util.AppAdmin
import io.realm.kotlin.test.mongodb.util.AppAdminImpl
import io.realm.kotlin.test.mongodb.util.AppInitializer
import io.realm.kotlin.test.mongodb.util.AppServicesClient
import io.realm.kotlin.test.mongodb.util.BaasApp
import io.realm.kotlin.test.mongodb.util.Service
import io.realm.kotlin.test.mongodb.util.TestAppInitializer.initializeDefault
import io.realm.kotlin.test.platform.PlatformUtils
import io.realm.kotlin.test.util.TestHelper
import kotlinx.coroutines.CloseableCoroutineDispatcher
Expand Down Expand Up @@ -91,27 +89,23 @@ open class TestApp private constructor(
@OptIn(ExperimentalKBsonSerializerApi::class, ExperimentalCoroutinesApi::class)
constructor(
testId: String?,
appName: String = TEST_APP_PARTITION,
appInitializer: AppInitializer,
dispatcher: CoroutineDispatcher = singleThreadDispatcher("$testId-dispatcher"),
builder: (AppConfiguration.Builder) -> AppConfiguration.Builder = {
it.syncRootDirectory(PlatformUtils.createTempDir("$appName-$testId"))
it.syncRootDirectory(PlatformUtils.createTempDir("${appInitializer.name}-$testId"))
},
debug: Boolean = false,
networkTransport: NetworkTransport? = null,
ejson: EJson = EJson,
initialSetup: suspend AppServicesClient.(app: BaasApp, service: Service) -> Unit = { app: BaasApp, service: Service ->
initializeDefault(app, service)
}
) : this(
dispatcher,
build(
debug = debug,
appName = appName,
appInitializer = appInitializer,
dispatcher = dispatcher,
builder = builder,
networkTransport = networkTransport,
ejson = ejson,
initialSetup = initialSetup
)
)

Expand Down Expand Up @@ -172,20 +166,19 @@ open class TestApp private constructor(
@Suppress("LongParameterList")
fun build(
debug: Boolean,
appName: String,
appInitializer: AppInitializer,
dispatcher: CoroutineDispatcher,
builder: (AppConfiguration.Builder) -> AppConfiguration.Builder,
networkTransport: NetworkTransport?,
ejson: EJson,
initialSetup: suspend AppServicesClient.(app: BaasApp, service: Service) -> Unit
): Pair<App, AppAdmin> {
val appAdmin: AppAdmin = runBlocking(dispatcher) {
AppServicesClient.build(
baseUrl = TEST_SERVER_BASE_URL,
debug = debug,
dispatcher = dispatcher
).run {
val baasApp = getOrCreateApp(appName, initialSetup)
val baasApp = getOrCreateApp(appInitializer)

AppAdminImpl(this, baasApp)
}
Expand Down
Loading

0 comments on commit 8c5fcc1

Please sign in to comment.