private void testFailoverTransition(String fromHost,String toHost,Set<String> downedHosts,String recoverHost,String... expectedConnectionsHistory) throws Exception {
  Properties props=new Properties();
  props.setProperty("retriesAllDown","2");
  String fromHostOk=UnreliableSocketFactory.STATUS_CONNECTED + fromHost;
  String toHostOk=UnreliableSocketFactory.STATUS_CONNECTED + toHost;
  Connection testConn=getUnreliableFailoverConnection(new String[]{HOST_1,HOST_2,HOST_3},props,downedHosts);
  Statement testStmt=null;
  try {
    if (recoverHost != null) {
      UnreliableSocketFactory.dontDownHost(recoverHost);
    }
    assertEquals(fromHostOk,UnreliableSocketFactory.getHostFromLastConnection());
    testStmt=testConn.createStatement();
    assertSingleValueQuery(testStmt,"SELECT 1",1L);
    UnreliableSocketFactory.downHost(fromHost);
    assertEquals(fromHostOk,UnreliableSocketFactory.getHostFromLastConnection());
    assertSQLException(testStmt,"SELECT 1",COMM_LINK_ERR_PATTERN);
    assertEquals(toHostOk,UnreliableSocketFactory.getHostFromLastConnection());
    assertSQLException(testStmt,"SELECT 1",STMT_CLOSED_ERR_PATTERN);
    testStmt=testConn.createStatement();
    assertSingleValueQuery(testStmt,"SELECT 1",1L);
    assertEquals(toHostOk,UnreliableSocketFactory.getHostFromLastConnection());
    assertConnectionsHistory(expectedConnectionsHistory);
  }
  finally {
    if (testStmt != null) {
      testStmt.close();
    }
    if (testConn != null) {
      testConn.close();
    }
  }
}

private void testFailoverTransition ( String fromHost , String toHost , Set < String > downedHosts , String recoverHost , String ... expectedConnectionsHistory ) throws Exception { Properties props = new Properties ( ) ; props . setProperty ( "retriesAllDown" , "2" ) ; String fromHostOk = UnreliableSocketFactory . STATUS_CONNECTED + fromHost ; String toHostOk = UnreliableSocketFactory . STATUS_CONNECTED + toHost ; Connection testConn = getUnreliableFailoverConnection ( new String [ ] { HOST_1 , HOST_2 , HOST_3 } , props , downedHosts ) ; Statement testStmt = null ; try { if ( recoverHost != null ) { UnreliableSocketFactory . dontDownHost ( recoverHost ) ; } assertEquals ( fromHostOk , UnreliableSocketFactory . getHostFromLastConnection ( ) ) ; testStmt = testConn . createStatement ( ) ; assertSingleValueQuery ( testStmt , "SELECT 1" , 1L ) ; UnreliableSocketFactory . downHost ( fromHost ) ; assertEquals ( fromHostOk , UnreliableSocketFactory . getHostFromLastConnection ( ) ) ; assertSQLException ( testStmt , "SELECT 1" , COMM_LINK_ERR_PATTERN ) ; assertEquals ( toHostOk , UnreliableSocketFactory . getHostFromLastConnection ( ) ) ; assertSQLException ( testStmt , "SELECT 1" , STMT_CLOSED_ERR_PATTERN ) ; testStmt = testConn . createStatement ( ) ; assertSingleValueQuery ( testStmt , "SELECT 1" , 1L ) ; assertEquals ( toHostOk , UnreliableSocketFactory . getHostFromLastConnection ( ) ) ; assertConnectionsHistory ( expectedConnectionsHistory ) ; } finally { if ( testStmt != null ) { testStmt . close ( ) ; } if ( testConn != null ) { testConn . close ( ) ; } } }
tests a failover transition .
