use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.
the class ClusterServiceImplTest2 method testFindUnhealthyClusters.
@Test
public void testFindUnhealthyClusters() throws Exception {
when(delayService.getDelay(any())).thenReturn(10L);
when(delayService.getDelay(new HostPort("127.0.0.2", 6379))).thenReturn(DefaultDelayMonitor.SAMPLE_LOST_BUT_PONG);
when(clusterDao.findClustersWithName(Lists.newArrayList("cluster1"))).thenReturn(Lists.newArrayList(new ClusterTbl().setClusterName("cluster1")));
List<ClusterListClusterModel> clusterTbls = clusterService.findUnhealthyClusters();
Assert.assertEquals(1, clusterTbls.size());
Assert.assertEquals("cluster1", clusterTbls.get(0).getClusterName());
}
use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.
the class ClusterServiceImplTest2 method testFindUnhealthyClusters2.
@Test
public void testFindUnhealthyClusters2() throws Exception {
when(delayService.getDelay(any())).thenReturn(10L);
when(delayService.getDelay(new HostPort("127.0.0.2", 6379))).thenReturn(DefaultDelayMonitor.SAMPLE_LOST_BUT_PONG);
when(delayService.getDelay(new HostPort("127.0.0.4", 6380))).thenReturn(DefaultDelayMonitor.SAMPLE_LOST_AND_NO_PONG);
when(clusterDao.findClustersWithName(anyList())).then(new Answer<List<ClusterTbl>>() {
@Override
public List<ClusterTbl> answer(InvocationOnMock invocation) throws Throwable {
List<String> clusterNames = (List<String>) invocation.getArguments()[0];
return Lists.transform(clusterNames, new Function<String, ClusterTbl>() {
@Override
public ClusterTbl apply(String input) {
return new ClusterTbl().setClusterName(input);
}
});
}
});
List<ClusterListClusterModel> clusterTbls = clusterService.findUnhealthyClusters();
Assert.assertEquals(2, clusterTbls.size());
Assert.assertEquals("cluster1", clusterTbls.get(0).getClusterName());
Assert.assertEquals("cluster2", clusterTbls.get(1).getClusterName());
}
use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.
the class KeeperServiceImplTest method testIsKeeper.
@Test
public void testIsKeeper() throws Exception {
when(metaCache.allKeepers()).thenReturn(Collections.singleton(new HostPort("127.0.0.1", 6379)));
HostPort hostPort = new HostPort("127.0.0.1", 6379);
Assert.assertTrue(keeperService.isKeeper(hostPort));
Assert.assertFalse(keeperService.isKeeper(new HostPort("128.0.0.1", 6380)));
}
use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.
the class InverseHostPortMapBuilder method build.
public static Map<HostPort, XpipeMetaManager.MetaDesc> build(XpipeMeta xpipeMeta) {
logger.info("build reverse map");
Map<HostPort, XpipeMetaManager.MetaDesc> result = new ConcurrentHashMap();
xpipeMeta.getDcs().forEach((dc, dcMeta) -> {
dcMeta.getClusters().forEach((clusterId, clusterMeta) -> {
clusterMeta.getShards().forEach((shardId, shardMeta) -> {
for (RedisMeta redisMeta : shardMeta.getRedises()) {
result.put(new HostPort(redisMeta.getIp(), redisMeta.getPort()), new XpipeMetaManager.MetaDesc(dcMeta, clusterMeta, shardMeta, redisMeta));
}
for (KeeperMeta keeperMeta : shardMeta.getKeepers()) {
result.put(new HostPort(keeperMeta.getIp(), keeperMeta.getPort()), new XpipeMetaManager.MetaDesc(dcMeta, clusterMeta, shardMeta, keeperMeta));
}
});
});
});
return result;
}
Aggregations