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());
}
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());
}
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)));
}
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());
}
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());
}
Aggregations