Search in sources :

Example 6 with InMemoryPsync

use of com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync 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) AbstractFakeRedisTest(com.ctrip.xpipe.redis.keeper.AbstractFakeRedisTest) Test(org.junit.Test)

Example 7 with InMemoryPsync

use of com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync in project x-pipe by ctripcorp.

the class TwoKeepers method psync.

private boolean psync(KeeperMeta downstreamKeeper) throws InterruptedException, ExecutionException {
    Psync psync = new InMemoryPsync(downstreamKeeper.getIp(), downstreamKeeper.getPort(), "?", -1, scheduled) {

        @Override
        protected void endReadRdb() {
            super.endReadRdb();
            future().setSuccess();
        }
    };
    try {
        return psync.execute().sync().isSuccess();
    } catch (Exception e) {
        return false;
    }
}
Also used : Psync(com.ctrip.xpipe.redis.core.protocal.Psync) InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync) InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with InMemoryPsync

use of com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync in project x-pipe by ctripcorp.

the class AbstractFakeRedisTest method sendInmemoryPsync.

protected InMemoryPsync sendInmemoryPsync(String ip, int port, String runid, long offset, PsyncObserver psyncObserver) throws Exception {
    SequenceCommandChain chain = new SequenceCommandChain(false);
    SimpleObjectPool<NettyClient> pool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new DefaultEndPoint(ip, port));
    NettyClient nettyClient = null;
    try {
        nettyClient = pool.borrowObject();
        SimpleObjectPool<NettyClient> clientPool = new FixedObjectPool<NettyClient>(nettyClient);
        chain.add(new Replconf(clientPool, ReplConfType.CAPA, scheduled, CAPA.EOF.toString()));
        InMemoryPsync psync = new InMemoryPsync(clientPool, runid, offset, scheduled);
        chain.add(psync);
        if (psyncObserver != null) {
            psync.addPsyncObserver(psyncObserver);
        }
        psync.addPsyncObserver(new PsyncObserver() {

            private long masterRdbOffset = 0;

            @Override
            public void reFullSync() {
            }

            @Override
            public void onFullSync(long masterRdbOffset) {
            }

            @Override
            public void onContinue(String requestReplId, String responseReplId) {
            }

            @Override
            public void onKeeperContinue(String replId, long beginOffset) {
            }

            @Override
            public void endWriteRdb() {
                new Replconf(clientPool, ReplConfType.ACK, scheduled, String.valueOf(masterRdbOffset)).execute();
            }

            @Override
            public void beginWriteRdb(EofType eofType, String replId, long masterRdbOffset) throws IOException {
                this.masterRdbOffset = masterRdbOffset;
            }
        });
        chain.execute();
        return psync;
    } finally {
        if (nettyClient != null) {
            pool.returnObject(nettyClient);
        }
    }
}
Also used : Replconf(com.ctrip.xpipe.redis.core.protocal.cmd.Replconf) EofType(com.ctrip.xpipe.redis.core.protocal.protocal.EofType) IOException(java.io.IOException) SequenceCommandChain(com.ctrip.xpipe.command.SequenceCommandChain) NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) DefaultEndPoint(com.ctrip.xpipe.endpoint.DefaultEndPoint) FixedObjectPool(com.ctrip.xpipe.pool.FixedObjectPool) InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync) PsyncObserver(com.ctrip.xpipe.redis.core.protocal.PsyncObserver)

Example 9 with InMemoryPsync

use of com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync in project x-pipe by ctripcorp.

the class FakeRedisHalfRdbServerFail method redisFailWhileSendingRdb.

@Test
public void redisFailWhileSendingRdb() throws Exception {
    waitConditionUntilTimeOut(() -> {
        return redisKeeperServer.getRedisMaster().getMasterState() == MASTER_STATE.REDIS_REPL_CONNECTED;
    });
    logger.info(remarkableMessage("[redisFailWhileSendingRdb]"));
    InMemoryPsync inMemoryPsync = sendInmemoryPsync("localhost", redisKeeperServer.getListeningPort());
    sleep(1500);
    assertPsyncResultEquals(inMemoryPsync);
}
Also used : InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync) AbstractFakeRedisTest(com.ctrip.xpipe.redis.keeper.AbstractFakeRedisTest) Test(org.junit.Test)

Aggregations

InMemoryPsync (com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync)9 Test (org.junit.Test)5 AbstractFakeRedisTest (com.ctrip.xpipe.redis.keeper.AbstractFakeRedisTest)4 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)3 Replconf (com.ctrip.xpipe.redis.core.protocal.cmd.Replconf)3 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)3 DefaultRedisKeeperServer (com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer)3 SequenceCommandChain (com.ctrip.xpipe.command.SequenceCommandChain)2 DefaultEndPoint (com.ctrip.xpipe.endpoint.DefaultEndPoint)2 FixedObjectPool (com.ctrip.xpipe.pool.FixedObjectPool)2 Psync (com.ctrip.xpipe.redis.core.protocal.Psync)2 PsyncObserver (com.ctrip.xpipe.redis.core.protocal.PsyncObserver)2 EofType (com.ctrip.xpipe.redis.core.protocal.protocal.EofType)2 IOException (java.io.IOException)2 SimplePsyncObserver (com.ctrip.xpipe.redis.core.utils.SimplePsyncObserver)1 DefaultReplicationStore (com.ctrip.xpipe.redis.keeper.store.DefaultReplicationStore)1 InetSocketAddress (java.net.InetSocketAddress)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1