Search in sources :

Example 16 with ShardTbl

use of com.ctrip.xpipe.redis.console.model.ShardTbl in project x-pipe by ctripcorp.

the class ShardServiceImplTest2 method findOrCreateShardIfNotExist6.

// shard exist with diff monitor name
@Test(expected = java.lang.IllegalArgumentException.class)
public void findOrCreateShardIfNotExist6() throws Exception {
    String cluster = "cluster-test", shard = "shard1";
    ShardTbl proto = new ShardTbl().setShardName(shard).setSetinelMonitorName(shard);
    ShardTbl expected = new ShardTbl().setShardName("shard1").setSetinelMonitorName(cluster + "-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);
    try {
        ShardTbl shardTbl = shardService.findOrCreateShardIfNotExist(cluster, proto, Maps.newHashMap());
    } catch (Exception e) {
        Assert.assertEquals(String.format("Post shard monitor name %s diff from previous %s", shard, cluster + "-shard1"), e.getMessage());
        throw e;
    }
}
Also used : ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 17 with ShardTbl

use of com.ctrip.xpipe.redis.console.model.ShardTbl in project x-pipe by ctripcorp.

the class ShardServiceImplTest2 method findOrCreateShardIfNotExist3.

// monitor name exist both for shard and cluster-shard
@Test(expected = java.lang.IllegalStateException.class)
public void findOrCreateShardIfNotExist3() 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", cluster + "-" + proto.getShardName()));
    when(shardDao.insertShard(cluster, proto, Maps.newHashMap())).thenReturn(proto);
    try {
        ShardTbl shardTbl = shardService.findOrCreateShardIfNotExist(cluster, proto, Maps.newHashMap());
    } catch (IllegalStateException e) {
        Assert.assertEquals(String.format("Both %s and %s is assigned as sentinel monitor name", proto.getShardName(), cluster + "-" + proto.getShardName()), e.getMessage());
        throw e;
    }
}
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