Package com.mysql.jdbc

Examples of com.mysql.jdbc.ReplicationConnection.createStatement()


    assertFalse(conn2.isReadOnly());
    assertTrue(conn2.isMasterConnection());
    try {
      conn2.createStatement().execute("DROP TABLE IF EXISTS testRepTable");
      conn2.createStatement().execute("CREATE TABLE testRepTable (a INT)");
      conn2.createStatement().execute("INSERT INTO testRepTable VALUES (1)");
      conn2.createStatement().execute("DROP TABLE IF EXISTS testRepTable");
     
    } catch (SQLException e) {
      fail("Should not fail to execute CREATE/INSERT/DROP statements.");
    }   
View Full Code Here


    assertTrue(conn2.isMasterConnection());
    try {
      conn2.createStatement().execute("DROP TABLE IF EXISTS testRepTable");
      conn2.createStatement().execute("CREATE TABLE testRepTable (a INT)");
      conn2.createStatement().execute("INSERT INTO testRepTable VALUES (1)");
      conn2.createStatement().execute("DROP TABLE IF EXISTS testRepTable");
     
    } catch (SQLException e) {
      fail("Should not fail to execute CREATE/INSERT/DROP statements.");
    }   
  }
View Full Code Here

    conn2.commit();
    // go to slaves:
    conn2.setReadOnly(true);
   
    // should succeed, as slave2 has not yet been activated:
    conn2.createStatement().execute("/* ping */ SELECT 1");
    // allow connections to slave2:
    UnreliableSocketFactory.dontDownHost("slave2");
    // force next re-balance to slave2:
    ForcedLoadBalanceStrategy.forceFutureServer("slave2:" + portNumber, -1);
    // re-balance:
View Full Code Here

    // re-balance:
    conn2.commit();
    // down slave1 (active but not selected slave connection):
    UnreliableSocketFactory.downHost("slave1");
    // should succeed, as slave2 is currently selected:
    conn2.createStatement().execute("/* ping */ SELECT 1");
   
   
 
    // make all hosts available
    UnreliableSocketFactory.flushAllHostLists();
View Full Code Here

   
    // peg connection to slave2:
    ForcedLoadBalanceStrategy.forceFutureServer("slave2:" + portNumber, -1);
    conn2.commit();

    rs = conn2.createStatement().executeQuery("SELECT CONNECTION_ID()");
    rs.next();
    int slave2id = rs.getInt(1);

    // peg connection to slave1 now:
    ForcedLoadBalanceStrategy.forceFutureServer("slave1:" + portNumber, -1);
View Full Code Here

    // by an inactive load-balanced connection, but we lack COM_PING
    // counters on the server side, and need to create infrastructure
    // to capture what's being sent by the driver separately.
   
    Thread.sleep(2000);
    conn2.createStatement().execute("/* ping */ SELECT 1");
    rs = conn2.createStatement().executeQuery("SELECT time FROM information_schema.processlist WHERE id = " + slave2id);
    rs.next();
    assertTrue("Processlist should be less than 2 seconds due to ping", rs.getInt(1) < 2);
   
    // peg connection to slave2:
View Full Code Here

    // counters on the server side, and need to create infrastructure
    // to capture what's being sent by the driver separately.
   
    Thread.sleep(2000);
    conn2.createStatement().execute("/* ping */ SELECT 1");
    rs = conn2.createStatement().executeQuery("SELECT time FROM information_schema.processlist WHERE id = " + slave2id);
    rs.next();
    assertTrue("Processlist should be less than 2 seconds due to ping", rs.getInt(1) < 2);
   
    // peg connection to slave2:
    ForcedLoadBalanceStrategy.forceFutureServer("slave2:" + portNumber, -1);
View Full Code Here

    conn2.commit();
    // leaving connection tied to slave2, bring slave2 down and slave1 up:
    UnreliableSocketFactory.downHost("slave2");
   
    try {
      conn2.createStatement().execute("/* ping */ SELECT 1");
      fail("Expected failure because current slave connection is down.");
    } catch (SQLException e) { }
   
    conn2.close();
   
View Full Code Here

   
    // disable master:
    UnreliableSocketFactory.downHost("master");
   
    // ping should succeed, because we're still attached to slaves:
    conn2.createStatement().execute("/* ping */ SELECT 1");
   
    // bring master back up:
    UnreliableSocketFactory.dontDownHost("master");

    // get back to master, confirm it's recovered:
View Full Code Here

    // bring master back up:
    UnreliableSocketFactory.dontDownHost("master");

    // get back to master, confirm it's recovered:
    conn2.commit();
    conn2.createStatement().execute("/* ping */ SELECT 1");
    try{
      conn2.setReadOnly(false);
    } catch (SQLException e) {}
   
    conn2.commit();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.