use of com.ctrip.xpipe.redis.console.model.ShardTbl in project x-pipe by ctripcorp.
the class ShardServiceImplTest2 method findOrCreateShardIfNotExist1.
/**
*==========================================================================
* no monitor name is posted
* ==========================================================================*
*/
// monitor name exist, no shard exist
@Test
public void findOrCreateShardIfNotExist1() throws Exception {
ShardTbl proto = new ShardTbl().setShardName("shard1");
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(cluster + "-" + proto.getShardName(), shardTbl.getSetinelMonitorName());
}
use of com.ctrip.xpipe.redis.console.model.ShardTbl in project x-pipe by ctripcorp.
the class ShardServiceImplTest2 method findOrCreateShardIfNotExist4.
// shard exist
@Test
public void findOrCreateShardIfNotExist4() throws Exception {
ShardTbl proto = new ShardTbl().setShardName("shard1");
String cluster = "cluster-test";
ShardTbl expected = new ShardTbl().setShardName("shard1").setSetinelMonitorName("shard1");
when(shardDao.queryAllShardsByClusterName(cluster)).thenReturn(Lists.newArrayList(expected));
when(shardDao.queryAllShardMonitorNames()).thenReturn(Sets.newHashSet("shard1", cluster + "-" + proto.getShardName()));
when(shardDao.insertShard(cluster, proto, Maps.newHashMap())).thenReturn(proto);
ShardTbl shardTbl = shardService.findOrCreateShardIfNotExist(cluster, proto, Maps.newHashMap());
Assert.assertTrue(expected == shardTbl);
}
use of com.ctrip.xpipe.redis.console.model.ShardTbl in project x-pipe by ctripcorp.
the class ShardServiceImplTest2 method findOrCreateShardIfNotExist7.
// shard not exist, but monitor name has been occupied by other shard
@Test(expected = java.lang.IllegalArgumentException.class)
public void findOrCreateShardIfNotExist7() throws Exception {
String cluster = "cluster-test", shard = "shard1";
ShardTbl proto = new ShardTbl().setShardName(shard).setSetinelMonitorName(shard);
when(shardDao.queryAllShardsByClusterName(cluster)).thenReturn(Lists.newArrayList());
when(shardDao.queryAllShardMonitorNames()).thenReturn(Sets.newHashSet("shard1", cluster + "-" + proto.getShardName()));
when(shardDao.insertShard(cluster, proto, Maps.newHashMap())).thenReturn(proto);
try {
ShardTbl shardTbl = shardService.findOrCreateShardIfNotExist(cluster, proto, Maps.newHashMap());
} catch (Exception e) {
Assert.assertEquals(String.format("Shard monitor name %s already exist", shard), e.getMessage());
throw e;
}
}
use of com.ctrip.xpipe.redis.console.model.ShardTbl 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());
}
use of com.ctrip.xpipe.redis.console.model.ShardTbl 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());
}
Aggregations