forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPresenceTest.java
More file actions
59 lines (38 loc) · 1.59 KB
/
PresenceTest.java
File metadata and controls
59 lines (38 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.pubnub.api;
import org.junit.Before;
import org.junit.Test;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
public class PresenceTest {
Pubnub pubnub = new Pubnub("demo", "demo");
Pubnub pubnub2 = new Pubnub("demo", "demo");
String random;
@Before
public void setUp() throws PubnubException {
pubnub.setCacheBusting(false);
pubnub2.setCacheBusting(false);
random = UUID.randomUUID().toString().substring(0, 8);
}
@Test
public void testPresenceOnCurrentClient() throws InterruptedException, PubnubException {
String channel = "java-unittest-" + Math.random();
CountDownLatch latch = new CountDownLatch(1);
TestHelper.PresenceCallback presenceCb = new TestHelper.PresenceCallback(latch);
pubnub.presence(channel, presenceCb);
pubnub.subscribe(channel, new Callback() {});
latch.await(10, TimeUnit.SECONDS);
assertEquals(pubnub.getUUID(), presenceCb.getUUID());
}
@Test
public void testPresenceOnOtherClient() throws InterruptedException, PubnubException {
String channel = "java-unittest-" + Math.random();
CountDownLatch latch = new CountDownLatch(1);
TestHelper.PresenceCallback presenceCb = new TestHelper.PresenceCallback(latch);
pubnub.presence(channel, presenceCb);
pubnub2.subscribe(channel, new Callback() {});
latch.await(10, TimeUnit.SECONDS);
assertEquals(pubnub2.getUUID(), presenceCb.getUUID());
}
}