Search in sources :

Example 11 with ShardTbl

use of com.ctrip.xpipe.redis.console.model.ShardTbl in project x-pipe by ctripcorp.

the class MetaUpdateTest3 method createShard.

@Test
public void createShard() throws Exception {
    List<RedisCreateInfo> createInfo = createInfo(Lists.newArrayList("192.168.0.1:6379", "192.168.0.1:6380"), Lists.newArrayList("192.168.0.2:6379", "192.168.0.2:6380"));
    metaUpdate.createShard(clusterName, shardName, createInfo);
    ShardTbl shardTbl = shardService.find(clusterName, shardName);
    List<RedisTbl> keepers = redisService.findKeepersByDcClusterShard(activeDC, clusterName, shardName);
    List<RedisTbl> redisTbls = redisService.findRedisesByDcClusterShard(activeDC, clusterName, shardName);
    logger.info("{}", shardTbl);
    logger.info("{}", keepers);
    logger.info("{}", redisTbls);
    Assert.assertTrue(listEquals(Lists.newArrayList("192.168.0.1:6379", "192.168.0.1:6380"), redisTbls.stream().map((redisTbl) -> {
        return redisTbl.getRedisIp() + ":" + redisTbl.getRedisPort();
    }).collect(Collectors.toList())));
    Assert.assertEquals(2, keepers.size());
}
Also used : ShardCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo) RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) RedisCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.RedisCreateInfo) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) java.util.concurrent(java.util.concurrent) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) RetMessage(com.ctrip.xpipe.redis.console.controller.api.RetMessage) Collectors(java.util.stream.Collectors) ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) com.ctrip.xpipe.redis.console.service(com.ctrip.xpipe.redis.console.service) List(java.util.List) Lists(com.google.common.collect.Lists) ClusterCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.ClusterCreateInfo) StringUtil(com.ctrip.xpipe.utils.StringUtil) Assert(org.junit.Assert) Before(org.junit.Before) ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) RedisTbl(com.ctrip.xpipe.redis.console.model.RedisTbl) RedisCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.RedisCreateInfo) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 12 with ShardTbl

use of com.ctrip.xpipe.redis.console.model.ShardTbl in project x-pipe by ctripcorp.

the class ShardServiceTest method testShardService.

@Test
public void testShardService() {
    ShardTbl target_result = new ShardTbl().setId(1).setClusterId(1).setShardName("shard1");
    assertEquals(shardService.find("cluster1", "shard1").getId(), target_result.getId());
    assertEquals(shardService.find("cluster1", "shard1").getClusterId(), target_result.getClusterId());
    assertEquals(shardService.find("cluster1", "shard1").getShardName(), target_result.getShardName());
}
Also used : ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) Test(org.junit.Test) AbstractConsoleTest(com.ctrip.xpipe.redis.console.AbstractConsoleTest)

Example 13 with ShardTbl

use of com.ctrip.xpipe.redis.console.model.ShardTbl in project x-pipe by ctripcorp.

the class MetaUpdateTest2 method addKeepers2.

@Test
public void addKeepers2() throws Exception {
    String cluster = "cluster-test", shard = "shard-test", dc = "SHAJQ";
    when(redisService.findKeepersByDcClusterShard(dc, cluster, shard)).thenReturn(null);
    KeeperBasicInfo keeper1 = new KeeperBasicInfo();
    keeper1.setHost("127.0.0.1");
    keeper1.setPort(6379);
    keeper1.setKeeperContainerId(1);
    keepers = Lists.newArrayList(keeper1);
    when(keeperAdvancedService.findBestKeepers(eq(dc), eq(RedisProtocol.REDIS_PORT_DEFAULT), any(), eq(cluster))).thenReturn(keepers);
    when(redisService.insertKeepers(anyString(), anyString(), anyString(), eq(keepers))).thenReturn(2 - keepers.size());
    Assert.assertEquals(1, metaUpdate.addKeepers(dc, cluster, new ShardTbl().setShardName(shard)));
}
Also used : ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) KeeperBasicInfo(com.ctrip.xpipe.redis.console.service.KeeperBasicInfo) Test(org.junit.Test)

Example 14 with ShardTbl

use of com.ctrip.xpipe.redis.console.model.ShardTbl in project x-pipe by ctripcorp.

the class MigrationStatTest method prepareData.

private void prepareData() {
    mockedMigrationCluster = (new MigrationClusterTbl()).setId(1).setEventId(1).setClusterId(1).setDestinationDcId(2).setStatus(MigrationStatus.Initiated.toString());
    ClusterTbl clusterTbl = new ClusterTbl().setId(1).setClusterName("test-cluster").setActivedcId(1).setStatus(ClusterStatus.Lock.toString());
    when(mockedClusterService.find(1)).thenReturn(clusterTbl);
    List<ShardTbl> shards = new LinkedList<>();
    shards.add((new ShardTbl()).setId(1).setClusterId(1).setShardName("test-shard"));
    when(mockedShardService.findAllByClusterName("test-cluster")).thenReturn(shards);
    List<DcTbl> dcs = new LinkedList<>();
    dcs.add((new DcTbl()).setId(1).setDcName("ADC"));
    dcs.add((new DcTbl()).setId(2).setDcName("BDC"));
    when(mockedDcService.findClusterRelatedDc("test-cluster")).thenReturn(dcs);
    when(mockedClusterService.find(anyString())).thenReturn(clusterTbl);
    when(mockedClusterService.find(anyInt())).thenReturn(clusterTbl);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            clusterTbl.setStatus(((ClusterStatus) invocation.getArguments()[1]).toString());
            return null;
        }
    }).when(mockedClusterService).updateStatusById(anyInt(), any());
}
Also used : MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) LinkedList(java.util.LinkedList) Answer(org.mockito.stubbing.Answer) DcTbl(com.ctrip.xpipe.redis.console.model.DcTbl) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 15 with ShardTbl

use of com.ctrip.xpipe.redis.console.model.ShardTbl in project x-pipe by ctripcorp.

the class ShardServiceImplTest2 method findOrCreateShardIfNotExist2.

// monitor name not exist
@Test
public void findOrCreateShardIfNotExist2() throws Exception {
    ShardTbl proto = new ShardTbl().setShardName("shard2");
    String cluster = "cluster-test";
    when(shardDao.queryAllShardsByClusterName(anyString())).thenReturn(null);
    when(shardDao.queryAllShardMonitorNames()).thenReturn(Sets.newHashSet("shard1"));
    when(shardDao.insertShard(cluster, proto, Maps.newHashMap())).thenReturn(proto);
    ShardTbl shardTbl = shardService.findOrCreateShardIfNotExist(cluster, proto, Maps.newHashMap());
    Assert.assertEquals(proto.getShardName(), shardTbl.getSetinelMonitorName());
}
Also used : ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

ShardTbl (com.ctrip.xpipe.redis.console.model.ShardTbl)17 Test (org.junit.Test)15 Matchers.anyString (org.mockito.Matchers.anyString)7 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)3 RetMessage (com.ctrip.xpipe.redis.console.controller.api.RetMessage)3 ShardCreateInfo (com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo)3 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)2 ClusterCreateInfo (com.ctrip.xpipe.redis.console.controller.api.data.meta.ClusterCreateInfo)2 RedisCreateInfo (com.ctrip.xpipe.redis.console.controller.api.data.meta.RedisCreateInfo)2 RedisTbl (com.ctrip.xpipe.redis.console.model.RedisTbl)2 SetinelTbl (com.ctrip.xpipe.redis.console.model.SetinelTbl)2 ShardDeleteEvent (com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent)2 com.ctrip.xpipe.redis.console.service (com.ctrip.xpipe.redis.console.service)2 KeeperBasicInfo (com.ctrip.xpipe.redis.console.service.KeeperBasicInfo)2 StringUtil (com.ctrip.xpipe.utils.StringUtil)2 Lists (com.google.common.collect.Lists)2 List (java.util.List)2 java.util.concurrent (java.util.concurrent)2 Collectors (java.util.stream.Collectors)2 Assert (org.junit.Assert)2