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