Search in sources :

Example 1 with ShardTbl

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);
}
Also used : ShardEvent(com.ctrip.xpipe.redis.console.notifier.shard.ShardEvent) ShardDeleteEvent(com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent) ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) SetinelTbl(com.ctrip.xpipe.redis.console.model.SetinelTbl) Test(org.junit.Test)

Example 2 with ShardTbl

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)));
}
Also used : ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) KeeperBasicInfo(com.ctrip.xpipe.redis.console.service.KeeperBasicInfo) Test(org.junit.Test)

Example 3 with ShardTbl

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();
}
Also used : ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) MigrationMigratingState(com.ctrip.xpipe.redis.console.migration.status.migration.MigrationMigratingState) Test(org.junit.Test) AbstractConsoleTest(com.ctrip.xpipe.redis.console.AbstractConsoleTest)

Example 4 with ShardTbl

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;
}
Also used : ShardDeleteEvent(com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent) ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) SetinelTbl(com.ctrip.xpipe.redis.console.model.SetinelTbl)

Example 5 with ShardTbl

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