當前位置: 首頁>>代碼示例>>Java>>正文


Java Connection.hashCode方法代碼示例

本文整理匯總了Java中java.sql.Connection.hashCode方法的典型用法代碼示例。如果您正苦於以下問題:Java Connection.hashCode方法的具體用法?Java Connection.hashCode怎麽用?Java Connection.hashCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.sql.Connection的用法示例。


在下文中一共展示了Connection.hashCode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testBug63284

import java.sql.Connection; //導入方法依賴的package包/類
public void testBug63284() throws Exception {
    Properties props = new Driver().parseURL(BaseTestCase.dbUrl, null);
    props.setProperty("autoReconnect", "true");
    props.setProperty("socketFactory", "testsuite.UnreliableSocketFactory");

    Properties urlProps = new NonRegisteringDriver().parseURL(BaseTestCase.dbUrl, null);

    String host = urlProps.getProperty(NonRegisteringDriver.HOST_PROPERTY_KEY);
    String port = urlProps.getProperty(NonRegisteringDriver.PORT_PROPERTY_KEY);

    props.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
    props.remove(NonRegisteringDriver.NUM_HOSTS_PROPERTY_KEY);
    props.remove(NonRegisteringDriver.HOST_PROPERTY_KEY + ".1");
    props.remove(NonRegisteringDriver.PORT_PROPERTY_KEY + ".1");

    props.setProperty("queriesBeforeRetryMaster", "50");
    props.setProperty("maxReconnects", "1");

    UnreliableSocketFactory.mapHost("master", host);
    UnreliableSocketFactory.mapHost("slave", host);

    Connection failoverConnection1 = null;
    Connection failoverConnection2 = null;

    try {
        failoverConnection1 = getConnectionWithProps("jdbc:mysql://master:" + port + ",slave:" + port + "/", props);

        failoverConnection2 = getConnectionWithProps("jdbc:mysql://master:" + port + ",slave:" + port + "/", props);

        assertTrue(((com.mysql.jdbc.Connection) failoverConnection1).isMasterConnection());

        // Two different Connection objects should not equal each other:
        assertFalse(failoverConnection1.equals(failoverConnection2));

        int hc = failoverConnection1.hashCode();

        UnreliableSocketFactory.downHost("master");

        for (int i = 0; i < 3; i++) {
            try {
                failoverConnection1.createStatement().execute("SELECT 1");
            } catch (SQLException e) {
                // do nothing, expect SQLException when failing over initially goal here is to ensure valid connection against a slave
            }
        }
        // ensure we're now connected to the slave
        assertFalse(((com.mysql.jdbc.Connection) failoverConnection1).isMasterConnection());

        // ensure that hashCode() result is persistent across failover events when proxy state changes
        assertEquals(hc, failoverConnection1.hashCode());
    } finally {
        if (failoverConnection1 != null) {
            failoverConnection1.close();
        }
        if (failoverConnection2 != null) {
            failoverConnection2.close();
        }
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:60,代碼來源:ConnectionRegressionTest.java


注:本文中的java.sql.Connection.hashCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。