Search in sources :

Example 6 with MockDefaultHostConnection

use of com.ctrip.platform.dal.dao.base.MockDefaultHostConnection in project dal by ctripcorp.

the class MockMajorityHostValidator method validate.

@Override
protected ValidateResult validate(Connection connection, int clusterHostCount) throws SQLException {
    MockDefaultHostConnection mockDefaultHostConnection = (MockDefaultHostConnection) connection;
    HostSpec host = mockDefaultHostConnection.getHost();
    if (MysqlStatus.unknown.equals(mysqlServer.get(host)))
        throw new SQLException("");
    int onlineCount = 0;
    for (Map.Entry<HostSpec, MysqlStatus> entry : mysqlServer.entrySet()) {
        if (MysqlStatus.ok.equals(entry.getValue())) {
            onlineCount++;
        }
    }
    if (MysqlStatus.ok.equals(mysqlServer.get(host)) && 2 * onlineCount > mysqlServer.size()) {
        return new ValidateResult(true, "");
    } else {
        return new ValidateResult(false, "");
    }
}
Also used : MockDefaultHostConnection(com.ctrip.platform.dal.dao.base.MockDefaultHostConnection) SQLException(java.sql.SQLException) HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

MockDefaultHostConnection (com.ctrip.platform.dal.dao.base.MockDefaultHostConnection)6 Test (org.junit.Test)5 SQLException (java.sql.SQLException)3 HashMap (java.util.HashMap)2 HostSpec (com.ctrip.framework.dal.cluster.client.base.HostSpec)1 MockConnection (com.ctrip.platform.dal.dao.base.MockConnection)1 MockResultSet (com.ctrip.platform.dal.dao.base.MockResultSet)1 DefaultHostConnection (com.ctrip.platform.dal.dao.datasource.cluster.DefaultHostConnection)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Map (java.util.Map)1