use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class DcMetaTest method testKeeper.
@Test
public void testKeeper() {
KeeperMeta keeperMeta = new KeeperMeta().setIp("127.0.0.1").setPort(6379);
Codec codec = new JsonCodec(true);
String keeperMetaDesc = codec.encode(keeperMeta);
logger.info("{}", keeperMetaDesc);
KeeperMeta keeperMetaDec = codec.decode(keeperMetaDesc, KeeperMeta.class);
logger.info("{}", keeperMetaDec);
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class AddKeeperCommandTest method testCheckStateCommandNoDelay.
@Test
public void testCheckStateCommandNoDelay() throws Exception {
int sleepTime = 2000;
SlaveRole keeperRole = new SlaveRole(SERVER_ROLE.KEEPER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECTED, 0);
Server server = startServer(keeperPort, new Callable<String>() {
@Override
public String call() throws Exception {
sleep(sleepTime);
return ByteBufUtils.readToString(keeperRole.format());
}
});
SettableFuture<Boolean> objectSettableFuture = SettableFuture.create();
executors.execute(new AbstractExceptionLogTask() {
@Override
public void doRun() throws Exception {
AddKeeperCommand.CheckStateCommand checkStateCommand = new AddKeeperCommand.CheckStateCommand(new KeeperMeta().setIp("127.0.0.1").setPort(server.getPort()), scheduled);
checkStateCommand.doExecute();
objectSettableFuture.set(true);
}
});
// should return immediately
objectSettableFuture.get(500, TimeUnit.MILLISECONDS);
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class DeleteKeeperCommandTest method testDeleteWaitTimeoutThenSuccess.
@Test
public void testDeleteWaitTimeoutThenSuccess() throws Exception {
List<KeeperMeta> keepers = new LinkedList<>();
keepers.add(keeperMeta);
final Server server = startEchoServer(keeperMeta.getPort());
scheduled.schedule(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
LifecycleHelper.stopIfPossible(server);
LifecycleHelper.disposeIfPossible(server);
}
}, checkIntervalMili / 2, TimeUnit.MILLISECONDS);
deleteKeeperCommand.execute().get();
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class DeleteKeeperCommandTest method beforeDeleteKeeperCommandTest.
@Before
public void beforeDeleteKeeperCommandTest() {
keeperMeta = new KeeperMeta();
keeperMeta.setIp("localhost");
keeperMeta.setPort(randomPort());
deleteKeeperCommand = new DeleteKeeperCommand(keeperContainerService, new KeeperTransMeta(clusterId, shardId, keeperMeta), scheduled, timeoutMilli, checkIntervalMili);
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class DefaultKeeperElectorManagerTest method addKeeperZkNode.
private void addKeeperZkNode(String clusterId, String shardId, ZkClient zkClient, int idLen) throws Exception {
String leaderElectionZKPath = MetaZkConfig.getKeeperLeaderLatchPath(clusterId, shardId);
String leaderElectionID;
if (idLen == 0) {
leaderElectionID = MetaZkConfig.getKeeperLeaderElectionId(new KeeperMeta());
} else {
leaderElectionID = MetaZkConfig.getKeeperLeaderElectionId(new KeeperMeta().setId(randomString(idLen)));
}
ElectContext ctx = new ElectContext(leaderElectionZKPath, leaderElectionID);
LeaderElector leaderElector = new DefaultLeaderElector(ctx, zkClient.get());
leaderElector.elect();
}
Aggregations