Skip to content

Commit 89f002f

Browse files
author
devendram
committed
Merge pull request #35 from pubnub/add-cg-presence-test
Add CG Presence test
2 parents 570ef25 + aa55e41 commit 89f002f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

java/srcTest/com/pubnub/api/ChannelGroupTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,4 +406,36 @@ public void testRemoveNamespacedGroup() throws InterruptedException, JSONExcepti
406406
assertJSONArrayHasNo(group, groups);
407407
assertEquals(channelNamespace, result.getString("namespace"));
408408
}
409+
410+
@Test
411+
public void testPresence() throws InterruptedException, JSONException, PubnubException {
412+
String group = "jtest_group3";
413+
JSONObject result;
414+
415+
final CountDownLatch latch1 = new CountDownLatch(1);
416+
final CountDownLatch latch2 = new CountDownLatch(1);
417+
final CountDownLatch latch3 = new CountDownLatch(1);
418+
final TestHelper.SimpleCallback cb1 = new TestHelper.SimpleCallback(latch1);
419+
final TestHelper.SimpleCallback cb2 = new TestHelper.SimpleCallback(latch2) {
420+
@Override
421+
public void connectCallback(String channel, Object message) {
422+
latch3.countDown();
423+
}
424+
};
425+
426+
pubnub.channelGroupAddChannel(group, "ch1", cb1);
427+
latch1.await(10, TimeUnit.SECONDS);
428+
429+
pubnub.channelGroupSubscribe(group + "-pnpres", cb2);
430+
latch3.await(10, TimeUnit.SECONDS);
431+
432+
pubnub.subscribe("ch1", new Callback() {
433+
});
434+
435+
latch2.await(10, TimeUnit.SECONDS);
436+
437+
result = (JSONObject) cb2.getResponse();
438+
439+
assertEquals(pubnub.getUUID(), result.getString("uuid"));
440+
}
409441
}

0 commit comments

Comments
 (0)