use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class ConsoleNotifycationTaskTest method testException.
@Test
public void testException() throws Exception {
ConsoleNotifycationTask task = new ConsoleNotifycationTask(100);
task.initialize();
task.setConsoleService(consoleService);
doThrow(new Exception()).when(consoleService).keeperActiveChanged(anyString(), anyString(), anyString(), (KeeperMeta) anyObject());
task.keeperActiveElected("cluster1", "shard1", new KeeperMeta());
sleep(300);
verify(consoleService, atLeast(2)).keeperActiveChanged(anyString(), anyString(), anyString(), any(KeeperMeta.class));
task.dispose();
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class MetaInfoChange method testGetKeeperActive.
@Test
public void testGetKeeperActive() {
KeeperMeta keeperMeta = metaServerMultiDcService.getActiveKeeper(clusterId, shardId);
logger.info("[testGetKeeperActive]{}, {}, {}", clusterId, shardId, keeperMeta);
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class BackupDcKeeperMasterChooserAlgorithmTest method testGetUpstream.
@Test
public void testGetUpstream() throws Exception {
backupAlgorithm.choose();
verify(multiDcService, atLeast(1)).getActiveKeeper(primaryDc, clusterId, shardId);
logger.info("[testGetUpstream][getActiveKeeper give a result]");
KeeperMeta keeperMeta = new KeeperMeta();
keeperMeta.setIp("localhost");
keeperMeta.setPort(randomPort());
when(multiDcService.getActiveKeeper(primaryDc, clusterId, shardId)).thenReturn(keeperMeta);
Assert.assertEquals(new Pair<>(keeperMeta.getIp(), keeperMeta.getPort()), backupAlgorithm.choose());
verify(multiDcService, atLeast(1)).getActiveKeeper(primaryDc, clusterId, shardId);
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class CurrentMetaTest method testToString.
@Test
public void testToString() {
List<KeeperMeta> allKeepers = getDcKeepers(getDc(), clusterId, shardId);
currentMeta.setSurviveKeepers(clusterId, shardId, allKeepers, allKeepers.get(0));
currentMeta.addResource(clusterId, shardId, new Releasable() {
@Override
public void release() throws Exception {
}
});
String json = currentMeta.toString();
CurrentMeta de = CurrentMeta.fromJson(json);
Assert.assertEquals(json, de.toString());
Assert.assertTrue(currentMeta.hasCluster(clusterId));
for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
Assert.assertTrue(currentMeta.hasShard(clusterId, shardMeta.getId()));
}
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class DefaultKeeperElectorManagerTest method testUpdateShardLeader.
@Test
public void testUpdateShardLeader() {
String prefix = "/path";
List<ChildData> dataList = new LinkedList<>();
final int portBegin = 4000;
final int count = 3;
dataList.add(new ChildData(prefix + "/" + randomString(10) + "-latch-02", null, JsonCodec.INSTANCE.encodeAsBytes(new KeeperMeta().setId("127.0.0.1").setPort(portBegin + 1))));
dataList.add(new ChildData(prefix + "/" + randomString(10) + "-latch-03", null, JsonCodec.INSTANCE.encodeAsBytes(new KeeperMeta().setId("127.0.0.1").setPort(portBegin + 2))));
dataList.add(new ChildData(prefix + "/" + randomString(10) + "-latch-01", null, JsonCodec.INSTANCE.encodeAsBytes(new KeeperMeta().setId("127.0.0.1").setPort(portBegin))));
keeperElectorManager.updateShardLeader(prefix, dataList, clusterMeta.getId(), shardMeta.getId());
verify(keeperActiveElectAlgorithm).select(eq(clusterMeta.getId()), eq(shardMeta.getId()), argThat(new BaseMatcher<List<KeeperMeta>>() {
@Override
public boolean matches(Object item) {
List<KeeperMeta> keepers = (List<KeeperMeta>) item;
if (keepers.size() != count) {
return false;
}
KeeperMeta prefix = null;
for (KeeperMeta keeperMeta : keepers) {
if (prefix != null) {
if (keeperMeta.getPort() < prefix.getPort()) {
return false;
}
}
prefix = keeperMeta;
}
return true;
}
@Override
public void describeTo(Description description) {
}
}));
}
Aggregations