File tree Expand file tree Collapse file tree
main/kotlin/io/ably/lib/objects
test/kotlin/io/ably/lib/objects/unit Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,11 +33,10 @@ internal fun LiveObjectsAdapter.ensureMessageSizeWithinLimit(objectMessages: Arr
3333}
3434
3535internal fun LiveObjectsAdapter.setChannelSerial (channelName : String , protocolMessage : ProtocolMessage ) {
36- if (protocolMessage.action == ProtocolMessage .Action .`object `) {
37- val channelSerial = protocolMessage.channelSerial
38- if (channelSerial.isNullOrEmpty()) return
39- setChannelSerial(channelName, channelSerial)
40- }
36+ if (protocolMessage.action != ProtocolMessage .Action .`object `) return
37+ val channelSerial = protocolMessage.channelSerial
38+ if (channelSerial.isNullOrEmpty()) return
39+ setChannelSerial(channelName, channelSerial)
4140}
4241
4342internal enum class ProtocolMessageFormat (private val value : String ) {
Original file line number Diff line number Diff line change @@ -18,8 +18,8 @@ internal class ObjectId private constructor(
1818 /* *
1919 * Creates ObjectId instance from hashed object id string.
2020 */
21- fun fromString (objectId : String? ): ObjectId {
22- if (objectId.isNullOrEmpty ()) {
21+ fun fromString (objectId : String ): ObjectId {
22+ if (objectId.isEmpty ()) {
2323 throw objectError(" Invalid object id: $objectId " )
2424 }
2525
@@ -29,8 +29,7 @@ internal class ObjectId private constructor(
2929 throw objectError(" Invalid object id: $objectId " )
3030 }
3131
32- val typeStr = parts[0 ]
33- val rest = parts[1 ]
32+ val (typeStr, rest) = parts
3433
3534 val type = when (typeStr) {
3635 " map" -> ObjectType .Map
Original file line number Diff line number Diff line change @@ -38,7 +38,6 @@ internal class ObjectsPool(
3838
3939 /* *
4040 * @spec RTO3a - Pool storing all live objects by object ID
41- * Note: This is the same as objectsPool property in DefaultLiveObjects.kt
4241 */
4342 private val pool = mutableMapOf<String , BaseLiveObject >()
4443
@@ -88,25 +87,17 @@ internal class ObjectsPool(
8887 * Does not create a new root object, so the reference to the root object remains the same.
8988 */
9089 internal fun resetToInitialPool (emitUpdateEvents : Boolean ) {
91- // Clear the pool first and keep the root object
92- val root = pool[ROOT_OBJECT_ID ]
93- if (root != null ) {
94- pool.clear()
95- set(ROOT_OBJECT_ID , root)
96-
97- // this will only clear the remaining root object and emit update events
98- clearObjectsData(emitUpdateEvents)
99- } else {
100- Log .w(tag, " Root object not found in pool during reset" )
101- }
90+ pool.entries.removeIf { (key, _) -> key != ROOT_OBJECT_ID } // only keep the root object
91+ clearObjectsData(emitUpdateEvents) // clear the root object and emit update events
10292 }
10393
10494
10595 /* *
10696 * Deletes objects from the pool for which object ids are not found in the provided array of ids.
97+ * Spec: RTO5c2
10798 */
10899 internal fun deleteExtraObjectIds (objectIds : MutableSet <String >) {
109- pool.entries.removeIf { (key, _) -> key !in objectIds }
100+ pool.entries.removeIf { (key, _) -> key !in objectIds && key != ROOT_OBJECT_ID } // RTO5c2a - Keep root object
110101 }
111102
112103 /* *
Original file line number Diff line number Diff line change @@ -37,11 +37,7 @@ class ObjectIdTest {
3737 }
3838
3939 @Test
40- fun testNullOrEmptyObjectId () {
41- val exception = assertThrows(AblyException ::class .java) {
42- ObjectId .fromString(null )
43- }
44- assertAblyExceptionError(exception)
40+ fun testEmptyObjectId () {
4541 val exception1 = assertThrows(AblyException ::class .java) {
4642 ObjectId .fromString(" " )
4743 }
You can’t perform that action at this time.
0 commit comments