lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceTest.java
/**
     * Attach to channel, enter presence channel, then initiate second
     * connection, seeing existing member in message subsequent to second attach response
     */
Attach to channel, enter presence channel, then initiate second
connection, seeing existing member in message subsequent to second attach response
Attach to channel enter presence channel then initiate second connection seeing existing member in message subsequent to second attach response
@Ignore("FIXME: fix exception")
    @Test
    public void attach_enter_simple() {
        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);
            /* wait until connected */
            (new ConnectionWaiter(clientAbly1.connection)).waitFor(ConnectionState.connected);
            assertEquals("Verify connected state reached", clientAbly1.connection.state, ConnectionState.connected);
            /* get channel and attach */
            Channel client1Channel = clientAbly1.channels.get(testChannel.channelName);
            client1Channel.attach();
            (new ChannelWaiter(client1Channel)).waitFor(ChannelState.attached);
            assertEquals("Verify attached state reached", client1Channel.state, ChannelState.attached);
            /* let client1 enter the channel and wait for the success callback */
            CompletionWaiter enterComplete = new CompletionWaiter();
            String enterString = "Test data (attach_enter)";
            client1Channel.presence.enter(enterString, enterComplete);
            enterComplete.waitFor();
            assertTrue("Verify enter callback called on completion", enterComplete.success);
            /* set up a second connection with different clientId */
            ClientOptions client2Opts = new ClientOptions() {{
                tokenDetails = token2;
                clientId = testClientId2;
            }};
            fillInOptions(client2Opts);
            clientAbly2 = new AblyRealtime(client2Opts);
            /* wait until connected */
            (new ConnectionWaiter(clientAbly2.connection)).waitFor(ConnectionState.connected);
            assertEquals("Verify connected state reached", clientAbly2.connection.state, ConnectionState.connected);
            /* get channel and subscribe to presence */
            Channel client2Channel = clientAbly2.channels.get(testChannel.channelName);
            PresenceWaiter client2Waiter = new PresenceWaiter(client2Channel);
            client2Waiter.waitFor(testClientId1, Action.present);
            /* get presence set and verify client present */
            PresenceMessage[] presences = client2Channel.presence.get(false);
            PresenceMessage expectedPresent = contains(presences, testClientId1, Action.present);
            assertNotNull("Verify expected client is in presence set", expectedPresent);
            assertEquals(expectedPresent.data, enterString);
        } 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 attach_enter_simple ( ) { 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 ) ; /* wait until connected */ ( new ConnectionWaiter ( clientAbly1 . connection ) ) . waitFor ( ConnectionState . connected ) ; assertEquals ( "Verify connected state reached" , clientAbly1 . connection . state , ConnectionState . connected ) ; /* get channel and attach */ Channel client1Channel = clientAbly1 . channels . get ( testChannel . channelName ) ; client1Channel . attach ( ) ; ( new ChannelWaiter ( client1Channel ) ) . waitFor ( ChannelState . attached ) ; assertEquals ( "Verify attached state reached" , client1Channel . state , ChannelState . attached ) ; /* let client1 enter the channel and wait for the success callback */ CompletionWaiter enterComplete = new CompletionWaiter ( ) ; String enterString = "Test data (attach_enter)" ; client1Channel . presence . enter ( enterString , enterComplete ) ; enterComplete . waitFor ( ) ; assertTrue ( "Verify enter callback called on completion" , enterComplete . success ) ; /* set up a second connection with different clientId */ ClientOptions client2Opts = new ClientOptions ( ) { { tokenDetails = token2 ; clientId = testClientId2 ; } } ; fillInOptions ( client2Opts ) ; clientAbly2 = new AblyRealtime ( client2Opts ) ; /* wait until connected */ ( new ConnectionWaiter ( clientAbly2 . connection ) ) . waitFor ( ConnectionState . connected ) ; assertEquals ( "Verify connected state reached" , clientAbly2 . connection . state , ConnectionState . connected ) ; /* get channel and subscribe to presence */ Channel client2Channel = clientAbly2 . channels . get ( testChannel . channelName ) ; PresenceWaiter client2Waiter = new PresenceWaiter ( client2Channel ) ; client2Waiter . waitFor ( testClientId1 , Action . present ) ; /* get presence set and verify client present */ PresenceMessage [ ] presences = client2Channel . presence . get ( false ) ; PresenceMessage expectedPresent = contains ( presences , testClientId1 , Action . present ) ; assertNotNull ( "Verify expected client is in presence set" , expectedPresent ) ; assertEquals ( expectedPresent . data , enterString ) ; } 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 to channel, enter presence channel, then initiate second
 connection, seeing existing member in message subsequent to second attach response
Attach to channel enter presence channel then initiate second connection seeing existing member in message subsequent to second attach response