lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceHistoryTest.java
/**
     * Publish events with data of various datatypes
     */
Publish events with data of various datatypes
Publish events with data of various datatypes
@Test
    public void presencehistory_types_forward() {
        AblyRealtime ably = null;
        try {
            ClientOptions rtOpts = createOptions();
            rtOpts.token = token.token;
            rtOpts.clientId = testClientId;
            ably = new AblyRealtime(rtOpts);
            String channelName = "persisted:presencehistory_types_forward_" + 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 enter events to the channel */
            CompletionWaiter msgComplete = new CompletionWaiter();
            channel.presence.enter("This is a string message payload", msgComplete);
            channel.presence.enter("This is a byte[] message payload".getBytes(), msgComplete);
            /* wait for the enter 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 and order */
            assertEquals("Expect messages.asArray()[0] to be expected String", messages.items()[0].data, "This is a string message payload");
            assertEquals("Expect messages.asArray()[1] to be expected byte[]", new String((byte[])messages.items()[1].data), "This is a byte[] message payload");
        } catch (AblyException e) {
            e.printStackTrace();
            fail("presencehistory_types: Unexpected exception");
        } finally {
            if(ably != null)
                ably.close();
        }
    }
@ Test public void presencehistory_types_forward ( ) { AblyRealtime ably = null ; try { ClientOptions rtOpts = createOptions ( ) ; rtOpts . token = token . token ; rtOpts . clientId = testClientId ; ably = new AblyRealtime ( rtOpts ) ; String channelName = "persisted:presencehistory_types_forward_" + 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 enter events to the channel */ CompletionWaiter msgComplete = new CompletionWaiter ( ) ; channel . presence . enter ( "This is a string message payload" , msgComplete ) ; channel . presence . enter ( "This is a byte[] message payload" . getBytes ( ) , msgComplete ) ; /* wait for the enter 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 and order */ assertEquals ( "Expect messages.asArray()[0] to be expected String" , messages . items ( ) [ 0 ] . data , "This is a string message payload" ) ; assertEquals ( "Expect messages.asArray()[1] to be expected byte[]" , new String ( ( byte [ ] ) messages . items ( ) [ 1 ] . data ) , "This is a byte[] message payload" ) ; } catch ( AblyException e ) { e . printStackTrace ( ) ; fail ( "presencehistory_types: Unexpected exception" ) ; } finally { if ( ably != null ) ably . close ( ) ; } }
Publish events with data of various datatypes
Publish events with data of various datatypes