Search in sources :

Example 76 with HostPort

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());
}
Also used : ClusterListClusterModel(com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel) HostPort(com.ctrip.xpipe.endpoint.HostPort) Test(org.junit.Test)

Example 77 with HostPort

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());
}
Also used : Function(com.google.common.base.Function) ClusterListClusterModel(com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HostPort(com.ctrip.xpipe.endpoint.HostPort) List(java.util.List) Matchers.anyList(org.mockito.Matchers.anyList) Test(org.junit.Test)

Example 78 with HostPort

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)));
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) Test(org.junit.Test)

Example 79 with HostPort

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;
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) XpipeMetaManager(com.ctrip.xpipe.redis.core.meta.XpipeMetaManager)

Aggregations

HostPort (com.ctrip.xpipe.endpoint.HostPort)79 Test (org.junit.Test)31 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)7 LinkedList (java.util.LinkedList)7 ALERT_TYPE (com.ctrip.xpipe.redis.console.alert.ALERT_TYPE)6 MasterInfo (com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo)6 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)6 ClusterShardHostPort (com.ctrip.xpipe.endpoint.ClusterShardHostPort)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Map (java.util.Map)5 RedisConf (com.ctrip.xpipe.redis.console.health.redisconf.RedisConf)4 MasterNotFoundException (com.ctrip.xpipe.redis.console.resources.MasterNotFoundException)4 XpipeMetaManager (com.ctrip.xpipe.redis.core.meta.XpipeMetaManager)4 Set (java.util.Set)4 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)3 AlertEntity (com.ctrip.xpipe.redis.console.alert.AlertEntity)3 AlertManager (com.ctrip.xpipe.redis.console.alert.AlertManager)3 DefaultRedisSessionManager (com.ctrip.xpipe.redis.console.health.DefaultRedisSessionManager)3 ClusterListClusterModel (com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel)3