lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceHistoryTest.java
/**
     * Connect twice to the service, each using the default (binary) protocol.
     * Publish messages on one connection to a given channel; then attach
     * the second connection to the same channel and verify a complete message
     * history can be obtained.
     */
Connect twice to the service, each using the default (binary) protocol.
Publish messages on one connection to a given channel; then attach
the second connection to the same channel and verify a complete message
history can be obtained.
Connect twice to the service each using the default ( binary ) protocol . Publish messages on one connection to a given channel ; then attach the second connection to the same channel and verify a complete message history can be obtained .
@Test
    public void presencehistory_second_channel() {
        AblyRealtime txAbly = null, rxAbly = null;
        try {
            ClientOptions txOpts = createOptions();
            txOpts.token = token.token;
            txOpts.clientId = testClientId;
            txAbly = new AblyRealtime(txOpts);
            ClientOptions rxOpts = createOptions(testVars.keys[0].keyStr);
            rxAbly = new AblyRealtime(rxOpts);
            String channelName = "persisted:presencehistory_second_channel_" + testParams.name;
            /* create a channel */
            final Channel txChannel = txAbly.channels.get(channelName);
            final Channel rxChannel = rxAbly.channels.get(channelName);
            /* attach sender */
            txChannel.attach();
            (new ChannelWaiter(txChannel)).waitFor(ChannelState.attached);
            assertEquals("Verify attached state reached", txChannel.state, ChannelState.attached);
            /* enter the channel */
            String messageText = "Test message (presencehistory_second_channel)";
            CompletionWaiter msgComplete = new CompletionWaiter();
            txChannel.presence.enter(messageText, msgComplete);
            /* wait for the enter callback to be called */
            msgComplete.waitFor();
            assertTrue("Verify success callback was called", msgComplete.success);
            /* attach receiver */
            rxChannel.attach();
            (new ChannelWaiter(rxChannel)).waitFor(ChannelState.attached);
            assertEquals("Verify attached state reached", rxChannel.state, ChannelState.attached);
            /* get the history for this channel */
            PaginatedResult<PresenceMessage> messages = rxChannel.presence.history(null);
            assertNotNull("Expected non-null messages", messages);
            assertEquals("Expected 1 message", messages.items().length, 1);
            /* verify message contents */
            assertEquals("Expect correct message text", messages.items()[0].data, messageText);
        } catch (AblyException e) {
            e.printStackTrace();
            fail("presencehistory_second_channel: Unexpected exception instantiating library");
        } finally {
            if(txAbly != null)
                txAbly.close();
            if(rxAbly != null)
                rxAbly.close();
        }
    }
@ Test public void presencehistory_second_channel ( ) { AblyRealtime txAbly = null , rxAbly = null ; try { ClientOptions txOpts = createOptions ( ) ; txOpts . token = token . token ; txOpts . clientId = testClientId ; txAbly = new AblyRealtime ( txOpts ) ; ClientOptions rxOpts = createOptions ( testVars . keys [ 0 ] . keyStr ) ; rxAbly = new AblyRealtime ( rxOpts ) ; String channelName = "persisted:presencehistory_second_channel_" + testParams . name ; /* create a channel */ final Channel txChannel = txAbly . channels . get ( channelName ) ; final Channel rxChannel = rxAbly . channels . get ( channelName ) ; /* attach sender */ txChannel . attach ( ) ; ( new ChannelWaiter ( txChannel ) ) . waitFor ( ChannelState . attached ) ; assertEquals ( "Verify attached state reached" , txChannel . state , ChannelState . attached ) ; /* enter the channel */ String messageText = "Test message (presencehistory_second_channel)" ; CompletionWaiter msgComplete = new CompletionWaiter ( ) ; txChannel . presence . enter ( messageText , msgComplete ) ; /* wait for the enter callback to be called */ msgComplete . waitFor ( ) ; assertTrue ( "Verify success callback was called" , msgComplete . success ) ; /* attach receiver */ rxChannel . attach ( ) ; ( new ChannelWaiter ( rxChannel ) ) . waitFor ( ChannelState . attached ) ; assertEquals ( "Verify attached state reached" , rxChannel . state , ChannelState . attached ) ; /* get the history for this channel */ PaginatedResult < PresenceMessage > messages = rxChannel . presence . history ( null ) ; assertNotNull ( "Expected non-null messages" , messages ) ; assertEquals ( "Expected 1 message" , messages . items ( ) . length , 1 ) ; /* verify message contents */ assertEquals ( "Expect correct message text" , messages . items ( ) [ 0 ] . data , messageText ) ; } catch ( AblyException e ) { e . printStackTrace ( ) ; fail ( "presencehistory_second_channel: Unexpected exception instantiating library" ) ; } finally { if ( txAbly != null ) txAbly . close ( ) ; if ( rxAbly != null ) rxAbly . close ( ) ; } }
Connect twice to the service, each using the default (binary) protocol.
Connect twice to the service each using the default ( binary ) protocol .