lib/src/test/java/io/ably/lib/test/realtime/RealtimeConnectTest.java
/**
     * Perform a simple connect, close the connection, and verify that
     * the connection can be re-established by calling connect().
     */
Perform a simple connect, close the connection, and verify that
the connection can be re-established by calling connect().
Perform a simple connect close the connection and verify that the connection can be re - established by calling connect () .
@Ignore("FIXME: fix exception")
    @Test
    public void connect_after_close() {
        try {
            ClientOptions opts = createOptions(testVars.keys[0].keyStr);
            AblyRealtime ably = new AblyRealtime(opts);
            ConnectionWaiter connectionWaiter = new ConnectionWaiter(ably.connection);
            connectionWaiter.waitFor(ConnectionState.connected);
            assertEquals("Verify connected state is reached", ConnectionState.connected, ably.connection.state);
            /* send a few channels to increment PendingMessageQueue.startSerial */
            for (int i = 0; i < 3; i++) {
                /* publish to the channel */
                CompletionWaiter msgComplete = new CompletionWaiter();
                ably.channels.get("test_channel").publish("test_event", "Test message", msgComplete);
                /* wait for the publish callback to be called */
                msgComplete.waitFor();
                assertTrue("Verify success callback was called", msgComplete.success);
            }
            ably.close();
            connectionWaiter.waitFor(ConnectionState.closed);
            assertEquals("Verify closed state is reached", ConnectionState.closed, ably.connection.state);
            try { Thread.sleep(1000L); } catch(InterruptedException e) {}
            ably.connection.connect();
            connectionWaiter.waitFor(ConnectionState.connected);
            assertEquals("Verify connected state is reached", ConnectionState.connected, ably.connection.state);
            /* publish to the channel in the new connection to check that it works */
            CompletionWaiter msgComplete = new CompletionWaiter();
            ably.channels.get("test_channel").publish("test_event", "Test message", msgComplete);
            /* wait for the publish callback to be called */
            msgComplete.waitFor();
            assertTrue("Verify success callback was called", msgComplete.success);
            ably.close();
            connectionWaiter.waitFor(ConnectionState.closed);
            assertEquals("Verify closed state is reached", ConnectionState.closed, ably.connection.state);
        } catch (AblyException e) {
            e.printStackTrace();
            fail("init0: Unexpected exception instantiating library");
        }
    }
@ Ignore ( "FIXME: fix exception" ) @ Test public void connect_after_close ( ) { try { ClientOptions opts = createOptions ( testVars . keys [ 0 ] . keyStr ) ; AblyRealtime ably = new AblyRealtime ( opts ) ; ConnectionWaiter connectionWaiter = new ConnectionWaiter ( ably . connection ) ; connectionWaiter . waitFor ( ConnectionState . connected ) ; assertEquals ( "Verify connected state is reached" , ConnectionState . connected , ably . connection . state ) ; /* send a few channels to increment PendingMessageQueue.startSerial */ for ( int i = 0 ; i < 3 ; i ++ ) { /* publish to the channel */ CompletionWaiter msgComplete = new CompletionWaiter ( ) ; ably . channels . get ( "test_channel" ) . publish ( "test_event" , "Test message" , msgComplete ) ; /* wait for the publish callback to be called */ msgComplete . waitFor ( ) ; assertTrue ( "Verify success callback was called" , msgComplete . success ) ; } ably . close ( ) ; connectionWaiter . waitFor ( ConnectionState . closed ) ; assertEquals ( "Verify closed state is reached" , ConnectionState . closed , ably . connection . state ) ; try { Thread . sleep ( 1000L ) ; } catch ( InterruptedException e ) { } ably . connection . connect ( ) ; connectionWaiter . waitFor ( ConnectionState . connected ) ; assertEquals ( "Verify connected state is reached" , ConnectionState . connected , ably . connection . state ) ; /* publish to the channel in the new connection to check that it works */ CompletionWaiter msgComplete = new CompletionWaiter ( ) ; ably . channels . get ( "test_channel" ) . publish ( "test_event" , "Test message" , msgComplete ) ; /* wait for the publish callback to be called */ msgComplete . waitFor ( ) ; assertTrue ( "Verify success callback was called" , msgComplete . success ) ; ably . close ( ) ; connectionWaiter . waitFor ( ConnectionState . closed ) ; assertEquals ( "Verify closed state is reached" , ConnectionState . closed , ably . connection . state ) ; } catch ( AblyException e ) { e . printStackTrace ( ) ; fail ( "init0: Unexpected exception instantiating library" ) ; } }
Perform a simple connect, close the connection, and verify that
 the connection can be re-established by calling connect().
Perform a simple connect close the connection and verify that the connection can be re - established by calling connect () .