use of com.ctrip.xpipe.redis.core.protocal.cmd.Replconf in project x-pipe by ctripcorp.
the class AbstractFakeRedisTest method sendInmemoryPsync.
protected InMemoryPsync sendInmemoryPsync(String ip, int port, String runid, long offset) throws Exception {
SequenceCommandChain chain = new SequenceCommandChain(false);
SimpleObjectPool<NettyClient> pool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress(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);
psync.addPsyncObserver(new PsyncObserver() {
private long masterRdbOffset = 0;
@Override
public void reFullSync() {
}
@Override
public void onFullSync() {
}
@Override
public void onContinue(String requestReplId, String responseReplId) {
}
@Override
public void endWriteRdb() {
new Replconf(clientPool, ReplConfType.ACK, scheduled, String.valueOf(masterRdbOffset)).execute();
}
@Override
public void beginWriteRdb(EofType eofType, long masterRdbOffset) throws IOException {
this.masterRdbOffset = masterRdbOffset;
}
});
chain.execute();
return psync;
} finally {
if (nettyClient != null) {
pool.returnObject(nettyClient);
}
}
}
use of com.ctrip.xpipe.redis.core.protocal.cmd.Replconf in project x-pipe by ctripcorp.
the class ReplconfTest method test.
@Test
public void test() throws Exception {
for (int i = 0; i < 100; i++) {
FixedObjectPool<NettyClient> clientPool = null;
try {
clientPool = createClientPool(host, port);
Replconf replconf = new Replconf(clientPool, ReplConfType.LISTENING_PORT, scheduled, String.valueOf(1234));
replconf.execute().addListener(new CommandFutureListener<Object>() {
@Override
public void operationComplete(CommandFuture<Object> commandFuture) throws Exception {
logger.info("{}", commandFuture.get());
}
});
Psync psync = new InMemoryPsync(clientPool, "?", -1L, scheduled);
try {
psync.execute().get(100, TimeUnit.MILLISECONDS);
Assert.fail();
} catch (TimeoutException e) {
}
} finally {
if (clientPool != null) {
clientPool.getObject().channel().close();
}
}
}
}
use of com.ctrip.xpipe.redis.core.protocal.cmd.Replconf in project x-pipe by ctripcorp.
the class ReplconfTest method testCapa.
@Test
public void testCapa() throws Exception {
Replconf conf = new Replconf(getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress(host, port)), ReplConfType.CAPA, scheduled, "eof", "psync2");
logger.info("{}", conf.execute().get());
}
use of com.ctrip.xpipe.redis.core.protocal.cmd.Replconf in project x-pipe by ctripcorp.
the class AbstractRedisMasterReplication method masterConnected.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void masterConnected(Channel channel) {
connectedTime = System.currentTimeMillis();
this.masterChannel = channel;
clientPool = new FixedObjectPool<NettyClient>(new DefaultNettyClient(channel));
checkTimeout(channel);
checkKeeper();
SequenceCommandChain chain = new SequenceCommandChain(false);
chain.add(listeningPortCommand());
chain.add(new FailSafeCommandWrapper<>(new Replconf(clientPool, ReplConfType.CAPA, scheduled, CAPA.EOF.toString(), CAPA.PSYNC2.toString())));
try {
executeCommand(chain).addListener(new CommandFutureListener() {
@Override
public void operationComplete(CommandFuture commandFuture) throws Exception {
if (commandFuture.isSuccess()) {
sendReplicationCommand();
} else {
logger.error("[operationComplete][listeningPortCommand]", commandFuture.cause());
}
}
});
} catch (Exception e) {
logger.error("[masterConnected]" + channel, e);
}
}
Aggregations