Skip to content

Commit 4f71ed8

Browse files
authored
Merge pull request #989 from ably/fix/presence-tests
Fix presence / ignored presence tests
2 parents 0af4d4e + 468ffc1 commit 4f71ed8

File tree

4 files changed

+15
-78
lines changed

4 files changed

+15
-78
lines changed

.github/workflows/integration-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v3
14+
with:
15+
submodules: 'recursive'
1416

1517
- run: ./gradlew :java:testRestSuite
1618

@@ -24,6 +26,8 @@ jobs:
2426
runs-on: ubuntu-latest
2527
steps:
2628
- uses: actions/checkout@v3
29+
with:
30+
submodules: 'recursive'
2731

2832
- run: ./gradlew :java:testRealtimeSuite
2933

lib/src/main/java/io/ably/lib/realtime/ChannelBase.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,7 @@ private static void callCompletionListenerSuccess(CompletionListener listener) {
369369

370370
@Deprecated
371371
public void sync() throws AblyException {
372-
Log.w(TAG, "sync() method is deprecated since protocol 1.2, current protocol " +
373-
Defaults.ABLY_PROTOCOL_VERSION);
372+
Log.w(TAG, "sync() method is intended only for internal testing purpose as per RTP19");
374373
}
375374

376375
private static void callCompletionListenerError(CompletionListener listener, ErrorInfo err) {

lib/src/main/java/io/ably/lib/realtime/Presence.java

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.List;
2828
import java.util.Locale;
2929
import java.util.Map;
30-
import java.util.Set;
3130

3231
/**
3332
* Enables the presence set to be entered and subscribed to, and the historic presence set to be retrieved for a channel.
@@ -903,11 +902,6 @@ private void failQueuedMessages(ErrorInfo reason) {
903902
************************************/
904903

905904
void onAttached(boolean hasPresence) {
906-
/* Interrupt get() call => by unblocking presence.waitForSync()*/
907-
synchronized (presence) {
908-
presence.notifyAll();
909-
}
910-
911905
presence.startSync();
912906
if (!hasPresence) { // RTP19a
913907
endSync();
@@ -919,8 +913,8 @@ void onAttached(boolean hasPresence) {
919913
/**
920914
* Spec: RTP17g
921915
*/
922-
synchronized void enterInternalMembers() {
923-
for (final PresenceMessage item: internalPresence.values()) {
916+
void enterInternalMembers() {
917+
for (final PresenceMessage item: internalPresence.members.values()) {
924918
try {
925919
enterClientWithId(item.id, item.clientId, item.data, new CompletionListener() {
926920
@Override
@@ -1026,7 +1020,7 @@ synchronized Collection<PresenceMessage> get(Param[] params) throws AblyExceptio
10261020
for (Param param: params) {
10271021
switch (param.key) {
10281022
case GET_WAITFORSYNC:
1029-
waitForSync = Boolean.valueOf(param.value);
1023+
waitForSync = Boolean.parseBoolean(param.value);
10301024
break;
10311025
case GET_CLIENTID:
10321026
clientId = param.value;
@@ -1041,8 +1035,7 @@ synchronized Collection<PresenceMessage> get(Param[] params) throws AblyExceptio
10411035
if (waitForSync)
10421036
waitForSync();
10431037

1044-
for (Map.Entry<String, PresenceMessage> entry: members.entrySet()) {
1045-
PresenceMessage member = entry.getValue();
1038+
for (PresenceMessage member: members.values()) {
10461039
if ((clientId == null || member.clientId.equals(clientId)) &&
10471040
(connectionId == null || member.connectionId.equals(connectionId)))
10481041
result.add(member);
@@ -1106,10 +1099,10 @@ synchronized boolean hasNewerItem(String key, PresenceMessage item) {
11061099
return false;
11071100

11081101
try {
1109-
long messageSerial = Long.valueOf(itemComponents[1]);
1110-
long messageIndex = Long.valueOf(itemComponents[2]);
1111-
long existingMessageSerial = Long.valueOf(existingItemComponents[1]);
1112-
long existingMessageIndex = Long.valueOf(existingItemComponents[2]);
1102+
long messageSerial = Long.parseLong(itemComponents[1]);
1103+
long messageIndex = Long.parseLong(itemComponents[2]);
1104+
long existingMessageSerial = Long.parseLong(existingItemComponents[1]);
1105+
long existingMessageIndex = Long.parseLong(existingItemComponents[2]);
11131106

11141107
return existingMessageSerial > messageSerial ||
11151108
(existingMessageSerial == messageSerial && existingMessageIndex >= messageIndex);
@@ -1119,34 +1112,6 @@ synchronized boolean hasNewerItem(String key, PresenceMessage item) {
11191112
}
11201113
}
11211114

1122-
/**
1123-
* Get all members based on the current state (even if sync is in progress)
1124-
* @return
1125-
*/
1126-
synchronized Collection<PresenceMessage> values() {
1127-
try { return values(false); } catch (InterruptedException|AblyException e) { return null; }
1128-
}
1129-
1130-
/**
1131-
* Get all members, optionally waiting if a sync is in progress.
1132-
* @param wait
1133-
* @return
1134-
* @throws InterruptedException
1135-
*/
1136-
synchronized Collection<PresenceMessage> values(boolean wait) throws AblyException, InterruptedException {
1137-
Set<PresenceMessage> result = new HashSet<PresenceMessage>();
1138-
if(wait)
1139-
waitForSync();
1140-
result.addAll(members.values());
1141-
for(Iterator<PresenceMessage> it = result.iterator(); it.hasNext();) {
1142-
PresenceMessage entry = it.next();
1143-
if(entry.action == PresenceMessage.Action.absent) {
1144-
it.remove();
1145-
}
1146-
}
1147-
return result;
1148-
}
1149-
11501115
/**
11511116
* Remove a member.
11521117
* @param item

lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceTest.java

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ public void setUpBefore() throws Exception {
139139
/**
140140
* Attach to channel, enter presence channel and await entered event
141141
*/
142-
@Ignore("FIXME: fix exception")
143142
@Test
144143
public void enter_simple() {
145144
AblyRealtime clientAbly1 = null;
@@ -190,7 +189,6 @@ public void enter_simple() {
190189
/**
191190
* Enter presence channel without prior attach and await entered event
192191
*/
193-
@Ignore("FIXME: fix exception")
194192
@Test
195193
public void enter_before_attach() {
196194
AblyRealtime clientAbly1 = null;
@@ -239,7 +237,6 @@ public void enter_before_attach() {
239237
/**
240238
* Enter presence channel without prior connect and await entered event
241239
*/
242-
@Ignore("FIXME: fix exception")
243240
@Test
244241
public void enter_before_connect() {
245242
AblyRealtime clientAbly1 = null;
@@ -285,7 +282,6 @@ public void enter_before_connect() {
285282
* Enter, then leave, presence channel and await leave event
286283
* Verify that the item is removed from the presence map (RTP2e)
287284
*/
288-
@Ignore("FIXME: fix exception")
289285
@Test
290286
public void enter_leave_simple() {
291287
AblyRealtime clientAbly1 = null;
@@ -345,7 +341,6 @@ public void enter_leave_simple() {
345341
/**
346342
* Enter, then enter again, expecting update event
347343
*/
348-
@Ignore("FIXME: fix exception")
349344
@Test
350345
public void enter_enter_simple() {
351346
AblyRealtime clientAbly1 = null;
@@ -414,7 +409,6 @@ public void enter_enter_simple() {
414409
/**
415410
* Enter, then update, expecting update event
416411
*/
417-
@Ignore("FIXME: fix exception")
418412
@Test
419413
public void enter_update_simple() {
420414
AblyRealtime clientAbly1 = null;
@@ -552,7 +546,6 @@ public void enter_update_null() {
552546
/**
553547
* Update without having first entered, expecting enter event
554548
*/
555-
@Ignore("FIXME: fix exception")
556549
@Test
557550
public void update_noenter() {
558551
AblyRealtime clientAbly1 = null;
@@ -611,7 +604,6 @@ public void update_noenter() {
611604
* Enter, then leave (with no data) and await leave event,
612605
* expecting enter data to be in leave event
613606
*/
614-
@Ignore("FIXME: fix exception")
615607
@Test
616608
public void enter_leave_nodata() {
617609
AblyRealtime clientAbly1 = null;
@@ -667,7 +659,6 @@ public void enter_leave_nodata() {
667659
/**
668660
* Attach to channel, enter presence channel and get presence using realtime get()
669661
*/
670-
@Ignore("FIXME: fix exception")
671662
@Test
672663
public void realtime_get_simple() {
673664
AblyRealtime clientAbly1 = null;
@@ -722,7 +713,6 @@ public void realtime_get_simple() {
722713
/**
723714
* Attach to channel, enter+leave presence channel and get presence with realtime get()
724715
*/
725-
@Ignore("FIXME: fix exception")
726716
@Test
727717
public void realtime_get_leave() {
728718
AblyRealtime clientAbly1 = null;
@@ -781,7 +771,6 @@ public void realtime_get_leave() {
781771
* Attach to channel, enter presence channel, then initiate second
782772
* connection, seeing existing member in message subsequent to second attach response
783773
*/
784-
@Ignore("FIXME: fix exception")
785774
@Test
786775
public void attach_enter_simple() {
787776
AblyRealtime clientAbly1 = null;
@@ -858,7 +847,6 @@ public void attach_enter_simple() {
858847
*
859848
* Test RTP4
860849
*/
861-
@Ignore("FIXME: fix exception")
862850
@Test
863851
public void attach_enter_multiple() {
864852
AblyRealtime clientAbly1 = null;
@@ -943,7 +931,6 @@ public void attach_enter_multiple() {
943931
/**
944932
* Attach and enter channel on two connections, seeing
945933
* both members in presence returned by realtime get() */
946-
@Ignore("FIXME: fix exception")
947934
@Test
948935
public void realtime_enter_multiple() {
949936
AblyRealtime clientAbly1 = null;
@@ -1014,7 +1001,6 @@ public void realtime_enter_multiple() {
10141001
/**
10151002
* Attach to channel, enter presence channel and get presence using rest get()
10161003
*/
1017-
@Ignore("FIXME: fix exception")
10181004
@Test
10191005
public void rest_get_simple() {
10201006
AblyRealtime clientAbly1 = null;
@@ -1067,7 +1053,6 @@ public void rest_get_simple() {
10671053
/**
10681054
* Attach to channel, enter+leave presence channel and get presence with rest get()
10691055
*/
1070-
@Ignore("FIXME: fix exception")
10711056
@Test
10721057
public void rest_get_leave() {
10731058
AblyRealtime clientAbly1 = null;
@@ -1125,7 +1110,6 @@ public void rest_get_leave() {
11251110
/**
11261111
* Attach and enter channel on two connections, seeing
11271112
* both members in presence returned by rest get() */
1128-
@Ignore("FIXME: fix exception")
11291113
@Test
11301114
public void rest_enter_multiple() {
11311115
AblyRealtime clientAbly1 = null;
@@ -1191,7 +1175,6 @@ public void rest_enter_multiple() {
11911175
/**
11921176
* Attach and enter channel multiple times on a single connection,
11931177
* retrieving members using paginated rest get() */
1194-
@Ignore("FIXME: fix exception")
11951178
@Test
11961179
public void rest_paginated_get() {
11971180
AblyRealtime clientAbly1 = null;
@@ -1277,7 +1260,6 @@ public void rest_paginated_get() {
12771260
/**
12781261
* Attach to channel, enter presence channel, disconnect and await leave event
12791262
*/
1280-
@Ignore("FIXME: fix exception")
12811263
@Test
12821264
public void disconnect_leave() {
12831265
AblyRealtime clientAbly1 = null;
@@ -1419,7 +1401,6 @@ public Presence.PresenceListener setMessageStack(List<PresenceMessage> messageSt
14191401
*
14201402
* @throws AblyException
14211403
*/
1422-
@Ignore("FIXME: flaky test")
14231404
@Test
14241405
public void realtime_presence_unsubscribe_single() throws AblyException {
14251406
/* Ably instance that will emit presence events */
@@ -1499,7 +1480,6 @@ public Presence.PresenceListener setMessageStack(List<PresenceMessage> messageSt
14991480
*
15001481
* @throws AblyException
15011482
*/
1502-
@Ignore("FIXME: flaky test")
15031483
@Test
15041484
public void realtime_presence_subscribe_all() throws AblyException {
15051485
/* Ably instance that will emit presence events */
@@ -1575,7 +1555,6 @@ public Presence.PresenceListener setMessageStack(List<PresenceMessage> messageSt
15751555
*
15761556
* @throws AblyException
15771557
*/
1578-
@Ignore("FIXME: fix exception")
15791558
@Test
15801559
public void realtime_presence_subscribe_multiple() throws AblyException {
15811560
/* Ably instance that will emit presence events */
@@ -1824,7 +1803,6 @@ public Presence.PresenceListener setMessageStack(List<PresenceMessage> messageSt
18241803
*
18251804
* @throws AblyException
18261805
*/
1827-
@Ignore("FIXME: flaky test")
18281806
@Test
18291807
public void realtime_presence_attach_implicit_subscribe_fail() throws AblyException {
18301808
AblyRealtime ably = null;
@@ -2142,7 +2120,6 @@ public void realtime_presence_attach_implicit_leaveclient_fail() throws AblyExce
21422120
*
21432121
* @throws AblyException
21442122
*/
2145-
@Ignore("FIXME: fix exception")
21462123
@Test
21472124
public void realtime_presence_get_throws_when_channel_failed() throws AblyException {
21482125
AblyRealtime ably = null;
@@ -2467,7 +2444,6 @@ public void onPresenceMessage(PresenceMessage message) {
24672444
*
24682445
* Tests RTP3
24692446
*/
2470-
@Ignore("FIXME: fix exception")
24712447
@Test
24722448
public void reattach_resume_broken_sync() {
24732449
AblyRealtime clientAbly1 = null;
@@ -2850,7 +2826,6 @@ public void onChannelStateChanged(ChannelStateChange stateChange) {
28502826
*
28512827
* Not functional yet
28522828
*/
2853-
@Ignore("FIXME: fix exception")
28542829
@Test
28552830
public void presence_without_subscribe_capability() throws AblyException {
28562831
String channelName = "presence_without_subscribe" + testParams.name;
@@ -2914,7 +2889,6 @@ public void onError(ErrorInfo reason) {
29142889
*
29152890
* Tests RTP13
29162891
*/
2917-
@Ignore("FIXME: fix exception")
29182892
@Test
29192893
public void sync_complete() {
29202894
AblyRealtime ably1 = null, ably2 = null;
@@ -2994,7 +2968,6 @@ public void presence_enter_without_permission() throws AblyException {
29942968
/**
29952969
* Enter wrong client (mismatching one set in the token), check exception
29962970
*/
2997-
@Ignore("FIXME: fix exception")
29982971
@Test
29992972
public void presence_enter_mismatched_clientid() throws AblyException {
30002973
String channelName = "presence_enter_mismatched_clientid" + testParams.name;
@@ -3236,7 +3209,6 @@ public boolean matches(ProtocolMessage message) {
32363209
* Verify presence data is received and encoded/decoded correctly
32373210
* Tests RTP8e, RTP6a
32383211
*/
3239-
@Ignore("FIXME: flaky test")
32403212
@Test
32413213
public void presence_encoding() throws AblyException, InterruptedException {
32423214
AblyRealtime ably1 = null, ably2 = null;
@@ -3307,7 +3279,6 @@ public void onPresenceMessage(PresenceMessage message) {
33073279
* Test Presence.get() filtering and syncToWait flag
33083280
* Tests RTP11b, RTP11c, RTP11d
33093281
*/
3310-
@Ignore("FIXME: fix exception")
33113282
@Test
33123283
public void presence_get() throws AblyException, InterruptedException {
33133284
AblyRealtime ably1 = null, ably2 = null;
@@ -3316,15 +3287,15 @@ public void presence_get() throws AblyException, InterruptedException {
33163287
final String channelName = "presence_get" + testParams.name;
33173288
ClientOptions opts = createOptions(testVars.keys[0].keyStr);
33183289
ably1 = new AblyRealtime(opts);
3319-
opts.autoConnect = false;
3320-
ably2 = new AblyRealtime(opts);
33213290

33223291
Channel channel1 = ably1.channels.get(channelName);
33233292
CompletionWaiter completionWaiter = new CompletionWaiter();
33243293
channel1.presence.enterClient("1", null, completionWaiter);
33253294
channel1.presence.enterClient("2", null, completionWaiter);
33263295
completionWaiter.waitFor(2);
33273296

3297+
opts.autoConnect = false;
3298+
ably2 = new AblyRealtime(opts);
33283299
Channel channel2 = ably2.channels.get(channelName);
33293300
PresenceWaiter waiter2 = new PresenceWaiter(channel2);
33303301

@@ -3403,7 +3374,6 @@ public void checkMembersWithChannelPresence(Channel testChannel) throws AblyExce
34033374
assertEquals("Members count with channel presence should be " + presenceMessages.length, presenceMessages.length, 1);
34043375
}
34053376

3406-
@Ignore
34073377
@Test
34083378
public void test_consistent_presence_for_members() {
34093379
AblyRealtime clientAbly1 = null;
@@ -3566,7 +3536,6 @@ public void message_from_encoded_json_object() throws AblyException {
35663536
* Refer Spec. TP4
35673537
* @throws AblyException
35683538
*/
3569-
@Ignore("FIXME: fix exception")
35703539
@Test
35713540
public void messages_from_encoded_json_array() throws AblyException {
35723541
JsonArray fixtures = null;

0 commit comments

Comments
 (0)