lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceHistoryTest.java
/**
     * Send a single message on a channel, wait enough time for it to
     * persist, then send a second message. Verify that both can be
     * retrieved using channel.history(direction=forwards) without any
     * further wait.
     */
Send a single message on a channel, wait enough time for it to
persist, then send a second message. Verify that both can be
retrieved using channel.history(direction=forwards) without any
further wait.
Send a single message on a channel wait enough time for it to persist then send a second message . Verify that both can be retrieved using channel . history ( direction = forwards ) without any further wait .
@Test
    public void presencehistory_mixed_f() {
        AblyRealtime ably = null;
        try {
            ClientOptions rtOpts = createOptions();
            rtOpts.token = token.token;
            rtOpts.clientId = testClientId;
            ably = new AblyRealtime(rtOpts);
            String channelName = "persisted:presencehistory_mixed_f_" + testParams.name;
            String persistMessageText = "test_event (persisted)";
            String liveMessageText = "test_event (live)";
            /* 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 */
            CompletionWaiter msgComplete = new CompletionWaiter();
            channel.presence.enter(persistMessageText, msgComplete);
            /* wait for the history to be persisted */
            try {
                Thread.sleep(16000);
            } catch(InterruptedException ie) {}
            /* publish to the channel */
            channel.presence.enter(liveMessageText, msgComplete);
            /* wait for the publish callback to be called */
            msgComplete.waitFor(2);
            assertTrue("Verify success callback was called", msgComplete.success);
            /* get the history for this channel */
            PaginatedResult<PresenceMessage> messages = channel.presence.history(new Param[]{ new Param("direction", "forwards") });
            assertNotNull("Expected non-null messages", messages);
            assertEquals("Expected 2 messages", messages.items().length, 2);
            /* verify message contents */
            assertEquals("Expect correct message data", messages.items()[0].data, persistMessageText);
            assertEquals("Expect correct message data", messages.items()[1].data, liveMessageText);
        } catch (AblyException e) {
            e.printStackTrace();
            fail("presencehistory_mixed_binary_f: Unexpected exception instantiating library");
        } finally {
            if(ably != null)
                ably.close();
        }
    }
@ Test public void presencehistory_mixed_f ( ) { AblyRealtime ably = null ; try { ClientOptions rtOpts = createOptions ( ) ; rtOpts . token = token . token ; rtOpts . clientId = testClientId ; ably = new AblyRealtime ( rtOpts ) ; String channelName = "persisted:presencehistory_mixed_f_" + testParams . name ; String persistMessageText = "test_event (persisted)" ; String liveMessageText = "test_event (live)" ; /* 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 */ CompletionWaiter msgComplete = new CompletionWaiter ( ) ; channel . presence . enter ( persistMessageText , msgComplete ) ; /* wait for the history to be persisted */ try { Thread . sleep ( 16000 ) ; } catch ( InterruptedException ie ) { } /* publish to the channel */ channel . presence . enter ( liveMessageText , msgComplete ) ; /* wait for the publish callback to be called */ msgComplete . waitFor ( 2 ) ; assertTrue ( "Verify success callback was called" , msgComplete . success ) ; /* get the history for this channel */ PaginatedResult < PresenceMessage > messages = channel . presence . history ( new Param [ ] { new Param ( "direction" , "forwards" ) } ) ; assertNotNull ( "Expected non-null messages" , messages ) ; assertEquals ( "Expected 2 messages" , messages . items ( ) . length , 2 ) ; /* verify message contents */ assertEquals ( "Expect correct message data" , messages . items ( ) [ 0 ] . data , persistMessageText ) ; assertEquals ( "Expect correct message data" , messages . items ( ) [ 1 ] . data , liveMessageText ) ; } catch ( AblyException e ) { e . printStackTrace ( ) ; fail ( "presencehistory_mixed_binary_f: Unexpected exception instantiating library" ) ; } finally { if ( ably != null ) ably . close ( ) ; } }
Send a single message on a channel, wait enough time for it to
 persist, then send a second message.
Send a single message on a channel wait enough time for it to persist then send a second message .