本文整理汇总了Java中com.mysql.jdbc.ReplicationConnection.close方法的典型用法代码示例。如果您正苦于以下问题:Java ReplicationConnection.close方法的具体用法?Java ReplicationConnection.close怎么用?Java ReplicationConnection.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mysql.jdbc.ReplicationConnection
的用法示例。
在下文中一共展示了ReplicationConnection.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReplicationJMXInterfaces
import com.mysql.jdbc.ReplicationConnection; //导入方法依赖的package包/类
public void testReplicationJMXInterfaces() throws Exception {
Properties props = new Properties();
props.setProperty("retriesAllDown", "3");
String replicationGroup = "testReplicationJMXInterfaces";
props.setProperty("replicationConnectionGroup", replicationGroup);
props.setProperty("replicationEnableJMX", "true");
Set<MockConnectionConfiguration> configs = new HashSet<MockConnectionConfiguration>();
MockConnectionConfiguration first = new MockConnectionConfiguration("first", "slave", null, false);
MockConnectionConfiguration second = new MockConnectionConfiguration("second", "master", null, false);
MockConnectionConfiguration third = new MockConnectionConfiguration("third", "slave", null, false);
configs.add(first);
configs.add(second);
configs.add(third);
ReplicationConnection conn2 = this.getUnreliableReplicationConnection(configs, props);
ReplicationGroupManagerMBean bean = getReplicationMBean();
assertEquals(1, bean.getActiveLogicalConnectionCount(replicationGroup));
assertEquals(1, bean.getTotalLogicalConnectionCount(replicationGroup));
assertEquals(0, bean.getSlavePromotionCount(replicationGroup));
assertEquals(1, bean.getActiveMasterHostCount(replicationGroup));
assertEquals(2, bean.getActiveSlaveHostCount(replicationGroup));
bean.removeSlaveHost(replicationGroup, first.getAddress());
assertFalse(bean.getSlaveHostsList(replicationGroup).contains(first.getAddress()));
assertEquals(1, bean.getActiveSlaveHostCount(replicationGroup));
conn2.close();
assertEquals(0, bean.getActiveLogicalConnectionCount(replicationGroup));
conn2 = this.getUnreliableReplicationConnection(configs, props);
assertEquals(1, bean.getActiveLogicalConnectionCount(replicationGroup));
assertEquals(2, bean.getTotalLogicalConnectionCount(replicationGroup));
assertEquals(1, bean.getActiveSlaveHostCount(replicationGroup));
assertEquals(1, bean.getActiveMasterHostCount(replicationGroup));
bean.promoteSlaveToMaster(replicationGroup, third.getAddress());
assertEquals(2, bean.getActiveMasterHostCount(replicationGroup));
assertEquals(0, bean.getActiveSlaveHostCount(replicationGroup));
// confirm this works when no group filter is specified:
bean.addSlaveHost(null, first.getAddress());
assertEquals(1, bean.getActiveSlaveHostCount(replicationGroup));
assertEquals(2, bean.getActiveMasterHostCount(replicationGroup));
bean.removeMasterHost(replicationGroup, second.getAddress());
assertEquals(1, bean.getActiveSlaveHostCount(replicationGroup));
assertEquals(1, bean.getActiveMasterHostCount(replicationGroup));
ReplicationConnection conn3 = this.getUnreliableReplicationConnection(configs, props);
assertEquals(2, bean.getActiveLogicalConnectionCount(replicationGroup));
assertEquals(3, bean.getTotalLogicalConnectionCount(replicationGroup));
assertTrue(bean.getMasterHostsList(replicationGroup).contains(third.getAddress()));
assertFalse(bean.getMasterHostsList(replicationGroup).contains(first.getAddress()));
assertFalse(bean.getMasterHostsList(replicationGroup).contains(second.getAddress()));
assertFalse(bean.getSlaveHostsList(replicationGroup).contains(third.getAddress()));
assertTrue(bean.getSlaveHostsList(replicationGroup).contains(first.getAddress()));
assertFalse(bean.getSlaveHostsList(replicationGroup).contains(second.getAddress()));
assertTrue(bean.getMasterHostsList(replicationGroup).contains(conn3.getMasterConnection().getHost()));
assertTrue(bean.getSlaveHostsList(replicationGroup).contains(conn3.getSlavesConnection().getHost()));
assertTrue(bean.getRegisteredConnectionGroups().contains(replicationGroup));
}
示例2: testBug56100
import com.mysql.jdbc.ReplicationConnection; //导入方法依赖的package包/类
/**
* Tests fix for Bug#56100 - Replication driver routes DML statements to read-only slaves.
*/
public void testBug56100() throws Exception {
final String port = getPort(null, new NonRegisteringDriver());
final String hostMaster = "master:" + port;
final String hostSlave = "slave:" + port;
final Properties props = new Properties();
props.setProperty("statementInterceptors", Bug56100StatementInterceptor.class.getName());
final ReplicationConnection testConn = getUnreliableReplicationConnection(new String[] { "master", "slave" }, props);
assertTrue(testConn.isHostMaster(hostMaster));
assertTrue(testConn.isHostSlave(hostSlave));
// verify that current connection is 'master'
assertTrue(testConn.isMasterConnection());
final Statement testStmt1 = testConn.createStatement();
testBug56100AssertHost(testStmt1, "master");
// set connection to read-only state and verify that current connection is 'slave' now
testConn.setReadOnly(true);
assertFalse(testConn.isMasterConnection());
final Statement testStmt2 = testConn.createStatement();
testBug56100AssertHost(testStmt1, "slave");
testBug56100AssertHost(testStmt2, "slave");
// set connection to read/write state and verify that current connection is 'master' again
testConn.setReadOnly(false);
assertTrue(testConn.isMasterConnection());
final Statement testStmt3 = testConn.createStatement();
testBug56100AssertHost(testStmt1, "master");
testBug56100AssertHost(testStmt2, "master");
testBug56100AssertHost(testStmt3, "master");
// let Connection.close() also close open statements
testConn.close();
assertThrows(SQLException.class, "No operations allowed after statement closed.", new Callable<Void>() {
public Void call() throws Exception {
testStmt1.execute("SELECT 'Bug56100'");
return null;
}
});
assertThrows(SQLException.class, "No operations allowed after statement closed.", new Callable<Void>() {
public Void call() throws Exception {
testStmt2.execute("SELECT 'Bug56100'");
return null;
}
});
assertThrows(SQLException.class, "No operations allowed after statement closed.", new Callable<Void>() {
public Void call() throws Exception {
testStmt3.execute("SELECT 'Bug56100'");
return null;
}
});
}
示例3: testReplicationJMXInterfaces
import com.mysql.jdbc.ReplicationConnection; //导入方法依赖的package包/类
public void testReplicationJMXInterfaces() throws Exception {
Properties props = new Properties();
props.setProperty("retriesAllDown", "3");
String replicationGroup = "testReplicationJMXInterfaces";
props.setProperty("replicationConnectionGroup", replicationGroup);
props.setProperty("replicationEnableJMX", "true");
Set<MockConnectionConfiguration> configs = new HashSet<MockConnectionConfiguration>();
MockConnectionConfiguration first = new MockConnectionConfiguration("first", "slave", null, false);
MockConnectionConfiguration second = new MockConnectionConfiguration("second", "master", null, false);
MockConnectionConfiguration third = new MockConnectionConfiguration("third", "slave", null, false);
configs.add(first);
configs.add(second);
configs.add(third);
ReplicationConnection conn2 = this
.getUnreliableReplicationConnection(configs, props);
ReplicationGroupManagerMBean bean = getReplicationMBean();
assertEquals(1, bean.getActiveLogicalConnectionCount(replicationGroup));
assertEquals(1, bean.getTotalLogicalConnectionCount(replicationGroup));
assertEquals(0, bean.getSlavePromotionCount(replicationGroup));
assertEquals(1, bean.getActiveMasterHostCount(replicationGroup));
assertEquals(2, bean.getActiveSlaveHostCount(replicationGroup));
bean.removeSlaveHost(replicationGroup, first.getAddress());
assertFalse(bean.getSlaveHostsList(replicationGroup).contains(first.getAddress()));
assertEquals(1, bean.getActiveSlaveHostCount(replicationGroup));
conn2.close();
assertEquals(0, bean.getActiveLogicalConnectionCount(replicationGroup));
conn2 = this.getUnreliableReplicationConnection(configs, props);
assertEquals(1, bean.getActiveLogicalConnectionCount(replicationGroup));
assertEquals(2, bean.getTotalLogicalConnectionCount(replicationGroup));
assertEquals(1, bean.getActiveSlaveHostCount(replicationGroup));
assertEquals(1, bean.getActiveMasterHostCount(replicationGroup));
bean.promoteSlaveToMaster(replicationGroup, third.getAddress());
assertEquals(2, bean.getActiveMasterHostCount(replicationGroup));
assertEquals(0, bean.getActiveSlaveHostCount(replicationGroup));
// confirm this works when no group filter is specified:
bean.addSlaveHost(null, first.getAddress());
assertEquals(1, bean.getActiveSlaveHostCount(replicationGroup));
assertEquals(2, bean.getActiveMasterHostCount(replicationGroup));
bean.removeMasterHost(replicationGroup, second.getAddress());
assertEquals(1, bean.getActiveSlaveHostCount(replicationGroup));
assertEquals(1, bean.getActiveMasterHostCount(replicationGroup));
ReplicationConnection conn3 = this
.getUnreliableReplicationConnection(configs, props);
assertEquals(2, bean.getActiveLogicalConnectionCount(replicationGroup));
assertEquals(3, bean.getTotalLogicalConnectionCount(replicationGroup));
assertTrue(bean.getMasterHostsList(replicationGroup).contains(third.getAddress()));
assertFalse(bean.getMasterHostsList(replicationGroup).contains(first.getAddress()));
assertFalse(bean.getMasterHostsList(replicationGroup).contains(second.getAddress()));
assertFalse(bean.getSlaveHostsList(replicationGroup).contains(third.getAddress()));
assertTrue(bean.getSlaveHostsList(replicationGroup).contains(first.getAddress()));
assertFalse(bean.getSlaveHostsList(replicationGroup).contains(second.getAddress()));
assertTrue(bean.getMasterHostsList(replicationGroup).contains(conn3.getMasterConnection().getHost()));
assertTrue(bean.getSlaveHostsList(replicationGroup).contains(conn3.getSlavesConnection().getHost()));
assertTrue(bean.getRegisteredConnectionGroups().contains(replicationGroup));
}