Search in sources :

Example 1 with DefaultRedisKeeperServer

use of com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer in project x-pipe by ctripcorp.

the class XRedisPartialTest method createRedisKeeperServer.

@Override
protected RedisKeeperServer createRedisKeeperServer(KeeperMeta keeperMeta, File baseDir, KeeperConfig keeperConfig, MetaServerKeeperService metaService, LeaderElectorManager leaderElectorManager, KeepersMonitorManager keeperMonitorManager) {
    return new DefaultRedisKeeperServer(keeperMeta, keeperConfig, baseDir, metaService, leaderElectorManager, keeperMonitorManager) {

        private int count = 0;

        @Override
        public RedisKeeperServerState getRedisKeeperServerState() {
            RedisKeeperServerState redisKeeperServerState = super.getRedisKeeperServerState();
            return (RedisKeeperServerState) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { RedisKeeperServerState.class }, new InvocationHandler() {

                @Override
                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                    if (method.getName().equals("psync")) {
                        count++;
                        logger.info("[psync][count]{}, {}", args, count);
                        if (count == 2) {
                            RedisClient redisClient = (RedisClient) args[0];
                            logger.info("[psync][close client]{}, {}", count, redisClient);
                            redisClient.close();
                        }
                    }
                    return method.invoke(redisKeeperServerState, args);
                }
            });
        }
    };
}
Also used : RedisKeeperServerState(com.ctrip.xpipe.redis.keeper.RedisKeeperServerState) RedisClient(com.ctrip.xpipe.redis.keeper.RedisClient) DefaultRedisKeeperServer(com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 2 with DefaultRedisKeeperServer

use of com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer in project x-pipe by ctripcorp.

the class DefaultRedisKeeperServerConnectToFakeRedisTest method testDumpWhileWaitForRdb.

@Test
public void testDumpWhileWaitForRdb() throws Exception {
    int sleepBeforeSendRdb = 2000;
    fakeRedisServer.setSleepBeforeSendRdb(sleepBeforeSendRdb);
    RedisKeeperServer redisKeeperServer = startRedisKeeperServerAndConnectToFakeRedis(100, allCommandsSize);
    sleep(sleepBeforeSendRdb / 4);
    int rdbDumpCount1 = ((DefaultRedisKeeperServer) redisKeeperServer).getRdbDumpTryCount();
    Assert.assertEquals(1, rdbDumpCount1);
    int keeperPort = redisKeeperServer.getListeningPort();
    logger.info(remarkableMessage("send psync to keeper port:{}"), keeperPort);
    InMemoryPsync psync = sendInmemoryPsync("localhost", keeperPort, "?", -1L);
    sleep(1000);
    int rdbDumpCount2 = ((DefaultRedisKeeperServer) redisKeeperServer).getRdbDumpTryCount();
    Assert.assertEquals(1, rdbDumpCount2);
    sleep(sleepBeforeSendRdb);
    assertPsyncResultEquals(psync);
}
Also used : DefaultRedisKeeperServer(com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer) DefaultRedisKeeperServer(com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer) RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync) Test(org.junit.Test)

Example 3 with DefaultRedisKeeperServer

use of com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer in project x-pipe by ctripcorp.

the class FakeRedisRdbDumperTest method testRdbDumpWhileNotConnectedToMaster.

@Test
public void testRdbDumpWhileNotConnectedToMaster() throws Exception {
    fakeRedisServer.setSleepBeforeSendFullSyncInfo(sleepBeforeSendFullSyncInfo);
    RedisKeeperServer redisKeeperServer = startRedisKeeperServerAndConnectToFakeRedis();
    InMemoryPsync inMemoryPsync = sendInmemoryPsync("localhost", redisKeeperServer.getListeningPort());
    CommandFuture<?> future = inMemoryPsync.future();
    sleep(sleepBeforeSendFullSyncInfo + 1000);
    Assert.assertEquals(1, ((DefaultRedisKeeperServer) redisKeeperServer).getRdbDumpTryCount());
    Assert.assertFalse(future.isSuccess());
}
Also used : DefaultRedisKeeperServer(com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer) RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync) Test(org.junit.Test)

Example 4 with DefaultRedisKeeperServer

use of com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer in project x-pipe by ctripcorp.

the class KeeperContainerService method createRedisKeeperServer.

private RedisKeeperServer createRedisKeeperServer(KeeperMeta keeper, File baseDir, MetaServerKeeperService metaService) throws Exception {
    RedisKeeperServer redisKeeperServer = new DefaultRedisKeeperServer(keeper, keeperConfig, baseDir, metaService, leaderElectorManager, keepersMonitorManager);
    register(redisKeeperServer);
    return redisKeeperServer;
}
Also used : DefaultRedisKeeperServer(com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer) DefaultRedisKeeperServer(com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer) RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer)

Aggregations

DefaultRedisKeeperServer (com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer)4 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)3 InMemoryPsync (com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync)2 Test (org.junit.Test)2 RedisClient (com.ctrip.xpipe.redis.keeper.RedisClient)1 RedisKeeperServerState (com.ctrip.xpipe.redis.keeper.RedisKeeperServerState)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1