use of com.ctrip.xpipe.redis.console.model.ShardTbl in project x-pipe by ctripcorp.
the class ShardServiceImplTest method testCreateShardEvent.
@Test
public void testCreateShardEvent() {
String sentinelAddress1 = "10.8.187.27:44400,10.8.187.28:44400,10.8.107.230:44400,10.8.107.169:44400,10.8.107.77:44400";
String sentinelAddress2 = "10.28.68.81:33355,10.28.68.82:33355,10.28.68.83:33355,10.8.107.198:33355,10.8.107.199:33355";
ShardTbl shardTbl = shardService.find(clusterName, shardNames[0]);
Map<Long, SetinelTbl> setinelTblMap = Maps.newHashMapWithExpectedSize(2);
setinelTblMap.put(1L, new SetinelTbl().setSetinelAddress(sentinelAddress1));
setinelTblMap.put(2L, new SetinelTbl().setSetinelAddress(sentinelAddress2));
ShardEvent shardEvent = shardService.createShardDeleteEvent(clusterName, shardNames[0], shardTbl, setinelTblMap);
Assert.assertTrue(shardEvent instanceof ShardDeleteEvent);
Assert.assertEquals(EventType.DELETE, shardEvent.getShardEventType());
Assert.assertEquals(clusterName, shardEvent.getClusterName());
Assert.assertEquals(shardNames[0], shardEvent.getShardName());
Assert.assertEquals(sentinelAddress1 + "," + sentinelAddress2, shardEvent.getShardSentinels());
System.out.println(shardEvent);
}
use of com.ctrip.xpipe.redis.console.model.ShardTbl in project x-pipe by ctripcorp.
the class MetaUpdateTest2 method addKeepers1.
@Test
public void addKeepers1() throws Exception {
String cluster = "cluster-test", shard = "shard-test", dc = "SHAJQ";
when(redisService.findKeepersByDcClusterShard(dc, cluster, shard)).thenReturn(null);
KeeperBasicInfo keeper1 = new KeeperBasicInfo();
KeeperBasicInfo keeper2 = new KeeperBasicInfo();
keeper1.setHost("127.0.0.1");
keeper1.setPort(6379);
keeper1.setKeeperContainerId(1);
keeper2.setHost("127.0.0.1");
keeper2.setPort(6380);
keeper2.setKeeperContainerId(1);
List<KeeperBasicInfo> keepers = Lists.newArrayList(keeper1, keeper2);
when(keeperAdvancedService.findBestKeepers(eq(dc), eq(RedisProtocol.REDIS_PORT_DEFAULT), any(), eq(cluster))).thenReturn(keepers);
when(redisService.insertKeepers(dc, cluster, shard, keepers)).thenReturn(2);
Assert.assertEquals(2, 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 testCheckingToMigrating.
@Test
public void testCheckingToMigrating() {
when(mockedMigrationShard.getCurrentShard()).thenReturn((new ShardTbl()).setShardName("test-shard"));
Assert.assertEquals(MigrationStatus.Initiated, migrationCluster.getStatus());
migrationCluster.updateStat(new MigrationMigratingState(migrationCluster));
Assert.assertEquals(MigrationStatus.Migrating, migrationCluster.getStatus());
migrationCluster.process();
sleep(100);
verify(mockedMigrationShard, times(1)).doMigrate();
}
use of com.ctrip.xpipe.redis.console.model.ShardTbl in project x-pipe by ctripcorp.
the class ClusterDeleteEventFactory method createClusterEvent.
@Override
public ClusterEvent createClusterEvent(String clusterName) {
ClusterDeleteEvent clusterDeleteEvent = new ClusterDeleteEvent(clusterName, executors);
List<ShardTbl> shardTbls = shardService.findAllByClusterName(clusterName);
if (shardTbls != null) {
for (ShardTbl shardTbl : shardTbls) {
logger.info("[createClusterEvent] Create Shard Delete Event: {}", shardTbl);
Map<Long, SetinelTbl> sentinelMap = sentinelService.findByShard(shardTbl.getId());
ShardDeleteEvent shardEvent = new ShardDeleteEvent(clusterName, shardTbl.getShardName(), executors);
shardEvent.setShardMonitorName(shardTbl.getSetinelMonitorName());
shardEvent.setShardSentinels(getShardSentinelAddress(sentinelMap));
shardDeleteEventListeners.forEach(shardDeleteEventListener -> shardEvent.addObserver(shardDeleteEventListener));
clusterDeleteEvent.addShardEvent(shardEvent);
}
}
clusterEventListeners.forEach(clusterDeleteEventListener -> clusterDeleteEvent.addObserver(clusterDeleteEventListener));
return clusterDeleteEvent;
}
use of com.ctrip.xpipe.redis.console.model.ShardTbl in project x-pipe by ctripcorp.
the class ShardServiceImplTest2 method findOrCreateShardIfNotExist5.
/**
*==========================================================================
* monitor name is posted
* ==========================================================================*
*/
// shard exist
@Test
public void findOrCreateShardIfNotExist5() throws Exception {
String cluster = "cluster-test", shard = "shard1";
ShardTbl proto = new ShardTbl().setShardName(shard).setSetinelMonitorName(shard);
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);
}
Aggregations