lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceHistoryTest.java
/**
     * Publish events, get limited history and check expected order (forwards)
     */
Publish events, get limited history and check expected order (forwards)
Publish events get limited history and check expected order ( forwards )
@Test
    public void presencehistory_limit_f() {
        AblyRealtime ably = null;
        try {
            ClientOptions rtOpts = createOptions();
            rtOpts.token = token.token;
            rtOpts.clientId = testClientId;
            ably = new AblyRealtime(rtOpts);
            String channelName = "persisted:presencehistory_limit_f_" + testParams.name;
            /* 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 < 50; i++) {
                try {
                    channel.presence.enter(String.valueOf(i), msgComplete.add());
                } catch(AblyException e) {
                    e.printStackTrace();
                    fail("presencehistory_limit_f: Unexpected exception");
                    return;
                }
            }
            /* 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("direction", "forwards"), new Param("limit", "25") });
            assertNotNull("Expected non-null messages", messages);
            assertEquals("Expected 25 messages", messages.items().length, 25);
            /* verify message order */
            for(int i = 0; i < 25; i++)
                assertEquals("Expect correct message data", messages.items()[i].data, String.valueOf(i));
        } catch (AblyException e) {
            e.printStackTrace();
            fail("presencehistory_limit_f: Unexpected exception");
        } finally {
            if(ably != null)
                ably.close();
        }
    }
@ Test public void presencehistory_limit_f ( ) { AblyRealtime ably = null ; try { ClientOptions rtOpts = createOptions ( ) ; rtOpts . token = token . token ; rtOpts . clientId = testClientId ; ably = new AblyRealtime ( rtOpts ) ; String channelName = "persisted:presencehistory_limit_f_" + testParams . name ; /* 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 < 50 ; i ++ ) { try { channel . presence . enter ( String . valueOf ( i ) , msgComplete . add ( ) ) ; } catch ( AblyException e ) { e . printStackTrace ( ) ; fail ( "presencehistory_limit_f: Unexpected exception" ) ; return ; } } /* 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 ( "direction" , "forwards" ) , new Param ( "limit" , "25" ) } ) ; assertNotNull ( "Expected non-null messages" , messages ) ; assertEquals ( "Expected 25 messages" , messages . items ( ) . length , 25 ) ; /* verify message order */ for ( int i = 0 ; i < 25 ; i ++ ) assertEquals ( "Expect correct message data" , messages . items ( ) [ i ] . data , String . valueOf ( i ) ) ; } catch ( AblyException e ) { e . printStackTrace ( ) ; fail ( "presencehistory_limit_f: Unexpected exception" ) ; } finally { if ( ably != null ) ably . close ( ) ; } }
Publish events, get limited history and check expected order (forwards)
Publish events get limited history and check expected order ( forwards )