Skip to content

Commit 76e2294

Browse files
authored
Do not cancel subscribe calls on set state (#110)
1 parent 965f901 commit 76e2294

File tree

8 files changed

+63
-69
lines changed

8 files changed

+63
-69
lines changed

.pubnub.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: kotlin
2-
version: 7.4.2
2+
version: 7.4.3
33
schema: 1
44
scm: github.com/pubnub/kotlin
55
files:
6-
- build/libs/pubnub-kotlin-7.4.2-all.jar
6+
- build/libs/pubnub-kotlin-7.4.3-all.jar
77
sdks:
88
-
99
type: library
@@ -23,8 +23,8 @@ sdks:
2323
-
2424
distribution-type: library
2525
distribution-repository: maven
26-
package-name: pubnub-kotlin-7.4.2
27-
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/7.4.2/pubnub-kotlin-7.4.2.jar
26+
package-name: pubnub-kotlin-7.4.3
27+
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/7.4.3/pubnub-kotlin-7.4.3.jar
2828
supported-platforms:
2929
supported-operating-systems:
3030
Android:
@@ -121,6 +121,11 @@ sdks:
121121
license-url: https://github.com/stleary/JSON-java/blob/20210307/LICENSE
122122
is-required: Required
123123
changelog:
124+
- date: 2023-04-11
125+
version: v7.4.3
126+
changes:
127+
- type: bug
128+
text: "Do not cancel subscribe call on set state."
124129
- date: 2023-03-07
125130
version: v7.4.2
126131
changes:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v7.4.3
2+
April 11 2023
3+
4+
#### Fixed
5+
- Do not cancel subscribe call on set state.
6+
17
## v7.4.2
28
March 07 2023
39

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ You will need the publish and subscribe keys to authenticate your app. Get your
2020
<dependency>
2121
<groupId>com.pubnub</groupId>
2222
<artifactId>pubnub-kotlin</artifactId>
23-
<version>7.4.2</version>
23+
<version>7.4.3</version>
2424
</dependency>
2525
```
2626

2727
* for Gradle, add the following dependency in your `gradle.build`:
2828
```groovy
29-
implementation 'com.pubnub:pubnub-kotlin:7.4.2'
29+
implementation 'com.pubnub:pubnub-kotlin:7.4.3'
3030
```
3131

3232
2. Configure your keys:

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ SONATYPE_HOST=DEFAULT
2121
SONATYPE_AUTOMATIC_RELEASE=true
2222
GROUP=com.pubnub
2323
POM_ARTIFACT_ID=pubnub-kotlin
24-
VERSION_NAME=7.4.2
24+
VERSION_NAME=7.4.3
2525
POM_PACKAGING=jar
2626

2727
POM_NAME=PubNub Android Chat Components

src/main/kotlin/com/pubnub/api/PubNub.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class PubNub(val configuration: PNConfiguration) {
9595

9696
companion object {
9797
private const val TIMESTAMP_DIVIDER = 1000
98-
private const val SDK_VERSION = "7.4.2"
98+
private const val SDK_VERSION = "7.4.3"
9999
private const val MAX_SEQUENCE = 65535
100100

101101
/**

src/main/kotlin/com/pubnub/api/managers/SubscriptionManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class SubscriptionManager(val pubnub: PubNub, private val subscriptionState: Sta
107107
}
108108

109109
internal fun adaptStateBuilder(stateOperation: StateOperation) {
110-
reconnect(stateOperation)
110+
subscriptionState.handleOperation(stateOperation)
111111
}
112112

113113
internal fun adaptSubscribeBuilder(subscribeOperation: SubscribeOperation) {

src/test/kotlin/com/pubnub/api/legacy/PubNubTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class PubNubTest : BaseTest() {
7171
fun getVersionAndTimeStamp() {
7272
val version = pubnub.version
7373
val timeStamp = pubnub.timestamp()
74-
assertEquals("7.4.2", version)
74+
assertEquals("7.4.3", version)
7575
assertTrue(timeStamp > 0)
7676
}
7777
}

src/test/kotlin/com/pubnub/api/legacy/managers/SubscriptionManagerTest.kt

Lines changed: 42 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching
1414
import com.google.gson.reflect.TypeToken
1515
import com.pubnub.api.CommonUtils.emptyJson
1616
import com.pubnub.api.PubNub
17-
import com.pubnub.api.PubNubException
1817
import com.pubnub.api.PubNubUtil
1918
import com.pubnub.api.callbacks.SubscribeCallback
2019
import com.pubnub.api.enums.PNHeartbeatNotificationOptions
@@ -1400,25 +1399,20 @@ class SubscriptionManagerTest : BaseTest() {
14001399
.atMost(5, TimeUnit.SECONDS)
14011400
.untilAtomic(atomic, Matchers.greaterThan(0))
14021401
}
1403-
14041402
@Test
14051403
fun testSubscribeBuilderWithState() {
1406-
val subscribeHits = AtomicInteger(0)
1407-
val heartbeatHits = AtomicInteger(0)
14081404
val expectedPayload = PubNubUtil.urlDecode(
14091405
"""%7B%22ch1%22%3A%5B%22p1%22%2C%22p2%22%5D%2C%22cg2%22%3A%5B%22p1%22%2C%22p2%22%5D%7D"""
14101406
)
14111407

1412-
val expectedMap = pubnub.mapper.fromJson<HashMap<String, Any>?>(
1413-
expectedPayload,
1414-
object : TypeToken<HashMap<String, Any>?>() {}.type
1408+
val expectedMap = pubnub.mapper.fromJson<HashMap<String, Any>>(
1409+
expectedPayload, object : TypeToken<HashMap<String, Any>?>() {}.type
14151410
)
14161411

14171412
stubFor(
1418-
get(urlPathEqualTo("/v2/subscribe/mySubscribeKey/ch2,ch1/0"))
1419-
.willReturn(
1420-
aResponse().withBody(
1421-
"""
1413+
get(urlPathEqualTo("/v2/subscribe/mySubscribeKey/ch2,ch1/0")).willReturn(
1414+
aResponse().withBody(
1415+
"""
14221416
{
14231417
"t": {
14241418
"t": "14607577960932487",
@@ -1442,77 +1436,66 @@ class SubscriptionManagerTest : BaseTest() {
14421436
}
14431437
]
14441438
}
1445-
""".trimIndent()
1446-
)
1439+
""".trimIndent()
14471440
)
1441+
)
14481442
)
14491443

14501444
stubFor(
1451-
get(urlPathEqualTo("/v2/presence/sub-key/mySubscribeKey/channel/ch2,ch1/heartbeat"))
1452-
.willReturn(emptyJson())
1445+
get(urlPathEqualTo("/v2/presence/sub-key/mySubscribeKey/channel/ch2,ch1/heartbeat")).willReturn(emptyJson())
14531446
)
14541447

14551448
stubFor(
1456-
get(urlPathEqualTo("/v2/presence/sub-key/mySubscribeKey/channel/ch1/uuid/myUUID/data"))
1457-
.willReturn(emptyJson())
1449+
get(urlPathEqualTo("/v2/presence/sub-key/mySubscribeKey/channel/ch1/uuid/myUUID/data")).willReturn(emptyJson())
14581450
)
14591451

14601452
pubnub.configuration.presenceTimeout = 20
14611453
pubnub.configuration.heartbeatNotificationOptions = PNHeartbeatNotificationOptions.ALL
14621454

14631455
pubnub.addListener(object : SubscribeCallback() {
14641456
override fun status(pubnub: PubNub, pnStatus: PNStatus) {
1465-
val heartbeatRequests = findAll(
1466-
getRequestedFor(
1467-
urlMatching(
1468-
"""/v2/presence/sub-key/${pubnub.configuration.subscribeKey}/channel/ch2,ch1/heartbeat.*"""
1469-
)
1470-
)
1471-
)
1472-
val subscribeRequests = findAll(
1473-
getRequestedFor(
1474-
urlMatching(
1475-
"""/v2/subscribe/${pubnub.configuration.subscribeKey}/ch2,ch1/.*"""
1476-
)
1477-
)
1478-
)
1479-
for (request in subscribeRequests) {
1480-
val stateString = PubNubUtil.urlDecode(request.queryParameter("state").firstValue())
1481-
var actualMap: HashMap<String, Any>? = null
1482-
try {
1483-
actualMap = pubnub.mapper.fromJson(
1484-
stateString,
1485-
object : TypeToken<HashMap<String, Any>?>() {}.type
1486-
)
1487-
} catch (e: PubNubException) {
1488-
e.printStackTrace()
1489-
}
1490-
if (actualMap != null && actualMap == expectedMap) {
1491-
subscribeHits.getAndAdd(1)
1492-
}
1493-
}
1494-
for (request in heartbeatRequests) {
1495-
if (!request.queryParams.containsKey("state")) {
1496-
heartbeatHits.getAndAdd(1)
1497-
}
1498-
}
1457+
// do nothing
14991458
}
15001459
})
15011460

15021461
pubnub.subscribe(
1503-
channels = listOf("ch1", "ch2"),
1504-
channelGroups = listOf("cg1", "cg2")
1462+
channels = listOf("ch1", "ch2"), channelGroups = listOf("cg1", "cg2")
15051463
)
15061464

15071465
pubnub.setPresenceState(
1508-
channels = listOf("ch1"),
1509-
channelGroups = listOf("cg2"),
1510-
state = listOf("p1", "p2")
1466+
channels = listOf("ch1"), channelGroups = listOf("cg2"), state = listOf("p1", "p2")
15111467
).async { _, _ -> }
15121468

1513-
Awaitility.await()
1514-
.atMost(5, TimeUnit.SECONDS)
1515-
.until { subscribeHits.get() > 0 && heartbeatHits.get() > 0 }
1469+
Awaitility.await().atMost(5, TimeUnit.SECONDS).until { verifyCalls(expectedMap) }
1470+
}
1471+
1472+
private fun verifyCalls(expectedMap: Map<String, Any>): Boolean {
1473+
val subscribeRequests = findAll(
1474+
getRequestedFor(
1475+
urlMatching(
1476+
"""/v2/subscribe/${pubnub.configuration.subscribeKey}/ch2,ch1/.*"""
1477+
)
1478+
)
1479+
)
1480+
val subCond = subscribeRequests.any {
1481+
val stateString = PubNubUtil.urlDecode(it.queryParameter("state").firstValue())
1482+
val actualMap: HashMap<String, Any> = pubnub.mapper.fromJson(
1483+
stateString, object : TypeToken<HashMap<String, Any>>() {}.type
1484+
)
1485+
actualMap == expectedMap
1486+
}
1487+
val heartbeatRequests = findAll(
1488+
getRequestedFor(
1489+
urlMatching(
1490+
"""/v2/presence/sub-key/${pubnub.configuration.subscribeKey}/channel/ch2,ch1/heartbeat.*"""
1491+
)
1492+
)
1493+
)
1494+
val heartbeatCond = heartbeatRequests.any {
1495+
!it.queryParams.containsKey("state")
1496+
}
1497+
1498+
return subCond && heartbeatCond
15161499
}
15171500

15181501
@Test

0 commit comments

Comments
 (0)