lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceTest.java
/**
     * Attach to channel, enter presence channel with large number of clientIds,
     * then initiate second connection, seeing existing members in sync subsequent
     * to second attach response
     *
     * Test RTP4
     */
Attach to channel, enter presence channel with large number of clientIds,
then initiate second connection, seeing existing members in sync subsequent
to second attach response

Test RTP4
Attach to channel enter presence channel with large number of clientIds then initiate second connection seeing existing members in sync subsequent to second attach response Test RTP4
@Ignore("FIXME: fix exception")
    @Test
    public void attach_enter_multiple() {
        AblyRealtime clientAbly1 = null;
        AblyRealtime clientAbly2 = null;
        TestChannel testChannel = new TestChannel();
        int clientCount = 250;
        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 = wildcardToken;
            }};
            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 for multiple clients and wait for the success callback */
            CompletionSet enterComplete = new CompletionSet();
            for(int i = 0; i < clientCount; i++) {
                client1Channel.presence.enterClient("client" + i, "Test data (attach_enter_multiple) " + i, enterComplete.add());
            }
            enterComplete.waitFor();
            assertTrue("Verify enter callback called on completion", enterComplete.pending.isEmpty());
            assertTrue("Verify no enter errors", enterComplete.errors.isEmpty());
            /* 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 */
            Channel client2Channel = clientAbly2.channels.get(testChannel.channelName);
            client2Channel.attach();
            (new ChannelWaiter(client2Channel)).waitFor(ChannelState.attached);
            assertEquals("Verify attached state reached", client2Channel.state, ChannelState.attached);
            /* get presence set and verify client present */
            HashMap<String, PresenceMessage> memberIndex = new HashMap<String, PresenceMessage>();
            PresenceMessage[] members = client2Channel.presence.get(true);
            assertNotNull("Expected non-null messages", members);
            assertEquals("Expected " + clientCount + " messages", members.length, clientCount);
            /* index received messages */
            for(PresenceMessage member: members)
                memberIndex.put(member.clientId, member);
            /* verify that all clientIds were received */
            assertEquals("Expected " + clientCount + " members", memberIndex.size(), clientCount);
            for(int i = 0; i < clientCount; i++) {
                String clientId = "client" + i;
                assertTrue("Expected client with id " + clientId, memberIndex.containsKey(clientId));
            }
        } catch(AblyException e) {
            e.printStackTrace();
            fail("Unexpected exception running test: " + e.getMessage());
        } finally {
            if(clientAbly1 != null)
                clientAbly1.close();
            if(clientAbly2 != null)
                clientAbly2.close();
            testChannel.dispose();
        }
    }
@ Ignore ( "FIXME: fix exception" ) @ Test public void attach_enter_multiple ( ) { AblyRealtime clientAbly1 = null ; AblyRealtime clientAbly2 = null ; TestChannel testChannel = new TestChannel ( ) ; int clientCount = 250 ; 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 = wildcardToken ; } } ; 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 for multiple clients and wait for the success callback */ CompletionSet enterComplete = new CompletionSet ( ) ; for ( int i = 0 ; i < clientCount ; i ++ ) { client1Channel . presence . enterClient ( "client" + i , "Test data (attach_enter_multiple) " + i , enterComplete . add ( ) ) ; } enterComplete . waitFor ( ) ; assertTrue ( "Verify enter callback called on completion" , enterComplete . pending . isEmpty ( ) ) ; assertTrue ( "Verify no enter errors" , enterComplete . errors . isEmpty ( ) ) ; /* 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 */ Channel client2Channel = clientAbly2 . channels . get ( testChannel . channelName ) ; client2Channel . attach ( ) ; ( new ChannelWaiter ( client2Channel ) ) . waitFor ( ChannelState . attached ) ; assertEquals ( "Verify attached state reached" , client2Channel . state , ChannelState . attached ) ; /* get presence set and verify client present */ HashMap < String , PresenceMessage > memberIndex = new HashMap < String , PresenceMessage > ( ) ; PresenceMessage [ ] members = client2Channel . presence . get ( true ) ; assertNotNull ( "Expected non-null messages" , members ) ; assertEquals ( "Expected " + clientCount + " messages" , members . length , clientCount ) ; /* index received messages */ for ( PresenceMessage member : members ) memberIndex . put ( member . clientId , member ) ; /* verify that all clientIds were received */ assertEquals ( "Expected " + clientCount + " members" , memberIndex . size ( ) , clientCount ) ; for ( int i = 0 ; i < clientCount ; i ++ ) { String clientId = "client" + i ; assertTrue ( "Expected client with id " + clientId , memberIndex . containsKey ( clientId ) ) ; } } catch ( AblyException e ) { e . printStackTrace ( ) ; fail ( "Unexpected exception running test: " + e . getMessage ( ) ) ; } finally { if ( clientAbly1 != null ) clientAbly1 . close ( ) ; if ( clientAbly2 != null ) clientAbly2 . close ( ) ; testChannel . dispose ( ) ; } }
Attach to channel, enter presence channel with large number of clientIds,
 then initiate second connection, seeing existing members in sync subsequent
 to second attach response
Attach to channel enter presence channel with large number of clientIds then initiate second connection seeing existing members in sync subsequent to second attach response