Search in sources :

Example 26 with HostSpec

use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.

the class OBStrategyTest method pickNode.

@Test
public void pickNode() {
    HostSpec hostSpec1 = routeStrategy.pickNode(dalHints);
    // pick from local
    Assert.assertEquals(getRequestZone(), hostSpec1.zone());
    HostSpec hostSpec2 = routeStrategy.pickNode(dalHints);
    // pick from local
    Assert.assertEquals(getRequestZone(), hostSpec2.zone());
    Assert.assertNotEquals(hostSpec1, hostSpec2);
    routeStrategy.dispose();
}
Also used : HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec) Test(org.junit.Test)

Example 27 with HostSpec

use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.

the class MultiHostDataSourceTest method mockDataSourceConfigs.

private Map<HostSpec, DataSourceConfigure> mockDataSourceConfigs() {
    Map<HostSpec, DataSourceConfigure> dataSourceConfigs = new HashMap<>();
    HostSpec host1 = HostSpec.of("10.32.20.117", 3306, "zone1");
    dataSourceConfigs.put(host1, mockDataSourceConfig(host1));
    HostSpec host2 = HostSpec.of("dst56614", 3306, "zone2");
    dataSourceConfigs.put(host2, mockDataSourceConfig(host2));
    HostSpec host3 = HostSpec.of("10.32.20.5", 3308, "zone3");
    dataSourceConfigs.put(host3, mockDataSourceConfig(host3));
    return dataSourceConfigs;
}
Also used : HashMap(java.util.HashMap) HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec) DataSourceConfigure(com.ctrip.platform.dal.dao.configure.DataSourceConfigure)

Example 28 with HostSpec

use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.

the class RoundRobinAccessStrategyTest method pickNode_1.

@Test
public void pickNode_1() {
    routeStrategy.init(shardMeta.configuredHosts(), caseInsensitiveProperties);
    HostSpec hostSpec = routeStrategy.pickNode(dalHints);
    // pick from local
    Assert.assertEquals(getRequestZone(), hostSpec.zone());
    HostSpec hostSpec1 = routeStrategy.pickNode(dalHints);
    // pick from local
    Assert.assertEquals(getRequestZone(), hostSpec1.zone());
    HostSpec hostSpec2 = routeStrategy.pickNode(dalHints);
    // pick from local
    Assert.assertEquals(hostSpec, hostSpec2);
    HostSpec hostSpec3 = routeStrategy.pickNode(dalHints);
    // pick from local
    Assert.assertEquals(hostSpec1, hostSpec3);
    routeStrategy.dispose();
}
Also used : HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec) Test(org.junit.Test)

Example 29 with HostSpec

use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.

the class ZonedHostSorterTest method testSort.

@Test
public void testSort() {
    ZonedHostSorter sorter = new ZonedHostSorter("0", "a", "b", "c");
    HostSpec host1 = HostSpec.of("ip1", 0, "c");
    HostSpec host2 = HostSpec.of("ip2", 0, "b");
    HostSpec host3 = HostSpec.of("ip3", 0, "b");
    HostSpec host4 = HostSpec.of("ip4", 0, "a");
    HostSpec host5 = HostSpec.of("ip5", 0, "x");
    List<HostSpec> sorted = sorter.sort(new HashSet<>(Arrays.asList(host1, host2, host3, host4, host5)));
    Assert.assertEquals(4, sorted.size());
    Assert.assertEquals("ip4", sorted.get(0).host());
    Assert.assertEquals("ip2", sorted.get(1).host());
    Assert.assertEquals("ip3", sorted.get(2).host());
    Assert.assertEquals("ip1", sorted.get(3).host());
}
Also used : HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec) Test(org.junit.Test)

Example 30 with HostSpec

use of com.ctrip.framework.dal.cluster.client.base.HostSpec 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

HostSpec (com.ctrip.framework.dal.cluster.client.base.HostSpec)30 Test (org.junit.Test)11 DalMetadataException (com.ctrip.framework.dal.cluster.client.exception.DalMetadataException)5 SQLException (java.sql.SQLException)5 ConnectionString (com.ctrip.framework.dal.cluster.client.database.ConnectionString)3 Database (com.ctrip.framework.dal.cluster.client.database.Database)3 DalHints (com.ctrip.platform.dal.dao.DalHints)3 HashMap (java.util.HashMap)3 DataSourceConfigure (com.ctrip.platform.dal.dao.configure.DataSourceConfigure)2 RouteStrategy (com.ctrip.platform.dal.dao.datasource.cluster.strategy.RouteStrategy)2 Connection (java.sql.Connection)2 Map (java.util.Map)2 DatabaseConfigImpl (com.ctrip.framework.dal.cluster.client.config.DatabaseConfigImpl)1 DatabaseShardConfigImpl (com.ctrip.framework.dal.cluster.client.config.DatabaseShardConfigImpl)1 CustomDataSourceFactory (com.ctrip.framework.dal.cluster.client.extended.CustomDataSourceFactory)1 ClusterRouteStrategyConfig (com.ctrip.framework.dal.cluster.client.multihost.ClusterRouteStrategyConfig)1 DefaultClusterRouteStrategyConfig (com.ctrip.framework.dal.cluster.client.multihost.DefaultClusterRouteStrategyConfig)1 ReadCurrentZoneSlavesFirstStrategyTest (com.ctrip.framework.dal.cluster.client.shard.read.ReadCurrentZoneSlavesFirstStrategyTest)1 ReadCurrentZoneSlavesFirstStrategyTest.produceHostSpec (com.ctrip.framework.dal.cluster.client.shard.read.ReadCurrentZoneSlavesFirstStrategyTest.produceHostSpec)1 CaseInsensitiveProperties (com.ctrip.framework.dal.cluster.client.util.CaseInsensitiveProperties)1