use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.
the class AbstractRedisCommandTest method testLogRequest.
// manual test
@Test
public void testLogRequest() throws Exception {
XpipeNettyClientKeyedObjectPool keyedObjectPool = getXpipeNettyClientKeyedObjectPool();
SimpleObjectPool<NettyClient> clientPool = keyedObjectPool.getKeyPool(new InetSocketAddress("127.0.0.1", 6379));
ScheduledExecutorService scheduled = Executors.newScheduledThreadPool(1);
InfoCommand infoCommand = new InfoCommand(clientPool, InfoCommand.INFO_TYPE.REPLICATION, scheduled);
infoCommand.logResponse(false);
// infoCommand.logRequest(false);
infoCommand.execute().get();
}
use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.
the class DefaultSlaveOfCommandTest method testMultiServer.
@Test
public void testMultiServer() throws Exception {
int begin = 10000;
int count = 32;
// make connection active
for (int i = 0; i < count; i++) {
int port = begin + i;
SimpleObjectPool<NettyClient> keyPool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress("127.0.0.1", port));
new PingCommand(keyPool, scheduled).execute().get();
}
CountDownLatch latch = new CountDownLatch(count);
for (int i = 0; i < count; i++) {
int port = begin + i;
SimpleObjectPool<NettyClient> keyPool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress("127.0.0.1", port));
long beginTime = System.currentTimeMillis();
new DefaultSlaveOfCommand(keyPool, "127.0.0.1", 0, scheduled).execute(executors).addListener(new CommandFutureListener<String>() {
@Override
public void operationComplete(CommandFuture<String> commandFuture) throws Exception {
long endTime = System.currentTimeMillis();
long duration = endTime - beginTime;
if (duration > 50) {
logger.warn("[timeout]127.0.0.1:{}, {}", port, duration);
}
latch.countDown();
}
});
}
latch.await();
sleep(1000);
logger.info("[testMultiServer][end]");
}
use of com.ctrip.xpipe.netty.commands.NettyClient 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.netty.commands.NettyClient in project x-pipe by ctripcorp.
the class TransactionalCommand method doExecute.
@Override
protected void doExecute() throws CommandExecutionException {
try {
final NettyClient nettyClient = parentClientPool.borrowObject();
SimpleObjectPool<NettyClient> clientPool = new FixedObjectPool<NettyClient>(nettyClient);
startTransaction(clientPool);
future().addListener(new CommandFutureListener<Object[]>() {
@Override
public void operationComplete(CommandFuture<Object[]> commandFuture) throws Exception {
if (nettyClient != null) {
try {
parentClientPool.returnObject(nettyClient);
} catch (ReturnObjectException e) {
logger.error("[doExecute]" + this, e);
}
}
}
});
} catch (BorrowObjectException e) {
throw new CommandExecutionException("execute " + this, e);
}
}
use of com.ctrip.xpipe.netty.commands.NettyClient 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