question: public void testFailoverAutoReconnect ( ) throws Exception { Set < String > downedHosts = new HashSet < String > ( ) ; downedHosts . add ( HOST_1 ) ; downedHosts . add ( HOST_2 ) ; Properties props = new Properties ( ) ; props . setProperty ( "retriesAllDown" , "2" ) ; props . setProperty ( "maxReconnects" , "2" ) ; props . setProperty ( "initialTimeout" , "1" ) ; for ( boolean foAutoReconnect : new boolean [ ] { true , false } ) { props . setProperty ( "autoReconnect" , Boolean . toString ( foAutoReconnect ) ) ; Connection testConn = getUnreliableFailoverConnection ( new String [ ] { HOST_1 , HOST_2 , HOST_3 } , props , downedHosts ) ; Statement testStmt1 = null , testStmt2 = null ; try { assertEquals ( HOST_3_OK , UnreliableSocketFactory . getHostFromLastConnection ( ) ) ; testStmt1 = testConn . createStatement ( ) ; testStmt2 = testConn . createStatement ( ) ; assertSingleValueQuery ( testStmt1 , "SELECT 1" , 1L ) ; assertSingleValueQuery ( testStmt2 , "SELECT 2" , 2L ) ; UnreliableSocketFactory . dontDownHost ( HOST_2 ) ; UnreliableSocketFactory . downHost ( HOST_3 ) ; assertEquals ( HOST_3_OK , UnreliableSocketFactory . getHostFromLastConnection ( ) ) ; assertSQLException ( testStmt1 , "SELECT 1" , COMM_LINK_ERR_PATTERN ) ; assertEquals ( HOST_2_OK , UnreliableSocketFactory . getHostFromLastConnection ( ) ) ; UnreliableSocketFactory . dontDownHost ( HOST_1 ) ; if ( ! foAutoReconnect ) { assertSQLException ( testStmt1 , "SELECT 1" , STMT_CLOSED_ERR_PATTERN ) ; assertSQLException ( testStmt2 , "SELECT 2" , STMT_CLOSED_ERR_PATTERN ) ; testStmt1 = testConn . createStatement ( ) ; testStmt2 = testConn . createStatement ( ) ; } assertSingleValueQuery ( testStmt1 , "SELECT 1" , 1L ) ; assertSingleValueQuery ( testStmt2 , "SELECT 2" , 2L ) ; UnreliableSocketFactory . downHost ( HOST_2 ) ; assertEquals ( HOST_2_OK , UnreliableSocketFactory . getHostFromLastConnection ( ) ) ; assertSQLException ( testStmt2 , "SELECT 2" , COMM_LINK_ERR_PATTERN ) ; assertEquals ( HOST_1_OK , UnreliableSocketFactory . getHostFromLastConnection ( ) ) ; UnreliableSocketFactory . dontDownHost ( HOST_3 ) ; if ( ! foAutoReconnect ) { assertSQLException ( testStmt1 , "SELECT 1" , STMT_CLOSED_ERR_PATTERN ) ; assertSQLException ( testStmt2 , "SELECT 2" , STMT_CLOSED_ERR_PATTERN ) ; testStmt1 = testConn . createStatement ( ) ; testStmt2 = testConn . createStatement ( ) ; } assertSingleValueQuery ( testStmt1 , "SELECT 1" , 1L ) ; assertSingleValueQuery ( testStmt2 , "SELECT 2" , 2L ) ; UnreliableSocketFactory . downHost ( HOST_1 ) ; assertEquals ( HOST_1_OK , UnreliableSocketFactory . getHostFromLastConnection ( ) ) ; assertSQLException ( testStmt1 , "SELECT 1" , COMM_LINK_ERR_PATTERN ) ; assertEquals ( HOST_3_OK , UnreliableSocketFactory . getHostFromLastConnection ( ) ) ; if ( ! foAutoReconnect ) { assertSQLException ( testStmt1 , "SELECT 1" , STMT_CLOSED_ERR_PATTERN ) ; assertSQLException ( testStmt2 , "SELECT 2" , STMT_CLOSED_ERR_PATTERN ) ; testStmt1 = testConn . createStatement ( ) ; testStmt2 = testConn . createStatement ( ) ; } assertSingleValueQuery ( testStmt1 , "SELECT 1" , 1L ) ; assertSingleValueQuery ( testStmt2 , "SELECT 2" , 2L ) ; if ( foAutoReconnect ) { assertConnectionsHistory ( HOST_1_FAIL , HOST_1_FAIL , HOST_2_FAIL , HOST_2_FAIL , HOST_3_OK , HOST_2_OK , HOST_3_FAIL , HOST_3_FAIL , HOST_2_FAIL , HOST_2_FAIL , HOST_3_FAIL , HOST_3_FAIL , HOST_1_OK , HOST_2_FAIL , HOST_2_FAIL , HOST_3_OK ) ; } else { assertConnectionsHistory ( HOST_1_FAIL , HOST_2_FAIL , HOST_3_OK , HOST_2_OK , HOST_3_FAIL , HOST_2_FAIL , HOST_3_FAIL , HOST_1_OK , HOST_2_FAIL , HOST_3_OK ) ; } } finally { if ( testStmt1 != null ) { testStmt1 . close ( ) ; } if ( testStmt2 != null ) { testStmt2 . close ( ) ; } if ( testConn != null ) { testConn . close ( ) ; } } } }
target:  Tests the property 'autoReconnect' in a failover connection using three hosts and the following sequence of events: - [\HOST_1 : \HOST_2 : /HOST_3] --> HOST_3 - [\HOST_1 : /HOST_2 : \HOST_3] --> HOST_2 - [/HOST_1 : /HOST_2 : \HOST_3] - [/HOST_1 : \HOST_2 : \HOST_3] --> HOST_1 - [/HOST_1 : \HOST_2 : /HOST_3] - [\HOST_1 : \HOST_2 : /HOST_3] --> HOST_3 [Legend: "/HOST_n" --> HOST_n up; "\HOST_n" --> HOST_n down]