Skip to content

Commit

Permalink
Add subscription state and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clementetb committed Feb 29, 2024
1 parent ac56828 commit 4b99e78
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Cache notification callback JNI references at startup to ensure that symbols can be resolved in core callbacks. (Issue [#1577](https://github.com/realm/realm-kotlin/issues/1577))
* Using `Realm.asFlow()` could miss an update if a write was started right after opening the Realm. (Issue [#1582](https://github.com/realm/realm-kotlin/issues/1582))
* Snapshot publishing with Github Action. (Issue [#1654](https://github.com/realm/realm-kotlin/issues/1654) [JIRA](https://jira.mongodb.org/browse/RKOTLIN-1018))
* [Sync] `NullPointerException` while waiting for the synchronization of a subscription set if the client was set in `AwaitingMark` state. (Issue [#1671](https://github.com/realm/realm-kotlin/issues/1671) [JIRA](https://jira.mongodb.org/browse/RKOTLIN-1027))

### Compatibility
* File format: Generates Realms with file format v23.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import io.realm.kotlin.internal.interop.ErrorCode
import io.realm.kotlin.internal.interop.realm_auth_provider_e
import io.realm.kotlin.internal.interop.realm_errno_e
import io.realm.kotlin.internal.interop.realm_error_category_e
import io.realm.kotlin.internal.interop.realm_flx_sync_subscription_set_state_e
import io.realm.kotlin.internal.interop.realm_sync_client_metadata_mode_e
import io.realm.kotlin.internal.interop.realm_sync_connection_state_e
import io.realm.kotlin.internal.interop.realm_sync_errno_connection_e
Expand All @@ -33,6 +34,7 @@ import io.realm.kotlin.internal.interop.realm_user_state_e
import io.realm.kotlin.internal.interop.realm_web_socket_errno_e
import io.realm.kotlin.internal.interop.sync.AuthProvider
import io.realm.kotlin.internal.interop.sync.CoreConnectionState
import io.realm.kotlin.internal.interop.sync.CoreSubscriptionSetState
import io.realm.kotlin.internal.interop.sync.CoreSyncSessionState
import io.realm.kotlin.internal.interop.sync.CoreUserState
import io.realm.kotlin.internal.interop.sync.MetadataMode
Expand Down Expand Up @@ -137,6 +139,13 @@ class SyncEnumTests {
}
}

@Test
fun syncSubscriptionSetState() {
checkEnum(realm_flx_sync_subscription_set_state_e::class) { nativeValue ->
CoreSubscriptionSetState.of(nativeValue)
}
}

@Test
fun websocketResultCode() {
checkEnum(realm_sync_socket_callback_result_e::class) { nativeValue ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ expect enum class CoreSubscriptionSetState {
RLM_SYNC_SUBSCRIPTION_BOOTSTRAPPING,
RLM_SYNC_SUBSCRIPTION_COMPLETE,
RLM_SYNC_SUBSCRIPTION_ERROR,
RLM_SYNC_SUBSCRIPTION_SUPERSEDED;
RLM_SYNC_SUBSCRIPTION_SUPERSEDED,
RLM_SYNC_SUBSCRIPTION_AWAITING_MARK;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ actual enum class CoreSubscriptionSetState(override val nativeValue: Int) : Nati
RLM_SYNC_SUBSCRIPTION_BOOTSTRAPPING(realm_flx_sync_subscription_set_state_e.RLM_SYNC_SUBSCRIPTION_BOOTSTRAPPING),
RLM_SYNC_SUBSCRIPTION_COMPLETE(realm_flx_sync_subscription_set_state_e.RLM_SYNC_SUBSCRIPTION_COMPLETE),
RLM_SYNC_SUBSCRIPTION_ERROR(realm_flx_sync_subscription_set_state_e.RLM_SYNC_SUBSCRIPTION_ERROR),
RLM_SYNC_SUBSCRIPTION_SUPERSEDED(realm_flx_sync_subscription_set_state_e.RLM_SYNC_SUBSCRIPTION_SUPERSEDED);
RLM_SYNC_SUBSCRIPTION_SUPERSEDED(realm_flx_sync_subscription_set_state_e.RLM_SYNC_SUBSCRIPTION_SUPERSEDED),
RLM_SYNC_SUBSCRIPTION_AWAITING_MARK(realm_flx_sync_subscription_set_state_e.RLM_SYNC_SUBSCRIPTION_AWAITING_MARK);

companion object {
fun of(state: Int): CoreSubscriptionSetState {
for (value in values()) {
for (value in entries) {
if (value.nativeValue == state) {
return value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ actual enum class CoreSubscriptionSetState(
RLM_SYNC_SUBSCRIPTION_BOOTSTRAPPING(realm_wrapper.RLM_SYNC_SUBSCRIPTION_BOOTSTRAPPING),
RLM_SYNC_SUBSCRIPTION_COMPLETE(realm_wrapper.RLM_SYNC_SUBSCRIPTION_COMPLETE),
RLM_SYNC_SUBSCRIPTION_ERROR(realm_wrapper.RLM_SYNC_SUBSCRIPTION_ERROR),
RLM_SYNC_SUBSCRIPTION_SUPERSEDED(realm_wrapper.RLM_SYNC_SUBSCRIPTION_SUPERSEDED);
RLM_SYNC_SUBSCRIPTION_SUPERSEDED(realm_wrapper.RLM_SYNC_SUBSCRIPTION_SUPERSEDED),
RLM_SYNC_SUBSCRIPTION_AWAITING_MARK(realm_wrapper.RLM_SYNC_SUBSCRIPTION_AWAITING_MARK);

companion object {
fun of(state: realm_flx_sync_subscription_set_state_e): CoreSubscriptionSetState {
for (value in values()) {
for (value in entries) {
if (value.nativeValue == state) {
return value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ internal abstract class BaseSubscriptionSetImpl<T : BaseRealm>(
SubscriptionSetState.ERROR
CoreSubscriptionSetState.RLM_SYNC_SUBSCRIPTION_SUPERSEDED ->
SubscriptionSetState.SUPERCEDED
CoreSubscriptionSetState.RLM_SYNC_SUBSCRIPTION_AWAITING_MARK ->
SubscriptionSetState.AWAITING_MARK
else -> TODO("Unsupported state: $coreState")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,11 @@ public enum class SubscriptionSetState {
* are ignored by the server. Get the latest subscription set by calling
* [SubscriptionSet.refresh].
*/
SUPERCEDED;
SUPERCEDED,

/**
* The last bootstrap message containing the initial state for this subscription set has been received. The
* client is awaiting a mark message to mark this subscription as fully caught up to history.
*/
AWAITING_MARK;
}

0 comments on commit 4b99e78

Please sign in to comment.