当前位置: 首页>>代码示例>>Java>>正文


Java ReplicationConnection.addSlaveHost方法代码示例

本文整理汇总了Java中com.mysql.jdbc.ReplicationConnection.addSlaveHost方法的典型用法代码示例。如果您正苦于以下问题:Java ReplicationConnection.addSlaveHost方法的具体用法?Java ReplicationConnection.addSlaveHost怎么用?Java ReplicationConnection.addSlaveHost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mysql.jdbc.ReplicationConnection的用法示例。


在下文中一共展示了ReplicationConnection.addSlaveHost方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testReplicationConnectionNoSlavesRemainOnMaster

import com.mysql.jdbc.ReplicationConnection; //导入方法依赖的package包/类
/**
 * Test that we remain on the master when:
 * - the connection is not in read-only mode
 * - no slaves are configured
 * - a new slave is added
 */
public void testReplicationConnectionNoSlavesRemainOnMaster() throws Exception {
    Properties props = getPropertiesFromTestsuiteUrl();
    String masterHost = props.getProperty(NonRegisteringDriver.HOST_PROPERTY_KEY) + ":" + props.getProperty(NonRegisteringDriver.PORT_PROPERTY_KEY);
    ReplicationConnection replConn = getTestReplicationConnectionNoSlaves(masterHost);
    Statement s = replConn.createStatement();
    ResultSet rs1 = s.executeQuery("select CONNECTION_ID()");
    assertTrue(rs1.next());
    int masterConnectionId = rs1.getInt(1);
    rs1.close();
    s.close();

    // add a slave and make sure we are NOT on a new connection
    replConn.addSlaveHost(masterHost);
    s = replConn.createStatement();
    rs1 = s.executeQuery("select CONNECTION_ID()");
    assertTrue(rs1.next());
    assertEquals(masterConnectionId, rs1.getInt(1));
    assertFalse(replConn.isReadOnly());
    rs1.close();
    s.close();
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:28,代码来源:ConnectionRegressionTest.java

示例2: testReplicationConnectionNoSlavesRemainOnMaster

import com.mysql.jdbc.ReplicationConnection; //导入方法依赖的package包/类
/**
 * Test that we remain on the master when:
 * - the connection is not in read-only mode
 * - no slaves are configured
 * - a new slave is added
 */
public void testReplicationConnectionNoSlavesRemainOnMaster() throws Exception {
	Properties props = getPropertiesFromTestsuiteUrl();
	String masterHost = props.getProperty(NonRegisteringDriver.HOST_PROPERTY_KEY) + ":" +
		props.getProperty(NonRegisteringDriver.PORT_PROPERTY_KEY);
	ReplicationConnection replConn = getTestReplicationConnectionNoSlaves(masterHost);
	Statement s = replConn.createStatement();
	ResultSet rs1 = s.executeQuery("select CONNECTION_ID()");
	assertTrue(rs1.next());
	int masterConnectionId = rs1.getInt(1);
	rs1.close();
	s.close();

	// add a slave and make sure we are NOT on a new connection
	replConn.addSlaveHost(masterHost);
	s = replConn.createStatement();
	rs1 = s.executeQuery("select CONNECTION_ID()");
	assertTrue(rs1.next());
	assertEquals(masterConnectionId, rs1.getInt(1));
	assertFalse(replConn.isReadOnly());
	rs1.close();
	s.close();
}
 
开发者ID:hinsenchan,项目名称:fil_project_mgmt_app_v2,代码行数:29,代码来源:ConnectionRegressionTest.java

示例3: 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());
    }

}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:67,代码来源:ConnectionRegressionTest.java


注:本文中的com.mysql.jdbc.ReplicationConnection.addSlaveHost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。