Search in sources :

Example 1 with ShardCreateInfo

use of com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo in project x-pipe by ctripcorp.

the class MetaUpdateTest3 method createShard3.

@Test
public void createShard3() throws Exception {
    ShardCreateInfo shardCreateInfo1 = new ShardCreateInfo();
    shardCreateInfo1.setShardMonitorName(shardName);
    shardCreateInfo1.setShardName(shardName + 1);
    ShardCreateInfo shardCreateInfo2 = new ShardCreateInfo();
    shardCreateInfo2.setShardMonitorName(clusterName + "-" + shardName);
    shardCreateInfo2.setShardName(shardName + 2);
    metaUpdate.createShards(clusterName, Lists.newArrayList(shardCreateInfo1, shardCreateInfo2));
    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"));
    RetMessage result = metaUpdate.createShard(clusterName, shardName, createInfo);
    Assert.assertEquals(RetMessage.FAIL_STATE, result.getState());
    Assert.assertEquals(String.format("Both %s and %s is assigned as sentinel monitor name", shardName, clusterName + "-" + shardName), result.getMessage());
}
Also used : ShardCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo) RetMessage(com.ctrip.xpipe.redis.console.controller.api.RetMessage) RedisCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.RedisCreateInfo) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 2 with ShardCreateInfo

use of com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo in project x-pipe by ctripcorp.

the class MetaUpdateTest3 method createShard1.

@Test
public void createShard1() throws Exception {
    ShardCreateInfo shardCreateInfo = new ShardCreateInfo();
    shardCreateInfo.setShardMonitorName(shardName);
    shardCreateInfo.setShardName(shardName);
    metaUpdate.createShards(clusterName, Lists.newArrayList(new ShardCreateInfo()));
    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) ShardCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo) RedisCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.RedisCreateInfo) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 3 with ShardCreateInfo

use of com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo in project x-pipe by ctripcorp.

the class MetaUpdateTest3 method createShard4.

@Test
public void createShard4() throws Exception {
    ShardCreateInfo shardCreateInfo1 = new ShardCreateInfo();
    shardCreateInfo1.setShardMonitorName(shardName);
    shardCreateInfo1.setShardName(shardName);
    metaUpdate.createShards(clusterName, Lists.newArrayList(shardCreateInfo1));
    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"));
    RetMessage result = metaUpdate.createShard(clusterName, shardName, createInfo);
    Assert.assertEquals(RetMessage.SUCCESS_STATE, result.getState());
}
Also used : ShardCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo) RetMessage(com.ctrip.xpipe.redis.console.controller.api.RetMessage) RedisCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.RedisCreateInfo) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 4 with ShardCreateInfo

use of com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo in project x-pipe by ctripcorp.

the class MetaUpdateTest3 method createShard2.

@Test
public void createShard2() throws Exception {
    ShardCreateInfo shardCreateInfo = new ShardCreateInfo();
    shardCreateInfo.setShardMonitorName(shardName);
    shardCreateInfo.setShardName(shardName);
    metaUpdate.createShards(clusterName, Lists.newArrayList(shardCreateInfo));
    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"));
    RetMessage result = metaUpdate.createShard(clusterName, shardName, clusterName + "-" + shardName, createInfo);
    Assert.assertEquals(RetMessage.FAIL_STATE, result.getState());
    Assert.assertEquals(String.format("Post shard monitor name %s diff from previous %s", clusterName + "-" + shardName, shardName), result.getMessage());
}
Also used : ShardCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo) RetMessage(com.ctrip.xpipe.redis.console.controller.api.RetMessage) RedisCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.RedisCreateInfo) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 5 with ShardCreateInfo

use of com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo in project x-pipe by ctripcorp.

the class MetaUpdateTest3 method createShard6.

@Test
public void createShard6() throws Exception {
    int taskNum = 3;
    ThreadPoolExecutor executorService = new ThreadPoolExecutor(taskNum, taskNum, 1L, TimeUnit.SECONDS, new SynchronousQueue<>());
    executorService.prestartAllCoreThreads();
    executorService.allowsCoreThreadTimeOut();
    for (int i = 0; i < taskNum; i++) {
        executorService.execute(new Runnable() {

            @Override
            public void run() {
                ShardCreateInfo shardCreateInfo = new ShardCreateInfo();
                shardCreateInfo.setShardMonitorName(shardName);
                shardCreateInfo.setShardName(shardName);
                RetMessage result = metaUpdate.createShards(clusterName, Lists.newArrayList(shardCreateInfo));
                logger.info("{}", result);
            }
        });
    }
    waitConditionUntilTimeOut(() -> executorService.getCompletedTaskCount() == taskNum, 2000);
    System.out.println("=========================");
    List<ShardTbl> shards = shardService.findAllByClusterName(clusterName);
    logger.info("{}", shards);
    Assert.assertEquals(1, shards.size());
}
Also used : ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) ShardCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo) RetMessage(com.ctrip.xpipe.redis.console.controller.api.RetMessage) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Aggregations

AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)5 RetMessage (com.ctrip.xpipe.redis.console.controller.api.RetMessage)5 ShardCreateInfo (com.ctrip.xpipe.redis.console.controller.api.data.meta.ShardCreateInfo)5 Test (org.junit.Test)5 RedisCreateInfo (com.ctrip.xpipe.redis.console.controller.api.data.meta.RedisCreateInfo)4 ShardTbl (com.ctrip.xpipe.redis.console.model.ShardTbl)2 ClusterCreateInfo (com.ctrip.xpipe.redis.console.controller.api.data.meta.ClusterCreateInfo)1 RedisTbl (com.ctrip.xpipe.redis.console.model.RedisTbl)1 com.ctrip.xpipe.redis.console.service (com.ctrip.xpipe.redis.console.service)1 StringUtil (com.ctrip.xpipe.utils.StringUtil)1 Lists (com.google.common.collect.Lists)1 List (java.util.List)1 java.util.concurrent (java.util.concurrent)1 Collectors (java.util.stream.Collectors)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1