本文整理汇总了Java中com.mysql.fabric.jdbc.FabricMySQLDataSource.setFabricServerGroup方法的典型用法代码示例。如果您正苦于以下问题:Java FabricMySQLDataSource.setFabricServerGroup方法的具体用法?Java FabricMySQLDataSource.setFabricServerGroup怎么用?Java FabricMySQLDataSource.setFabricServerGroup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mysql.fabric.jdbc.FabricMySQLDataSource
的用法示例。
在下文中一共展示了FabricMySQLDataSource.setFabricServerGroup方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConnectionDataSource
import com.mysql.fabric.jdbc.FabricMySQLDataSource; //导入方法依赖的package包/类
/**
* Test that we can connect with the data source, given a server group name
*/
public void testConnectionDataSource() throws Exception {
if (!this.isSetForFabricTest) {
return;
}
FabricMySQLDataSource ds = getNewDefaultDataSource();
ds.setFabricServerGroup("fabric_test1_global");
Connection c = ds.getConnection(this.username, this.password);
// same as above
ResultSet rs = c.createStatement().executeQuery("select user()");
rs.next();
String userFromDb = rs.getString(1).split("@")[0];
assertEquals(this.username, userFromDb);
rs.close();
c.close();
}
示例2: testBug82094
import com.mysql.fabric.jdbc.FabricMySQLDataSource; //导入方法依赖的package包/类
/**
* Test Bug#82094 - ConcurrentModificationException on Fabric connections after topology changes.
*
* This test requires a Fabric instance running with a HA group (ha_config1_group) containing three servers, one promoted to master and failure detection
* turned on.
* Note that removing one or the other secondary server is a distinct case and only one of them causes the reported failure. This is so because of the order
* the elements on the slave servers HashSet, from the ReplicationConnectionGroup object, are iterated. So, we remove one at a time in this test to make
* sure we cover both cases.
*/
public void testBug82094() throws Exception {
if (!this.isSetForFabricTest) {
return;
}
FabricMySQLDataSource ds = getNewDefaultDataSource();
ds.setFabricServerGroup("ha_config1_group");
this.conn = (FabricMySQLConnection) ds.getConnection(this.username, this.password);
this.conn.createStatement().close(); // Make sure there is an internal ReplicationConnection.
FabricConnection fabricConn = new FabricConnection(this.fabricUrl, this.fabricUsername, this.fabricPassword);
for (Server server : fabricConn.getServerGroup("ha_config1_group").getServers()) {
if (server.isSlave()) {
try {
this.conn.transactionCompleted();
// Remove Secondary server.
fabricConn.getClient().removeServerFromGroup(server.getGroupName(), server.getHostname(), server.getPort());
// Make sure the TTL expires before moving on.
fabricConn.refreshState();
while (!fabricConn.isStateExpired()) {
Thread.sleep(1000);
}
this.conn.transactionCompleted();
} finally {
// Add Secondary server back.
fabricConn.getClient().addServerToGroup(server.getGroupName(), server.getHostname(), server.getPort());
// Make sure the TTL expires before moving on.
fabricConn.refreshState();
while (!fabricConn.isStateExpired()) {
Thread.sleep(1000);
}
}
}
}
this.conn.close();
}
示例3: testConnectionDataSource
import com.mysql.fabric.jdbc.FabricMySQLDataSource; //导入方法依赖的package包/类
/**
* Test that we can connect with the data source, given a server group name
*/
public void testConnectionDataSource() throws Exception {
FabricMySQLDataSource ds = getNewDefaultDataSource();
ds.setFabricServerGroup("fabric_test1_global");
Connection c = ds.getConnection(this.username, this.password);
// same as above
ResultSet rs = c.createStatement().executeQuery("select user()");
rs.next();
String userFromDb = rs.getString(1).split("@")[0];
assertEquals(this.username, userFromDb);
rs.close();
c.close();
}
示例4: testConnectionDataSource
import com.mysql.fabric.jdbc.FabricMySQLDataSource; //导入方法依赖的package包/类
/**
* Test that we can connect with the data source, given a server group name
*/
public void testConnectionDataSource() throws Exception {
FabricMySQLDataSource ds = getNewDefaultDataSource();
ds.setFabricServerGroup("fabric_test1_global");
Connection c = ds.getConnection(this.username, this.password);
// same as above
ResultSet rs = c.createStatement().executeQuery("select user()");
rs.next();
String userFromDb = rs.getString(1).split("@")[0];
assertEquals(this.username, userFromDb);
rs.close();
c.close();
}