lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceTest.java
/**
     * Attach and enter channel on two connections, seeing
     * both members in presence returned by rest get() */
Attach and enter channel on two connections, seeing
both members in presence returned by rest get()
Attach and enter channel on two connections seeing both members in presence returned by rest get ()
@Ignore("FIXME: fix exception")
    @Test
    public void rest_enter_multiple() {
        AblyRealtime clientAbly1 = null;
        AblyRealtime clientAbly2 = null;
        TestChannel testChannel = new TestChannel();
        try {
            /* subscribe for presence events in the anonymous connection */
            new PresenceWaiter(testChannel.realtimeChannel);
            /* set up a connection with specific clientId */
            ClientOptions client1Opts = new ClientOptions() {{
                tokenDetails = token1;
                clientId = testClientId1;
            }};
            fillInOptions(client1Opts);
            clientAbly1 = new AblyRealtime(client1Opts);
            /* get channel and attach */
            Channel client1Channel = clientAbly1.channels.get(testChannel.channelName);
            CompletionWaiter enter1Complete = new CompletionWaiter();
            String enterString1 = "Test data (enter_multiple, clientId1)";
            client1Channel.presence.enter(enterString1, enter1Complete);
            enter1Complete.waitFor();
            assertTrue("Verify enter callback called on completion", enter1Complete.success);
            /* set up a second connection with different clientId */
            ClientOptions client2Opts = new ClientOptions() {{
                tokenDetails = token2;
                clientId = testClientId2;
            }};
            fillInOptions(client2Opts);
            clientAbly2 = new AblyRealtime(client2Opts);
            /* get channel and subscribe to presence */
            Channel client2Channel = clientAbly2.channels.get(testChannel.channelName);
            CompletionWaiter enter2Complete = new CompletionWaiter();
            String enterString2 = "Test data (enter_multiple, clientId2)";
            client2Channel.presence.enter(enterString2, enter2Complete);
            enter2Complete.waitFor();
            assertTrue("Verify enter callback called on completion", enter2Complete.success);
            /* get presence set and verify client present */
            PresenceMessage[] presences = testChannel.restChannel.presence.get(null).items();
            PresenceMessage expectedPresent1 = contains(presences, testClientId1, Action.present);
            PresenceMessage expectedPresent2 = contains(presences, testClientId2, Action.present);
            assertNotNull("Verify expected clients are in presence set", expectedPresent1);
            assertNotNull("Verify expected clients are in presence set", expectedPresent2);
            assertEquals(expectedPresent1.data, enterString1);
            assertEquals(expectedPresent2.data, enterString2);
        } catch(AblyException e) {
            e.printStackTrace();
            fail("Unexpected exception running test: " + e.getMessage());
        } finally {
            if(clientAbly1 != null)
                clientAbly1.close();
            if(clientAbly2 != null)
                clientAbly2.close();
            if(testChannel != null)
                testChannel.dispose();
        }
    }
@ Ignore ( "FIXME: fix exception" ) @ Test public void rest_enter_multiple ( ) { AblyRealtime clientAbly1 = null ; AblyRealtime clientAbly2 = null ; TestChannel testChannel = new TestChannel ( ) ; try { /* subscribe for presence events in the anonymous connection */ new PresenceWaiter ( testChannel . realtimeChannel ) ; /* set up a connection with specific clientId */ ClientOptions client1Opts = new ClientOptions ( ) { { tokenDetails = token1 ; clientId = testClientId1 ; } } ; fillInOptions ( client1Opts ) ; clientAbly1 = new AblyRealtime ( client1Opts ) ; /* get channel and attach */ Channel client1Channel = clientAbly1 . channels . get ( testChannel . channelName ) ; CompletionWaiter enter1Complete = new CompletionWaiter ( ) ; String enterString1 = "Test data (enter_multiple, clientId1)" ; client1Channel . presence . enter ( enterString1 , enter1Complete ) ; enter1Complete . waitFor ( ) ; assertTrue ( "Verify enter callback called on completion" , enter1Complete . success ) ; /* set up a second connection with different clientId */ ClientOptions client2Opts = new ClientOptions ( ) { { tokenDetails = token2 ; clientId = testClientId2 ; } } ; fillInOptions ( client2Opts ) ; clientAbly2 = new AblyRealtime ( client2Opts ) ; /* get channel and subscribe to presence */ Channel client2Channel = clientAbly2 . channels . get ( testChannel . channelName ) ; CompletionWaiter enter2Complete = new CompletionWaiter ( ) ; String enterString2 = "Test data (enter_multiple, clientId2)" ; client2Channel . presence . enter ( enterString2 , enter2Complete ) ; enter2Complete . waitFor ( ) ; assertTrue ( "Verify enter callback called on completion" , enter2Complete . success ) ; /* get presence set and verify client present */ PresenceMessage [ ] presences = testChannel . restChannel . presence . get ( null ) . items ( ) ; PresenceMessage expectedPresent1 = contains ( presences , testClientId1 , Action . present ) ; PresenceMessage expectedPresent2 = contains ( presences , testClientId2 , Action . present ) ; assertNotNull ( "Verify expected clients are in presence set" , expectedPresent1 ) ; assertNotNull ( "Verify expected clients are in presence set" , expectedPresent2 ) ; assertEquals ( expectedPresent1 . data , enterString1 ) ; assertEquals ( expectedPresent2 . data , enterString2 ) ; } catch ( AblyException e ) { e . printStackTrace ( ) ; fail ( "Unexpected exception running test: " + e . getMessage ( ) ) ; } finally { if ( clientAbly1 != null ) clientAbly1 . close ( ) ; if ( clientAbly2 != null ) clientAbly2 . close ( ) ; if ( testChannel != null ) testChannel . dispose ( ) ; } }
Attach and enter channel on two connections, seeing
 both members in presence returned by rest get()
Attach and enter channel on two connections seeing both members in presence returned by rest get ()