lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceHistoryTest.java
/**
     * Publish enough presence to fill 2 pages.
     * Verify that,
     *   - {@code PaginatedQuery#isLast} returns false, when we are at the first page.
     *   - {@code PaginatedQuery#isLast} returns true, when we are at the second page.
     */
Publish enough presence to fill 2 pages.
Verify that,
-  PaginatedQuery#isLast returns false, when we are at the first page.
-  PaginatedQuery#isLast returns true, when we are at the second page.
Publish enough presence to fill 2 pages . Verify that - PaginatedQuery#isLast returns false when we are at the first page . - PaginatedQuery#isLast returns true when we are at the second page .
@Test
    public void presencehistory_islast() throws AblyException {
        AblyRealtime ably = null;
        try {
            ClientOptions opts = createOptions(testVars.keys[0].keyStr);
            opts.token = token.token;
            opts.clientId = testClientId;
            ably = new AblyRealtime(opts);
            String channelName = "persisted:presencehistory_islast_" + testParams.name;
            int pageMessageCount = 10;
            /* create a channel */
            final Channel channel = ably.channels.get(channelName);
            /* attach */
            channel.attach();
            new ChannelWaiter(channel).waitFor(ChannelState.attached);
            assertEquals("Verify attached state reached", channel.state, ChannelState.attached);
            /* publish to the channel */
            CompletionSet msgComplete = new CompletionSet();
            for (int i = 0; i < (pageMessageCount * 2 - 1); i++) {
                channel.presence.update(String.valueOf(i), msgComplete.add());
            }
            /* wait for the publish callbacks to be called */
            msgComplete.waitFor();
            assertTrue("Verify success callback was called", msgComplete.errors.isEmpty());
            /* get the history for this channel */
            PaginatedResult<PresenceMessage> messages = channel.presence.history(new Param[]{new Param("limit", String.format(Locale.ENGLISH, "%d", pageMessageCount))});
            assertNotNull("Expected non-null messages", messages);
            assertEquals("Expected " + pageMessageCount + " messages", messages.items().length, pageMessageCount);
            /* Verify that current page is not the last */
            assertThat(messages.isLast(), is(false));
            /* get next page */
            messages = messages.next();
            --pageMessageCount;
            assertNotNull("Expected non-null messages", messages);
            assertEquals("Expected " + pageMessageCount + " messages", messages.items().length, pageMessageCount);
            /* Verify that current page is the last */
            assertThat(messages.isLast(), is(true));
        } finally {
            if (ably != null)
                ably.close();
        }
    }
@ Test public void presencehistory_islast ( ) throws AblyException { AblyRealtime ably = null ; try { ClientOptions opts = createOptions ( testVars . keys [ 0 ] . keyStr ) ; opts . token = token . token ; opts . clientId = testClientId ; ably = new AblyRealtime ( opts ) ; String channelName = "persisted:presencehistory_islast_" + testParams . name ; int pageMessageCount = 10 ; /* create a channel */ final Channel channel = ably . channels . get ( channelName ) ; /* attach */ channel . attach ( ) ; new ChannelWaiter ( channel ) . waitFor ( ChannelState . attached ) ; assertEquals ( "Verify attached state reached" , channel . state , ChannelState . attached ) ; /* publish to the channel */ CompletionSet msgComplete = new CompletionSet ( ) ; for ( int i = 0 ; i < ( pageMessageCount * 2 - 1 ) ; i ++ ) { channel . presence . update ( String . valueOf ( i ) , msgComplete . add ( ) ) ; } /* wait for the publish callbacks to be called */ msgComplete . waitFor ( ) ; assertTrue ( "Verify success callback was called" , msgComplete . errors . isEmpty ( ) ) ; /* get the history for this channel */ PaginatedResult < PresenceMessage > messages = channel . presence . history ( new Param [ ] { new Param ( "limit" , String . format ( Locale . ENGLISH , "%d" , pageMessageCount ) ) } ) ; assertNotNull ( "Expected non-null messages" , messages ) ; assertEquals ( "Expected " + pageMessageCount + " messages" , messages . items ( ) . length , pageMessageCount ) ; /* Verify that current page is not the last */ assertThat ( messages . isLast ( ) , is ( false ) ) ; /* get next page */ messages = messages . next ( ) ; -- pageMessageCount ; assertNotNull ( "Expected non-null messages" , messages ) ; assertEquals ( "Expected " + pageMessageCount + " messages" , messages . items ( ) . length , pageMessageCount ) ; /* Verify that current page is the last */ assertThat ( messages . isLast ( ) , is ( true ) ) ; } finally { if ( ably != null ) ably . close ( ) ; } }
Publish enough presence to fill 2 pages.
Publish enough presence to fill 2 pages .