本文整理汇总了Java中com.mysql.jdbc.ReplicationConnection.setAutoCommit方法的典型用法代码示例。如果您正苦于以下问题:Java ReplicationConnection.setAutoCommit方法的具体用法?Java ReplicationConnection.setAutoCommit怎么用?Java ReplicationConnection.setAutoCommit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mysql.jdbc.ReplicationConnection
的用法示例。
在下文中一共展示了ReplicationConnection.setAutoCommit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReplicationConnectionGroupHostManagement
import com.mysql.jdbc.ReplicationConnection; //导入方法依赖的package包/类
public void testReplicationConnectionGroupHostManagement() throws Exception {
String replicationGroup1 = "rg1";
Properties props = new Properties();
props.setProperty("replicationConnectionGroup", replicationGroup1);
props.setProperty("retriesAllDown", "3");
ReplicationConnection conn2 = this.getUnreliableReplicationConnection(new String[] { "first", "second", "third" }, props);
assertNotNull("Connection should not be null", this.conn);
conn2.setAutoCommit(false);
String port = getPort(props, new NonRegisteringDriver());
String firstHost = "first:" + port;
String secondHost = "second:" + port;
String thirdHost = "third:" + port;
// "first" should be master, "second" and "third" should be slaves.
assertEquals(1, ReplicationConnectionGroupManager.getConnectionCountWithHostAsMaster(replicationGroup1, firstHost));
assertEquals(0, ReplicationConnectionGroupManager.getConnectionCountWithHostAsSlave(replicationGroup1, firstHost));
// remove "third" from slave pool:
conn2.removeSlave(thirdHost);
assertEquals(0, ReplicationConnectionGroupManager.getConnectionCountWithHostAsMaster(replicationGroup1, thirdHost));
assertEquals(0, ReplicationConnectionGroupManager.getConnectionCountWithHostAsSlave(replicationGroup1, thirdHost));
// add "third" back into slave pool:
conn2.addSlaveHost(thirdHost);
assertEquals(0, ReplicationConnectionGroupManager.getConnectionCountWithHostAsMaster(replicationGroup1, thirdHost));
assertEquals(1, ReplicationConnectionGroupManager.getConnectionCountWithHostAsSlave(replicationGroup1, thirdHost));
conn2.setReadOnly(false);
assertEquals(0, ReplicationConnectionGroupManager.getNumberOfMasterPromotion(replicationGroup1));
// failover to "second" as master
ReplicationConnectionGroupManager.promoteSlaveToMaster(replicationGroup1, secondHost);
assertEquals(1, ReplicationConnectionGroupManager.getNumberOfMasterPromotion(replicationGroup1));
// "first" is still a master:
assertEquals(1, ReplicationConnectionGroupManager.getConnectionCountWithHostAsMaster(replicationGroup1, firstHost));
assertEquals(0, ReplicationConnectionGroupManager.getConnectionCountWithHostAsSlave(replicationGroup1, firstHost));
assertEquals(1, ReplicationConnectionGroupManager.getConnectionCountWithHostAsMaster(replicationGroup1, secondHost));
assertEquals(0, ReplicationConnectionGroupManager.getConnectionCountWithHostAsSlave(replicationGroup1, secondHost));
ReplicationConnectionGroupManager.removeMasterHost(replicationGroup1, firstHost);
conn2.createStatement().execute("SELECT 1");
assertFalse(conn2.isClosed());
conn2.commit();
// validate that queries are successful:
conn2.createStatement().execute("SELECT 1");
assertTrue(conn2.isHostMaster(secondHost));
// master is now offline
UnreliableSocketFactory.downHost("second");
try {
Statement lstmt = conn2.createStatement();
lstmt.execute("SELECT 1");
fail("Should fail here due to closed connection");
} catch (SQLException sqlEx) {
assertEquals("08S01", sqlEx.getSQLState());
}
}