Search in sources :

Example 11 with KeeperMeta

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);
}
Also used : Codec(com.ctrip.xpipe.api.codec.Codec) JsonCodec(com.ctrip.xpipe.codec.JsonCodec) JsonCodec(com.ctrip.xpipe.codec.JsonCodec) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

Example 12 with KeeperMeta

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);
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) ExecutionException(java.util.concurrent.ExecutionException) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 13 with KeeperMeta

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();
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) LinkedList(java.util.LinkedList) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 14 with KeeperMeta

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);
}
Also used : KeeperTransMeta(com.ctrip.xpipe.redis.core.entity.KeeperTransMeta) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Before(org.junit.Before)

Example 15 with KeeperMeta

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();
}
Also used : ElectContext(com.ctrip.xpipe.cluster.ElectContext) DefaultLeaderElector(com.ctrip.xpipe.cluster.DefaultLeaderElector) LeaderElector(com.ctrip.xpipe.api.cluster.LeaderElector) DefaultLeaderElector(com.ctrip.xpipe.cluster.DefaultLeaderElector) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Aggregations

KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)50 Test (org.junit.Test)28 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)9 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)8 KeeperTransMeta (com.ctrip.xpipe.redis.core.entity.KeeperTransMeta)6 LinkedList (java.util.LinkedList)6 AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)4 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)4 KeeperStateChangeJob (com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob)4 InetSocketAddress (java.net.InetSocketAddress)4 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)3 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)3 ShardStatus (com.ctrip.xpipe.redis.core.meta.ShardStatus)3 Before (org.junit.Before)3 RedisKeeperServerState (com.ctrip.xpipe.redis.keeper.RedisKeeperServerState)2 DefaultSlaveOfJob (com.ctrip.xpipe.redis.meta.server.job.DefaultSlaveOfJob)2 Server (com.ctrip.xpipe.simpleserver.Server)2 Pair (com.ctrip.xpipe.tuple.Pair)2 ExecutionException (java.util.concurrent.ExecutionException)2 ChildData (org.apache.curator.framework.recipes.cache.ChildData)2