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();
}
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;
}
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();
}
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());
}
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, "");
}
}
Aggregations