lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceTest.java
/**
     * Attach and enter channel multiple times on a single connection,
     * retrieving members using paginated rest get() */
Attach and enter channel multiple times on a single connection,
retrieving members using paginated rest get()
Attach and enter channel multiple times on a single connection retrieving members using paginated rest get ()
@Ignore("FIXME: fix exception")
    @Test
    public void rest_paginated_get() {
        AblyRealtime clientAbly1 = null;
        TestChannel testChannel = new TestChannel();
        int clientCount = 30;
        long delay = 100L;
        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);
            /* get channel and attach */
            Channel client1Channel = clientAbly1.channels.get(testChannel.channelName);
            /* enter multiple clients */
            CompletionSet enterComplete = new CompletionSet();
            for(int i = 0; i < clientCount; i++) {
                client1Channel.presence.enterClient("client" + i, "Test data (rest_paginated_get) " + i, enterComplete.add());
                try { Thread.sleep(delay); } catch(InterruptedException e){}
            }
            enterComplete.waitFor();
            assertTrue("Verify enter callback called on completion", enterComplete.errors.isEmpty());
            /* get the presence for this channel */
            HashMap<String, PresenceMessage> memberIndex = new HashMap<String, PresenceMessage>();
            PaginatedResult<PresenceMessage> members = testChannel.restChannel.presence.get(new Param[] { new Param("limit", "10") });
            assertNotNull("Expected non-null messages", members);
            assertEquals("Expected 10 messages", members.items().length, 10);
            /* index received messages */
            for(int i = 0; i < 10; i++) {
                PresenceMessage member = members.items()[i];
                memberIndex.put(member.clientId, member);
            }
            /* get next page */
            members = members.next();
            assertNotNull("Expected non-null messages", members);
            assertEquals("Expected 10 messages", members.items().length, 10);
            /* index received messages */
            for(int i = 0; i < 10; i++) {
                PresenceMessage member = members.items()[i];
                memberIndex.put(member.clientId, member);
            }
            /* get next page */
            members = members.next();
            assertNotNull("Expected non-null messages", members);
            assertEquals("Expected 10 messages", members.items().length, 10);
            /* index received messages */
            for(int i = 0; i < 10; i++) {
                PresenceMessage member = members.items()[i];
                memberIndex.put(member.clientId, member);
            }
            /* verify there is no next page */
            assertFalse("Expected null next page", members.hasNext());
            /* 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(testChannel != null)
                testChannel.dispose();
        }
    }
@ Ignore ( "FIXME: fix exception" ) @ Test public void rest_paginated_get ( ) { AblyRealtime clientAbly1 = null ; TestChannel testChannel = new TestChannel ( ) ; int clientCount = 30 ; long delay = 100L ; 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 ) ; /* get channel and attach */ Channel client1Channel = clientAbly1 . channels . get ( testChannel . channelName ) ; /* enter multiple clients */ CompletionSet enterComplete = new CompletionSet ( ) ; for ( int i = 0 ; i < clientCount ; i ++ ) { client1Channel . presence . enterClient ( "client" + i , "Test data (rest_paginated_get) " + i , enterComplete . add ( ) ) ; try { Thread . sleep ( delay ) ; } catch ( InterruptedException e ) { } } enterComplete . waitFor ( ) ; assertTrue ( "Verify enter callback called on completion" , enterComplete . errors . isEmpty ( ) ) ; /* get the presence for this channel */ HashMap < String , PresenceMessage > memberIndex = new HashMap < String , PresenceMessage > ( ) ; PaginatedResult < PresenceMessage > members = testChannel . restChannel . presence . get ( new Param [ ] { new Param ( "limit" , "10" ) } ) ; assertNotNull ( "Expected non-null messages" , members ) ; assertEquals ( "Expected 10 messages" , members . items ( ) . length , 10 ) ; /* index received messages */ for ( int i = 0 ; i < 10 ; i ++ ) { PresenceMessage member = members . items ( ) [ i ] ; memberIndex . put ( member . clientId , member ) ; } /* get next page */ members = members . next ( ) ; assertNotNull ( "Expected non-null messages" , members ) ; assertEquals ( "Expected 10 messages" , members . items ( ) . length , 10 ) ; /* index received messages */ for ( int i = 0 ; i < 10 ; i ++ ) { PresenceMessage member = members . items ( ) [ i ] ; memberIndex . put ( member . clientId , member ) ; } /* get next page */ members = members . next ( ) ; assertNotNull ( "Expected non-null messages" , members ) ; assertEquals ( "Expected 10 messages" , members . items ( ) . length , 10 ) ; /* index received messages */ for ( int i = 0 ; i < 10 ; i ++ ) { PresenceMessage member = members . items ( ) [ i ] ; memberIndex . put ( member . clientId , member ) ; } /* verify there is no next page */ assertFalse ( "Expected null next page" , members . hasNext ( ) ) ; /* 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 ( testChannel != null ) testChannel . dispose ( ) ; } }
Attach and enter channel multiple times on a single connection,
 retrieving members using paginated rest get()
Attach and enter channel multiple times on a single connection retrieving members using paginated rest get ()