use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class DefaultSlaveOfJobTest method testSlavesSuccess.
@Test
public void testSlavesSuccess() throws Exception {
List<RedisMeta> slaves = new LinkedList<>();
List<Integer> ports = new LinkedList<>(randomPorts(2));
slaves.add(new RedisMeta().setIp("localhost").setPort(ports.get(0)));
slaves.add(new RedisMeta().setIp("localhost").setPort(ports.get(1)));
startServer(ports.get(0), "+OK\r\n");
startServer(ports.get(1), "+OK\r\n");
Command<Void> command = new DefaultSlaveOfJob(slaves, "localhost", randomPort(), getXpipeNettyClientKeyedObjectPool(), scheduled, executors);
command.execute().get(1, TimeUnit.SECONDS);
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class FirstNewMasterChooserTest method testRedis.
// run with real redis
// @Test
public void testRedis() {
redises.clear();
redises.add(new RedisMeta().setIp("localhost").setPort(6379));
redises.add(new RedisMeta().setIp("localhost").setPort(6479));
logger.info("{}", firstNewMasterChooser.choose(redises));
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class FirstNewMasterChooserTest method testSort.
@Test
public void testSort() {
int allCount = 5;
List<RedisMeta> redisMetas = new LinkedList<>();
for (int i = 0; i < allCount; i++) {
redisMetas.add(new RedisMeta().setPort(i));
}
Assert.assertEquals(0, firstNewMasterChooser.sortAccording(redisMetas, new LinkedList<>()).size());
List<RedisMeta> alive = new LinkedList<>();
for (int i = 4; i >= 2; i--) {
alive.add(redisMetas.get(i));
}
List<RedisMeta> sorted = firstNewMasterChooser.sortAccording(redisMetas, alive);
Assert.assertEquals(3, sorted.size());
RedisMeta previous = null;
for (RedisMeta redis : sorted) {
if (previous != null) {
Assert.assertTrue(redis.getPort() > previous.getPort());
}
previous = redis;
}
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class PrimaryDcKeeperMasterChooserAlgorithmTest method testOneMaster.
@Test
public void testOneMaster() throws Exception {
SlaveRole role = new SlaveRole(SERVER_ROLE.MASTER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECT, 0L);
RedisMeta chosen = redises.get(0);
startServer(chosen.getPort(), ByteBufUtils.readToString(role.format()));
when(currentMetaManager.getKeeperMaster(clusterId, shardId)).thenReturn(null);
Assert.assertEquals(new Pair<String, Integer>(chosen.getIp(), chosen.getPort()), primaryAlgorithm.choose());
for (RedisMeta redisMeta : redises) {
when(currentMetaManager.getKeeperMaster(clusterId, shardId)).thenReturn(new Pair<String, Integer>(redisMeta.getIp(), redisMeta.getPort()));
Assert.assertEquals(new Pair<String, Integer>(chosen.getIp(), chosen.getPort()), primaryAlgorithm.choose());
}
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class PrimaryDcKeeperMasterChooserAlgorithmTest method befoePrimaryDcKeeperMasterChooserTest.
@Before
public void befoePrimaryDcKeeperMasterChooserTest() throws Exception {
primaryAlgorithm = new PrimaryDcKeeperMasterChooserAlgorithm(clusterId, shardId, dcMetaCache, currentMetaManager, getXpipeNettyClientKeyedObjectPool(), 1, scheduled);
redises = new LinkedList<>();
int port1 = randomPort();
redises.add(new RedisMeta().setIp("localhost").setPort(port1));
redises.add(new RedisMeta().setIp("localhost").setPort(randomPort(Sets.newHashSet(port1))));
when(dcMetaCache.getShardRedises(clusterId, shardId)).thenReturn(redises);
when(dcMetaCache.isCurrentDcPrimary(clusterId, shardId)).thenReturn(true);
}
Aggregations