Search in sources :

Example 1 with RedisClient

use of com.ctrip.xpipe.redis.keeper.RedisClient 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 RedisClient

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

the class DefaultRedisSlaveTest method beforeDefaultRedisSlaveTest.

@Before
public void beforeDefaultRedisSlaveTest() {
    when(channel.closeFuture()).thenReturn(new DefaultChannelPromise(channel));
    when(channel.remoteAddress()).thenReturn(localhostInetAddress(randomPort()));
    RedisClient redisClient = new DefaultRedisClient(channel, redisKeeperServer);
    redisSlave = new DefaultRedisSlave(redisClient);
    redisSlave.setRdbDumpMaxWaitMilli(waitDumpMilli);
}
Also used : RedisClient(com.ctrip.xpipe.redis.keeper.RedisClient) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) Before(org.junit.Before)

Aggregations

RedisClient (com.ctrip.xpipe.redis.keeper.RedisClient)2 RedisKeeperServerState (com.ctrip.xpipe.redis.keeper.RedisKeeperServerState)1 DefaultRedisKeeperServer (com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer)1 DefaultChannelPromise (io.netty.channel.DefaultChannelPromise)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 Before (org.junit.Before)1