lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceTest.java
/**
     * Enter, then leave, presence channel and await leave event
     * Verify that the item is removed from the presence map (RTP2e)
     */
Enter, then leave, presence channel and await leave event
Verify that the item is removed from the presence map (RTP2e)
Enter then leave presence channel and await leave event Verify that the item is removed from the presence map ( RTP2e )
@Ignore("FIXME: fix exception")
    @Test
    public void enter_leave_simple() {
        AblyRealtime clientAbly1 = null;
        TestChannel testChannel = new TestChannel();
        try {
            /* subscribe for presence events in the anonymous connection */
            PresenceWaiter presenceWaiter = new PresenceWaiter(testChannel.realtimeChannel);
            /* set up a connection with specific clientId */
            ClientOptions client1Opts = new ClientOptions() {{
                tokenDetails = token1;
                clientId = testClientId1;
            }};
            fillInOptions(client1Opts);
            clientAbly1 = new AblyRealtime(client1Opts);
            /* get channel */
            Channel client1Channel = clientAbly1.channels.get(testChannel.channelName);
            /* let client1 enter the channel and wait for the entered event to be delivered */
            CompletionWaiter enterComplete = new CompletionWaiter();
            String enterString = "Test data (enter_before_connect)";
            client1Channel.presence.enter(enterString, enterComplete);
            presenceWaiter.waitFor(testClientId1, Action.enter);
            assertNotNull(presenceWaiter.contains(testClientId1, Action.enter));
            assertEquals(presenceWaiter.receivedMessages.get(0).data, enterString);
            presenceWaiter.reset();
            /* verify enter callback called on completion */
            enterComplete.waitFor();
            assertTrue("Verify enter callback called on completion", enterComplete.success);
            /* let client1 leave the channel and wait for the leave event to be delivered */
            CompletionWaiter leaveComplete = new CompletionWaiter();
            String leaveString = "Test data (enter_before_connect), leaving";
            client1Channel.presence.leave(leaveString, leaveComplete);
            presenceWaiter.waitFor(testClientId1, Action.leave);
            PresenceMessage expectedLeft = presenceWaiter.contains(testClientId1, clientAbly1.connection.id, Action.leave);
            assertNotNull(expectedLeft);
            assertEquals(expectedLeft.data, leaveString);
            /* verify leave callback called on completion */
            leaveComplete.waitFor();
            assertTrue("Verify leave callback called on completion", leaveComplete.success);
            assertEquals("Verify item is removed from the presence map", client1Channel.presence.get(testClientId1, false).length, 0);
        } catch(AblyException e) {
            e.printStackTrace();
            fail("Unexpected exception running test: " + e.getMessage());
        } finally {
            if(clientAbly1 != null)
                clientAbly1.close();
            if(testChannel != null)
                testChannel.dispose();
        }
    }
@ Ignore ( "FIXME: fix exception" ) @ Test public void enter_leave_simple ( ) { AblyRealtime clientAbly1 = null ; TestChannel testChannel = new TestChannel ( ) ; try { /* subscribe for presence events in the anonymous connection */ PresenceWaiter presenceWaiter = new PresenceWaiter ( testChannel . realtimeChannel ) ; /* set up a connection with specific clientId */ ClientOptions client1Opts = new ClientOptions ( ) { { tokenDetails = token1 ; clientId = testClientId1 ; } } ; fillInOptions ( client1Opts ) ; clientAbly1 = new AblyRealtime ( client1Opts ) ; /* get channel */ Channel client1Channel = clientAbly1 . channels . get ( testChannel . channelName ) ; /* let client1 enter the channel and wait for the entered event to be delivered */ CompletionWaiter enterComplete = new CompletionWaiter ( ) ; String enterString = "Test data (enter_before_connect)" ; client1Channel . presence . enter ( enterString , enterComplete ) ; presenceWaiter . waitFor ( testClientId1 , Action . enter ) ; assertNotNull ( presenceWaiter . contains ( testClientId1 , Action . enter ) ) ; assertEquals ( presenceWaiter . receivedMessages . get ( 0 ) . data , enterString ) ; presenceWaiter . reset ( ) ; /* verify enter callback called on completion */ enterComplete . waitFor ( ) ; assertTrue ( "Verify enter callback called on completion" , enterComplete . success ) ; /* let client1 leave the channel and wait for the leave event to be delivered */ CompletionWaiter leaveComplete = new CompletionWaiter ( ) ; String leaveString = "Test data (enter_before_connect), leaving" ; client1Channel . presence . leave ( leaveString , leaveComplete ) ; presenceWaiter . waitFor ( testClientId1 , Action . leave ) ; PresenceMessage expectedLeft = presenceWaiter . contains ( testClientId1 , clientAbly1 . connection . id , Action . leave ) ; assertNotNull ( expectedLeft ) ; assertEquals ( expectedLeft . data , leaveString ) ; /* verify leave callback called on completion */ leaveComplete . waitFor ( ) ; assertTrue ( "Verify leave callback called on completion" , leaveComplete . success ) ; assertEquals ( "Verify item is removed from the presence map" , client1Channel . presence . get ( testClientId1 , false ) . length , 0 ) ; } catch ( AblyException e ) { e . printStackTrace ( ) ; fail ( "Unexpected exception running test: " + e . getMessage ( ) ) ; } finally { if ( clientAbly1 != null ) clientAbly1 . close ( ) ; if ( testChannel != null ) testChannel . dispose ( ) ; } }
Enter, then leave, presence channel and await leave event
 Verify that the item is removed from the presence map (RTP2e)
Enter then leave presence channel and await leave event Verify that the item is removed from the presence map ( RTP2e )