use of com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole in project x-pipe by ctripcorp.
the class RoleCommandTest method testKeeper.
@Test
public void testKeeper() throws Exception {
Server slave = startServer("*5\r\n" + "$6\r\nkeeper\r\n" + "$9\r\nlocalhost\r\n" + ":6379\r\n" + "$9\r\nconnected\r\n" + ":477\r\n");
RoleCommand roleCommand = new RoleCommand(getXpipeNettyClientKeyedObjectPool().getKeyPool(localhostInetAddress(slave.getPort())), 2000, false, scheduled);
SlaveRole role = (SlaveRole) roleCommand.execute().get();
Assert.assertEquals(SERVER_ROLE.KEEPER, role.getServerRole());
Assert.assertEquals("localhost", role.getMasterHost());
Assert.assertEquals(6379, role.getMasterPort());
Assert.assertEquals(MASTER_STATE.REDIS_REPL_CONNECTED, role.getMasterState());
Assert.assertEquals(477, role.getMasterOffset());
}
use of com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole in project x-pipe by ctripcorp.
the class AddKeeperCommandTest method testFailTimeout.
@Test
public void testFailTimeout() throws Exception {
SlaveRole slaveRole = new SlaveRole(SERVER_ROLE.KEEPER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECT, 0);
startServer(keeperPort, ByteBufUtils.readToString(slaveRole.format()));
long begin = System.currentTimeMillis();
try {
addKeeperCommand.execute().get();
Assert.fail();
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof KeeperMasterStateNotAsExpectedException);
}
long end = System.currentTimeMillis();
long interval = end - begin;
Assert.assertTrue(interval >= timeoutMilli);
Assert.assertTrue(interval <= timeoutMilli * 2);
}
use of com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole in project x-pipe by ctripcorp.
the class AddKeeperCommandTest method testCheckStateCommandNoDelay.
@Test
public void testCheckStateCommandNoDelay() throws Exception {
int sleepTime = 2000;
SlaveRole keeperRole = new SlaveRole(SERVER_ROLE.KEEPER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECTED, 0);
Server server = startServer(keeperPort, new Callable<String>() {
@Override
public String call() throws Exception {
sleep(sleepTime);
return ByteBufUtils.readToString(keeperRole.format());
}
});
SettableFuture<Boolean> objectSettableFuture = SettableFuture.create();
executors.execute(new AbstractExceptionLogTask() {
@Override
public void doRun() throws Exception {
AddKeeperCommand.CheckStateCommand checkStateCommand = new AddKeeperCommand.CheckStateCommand(new KeeperMeta().setIp("127.0.0.1").setPort(server.getPort()), scheduled);
checkStateCommand.doExecute();
objectSettableFuture.set(true);
}
});
// should return immediately
objectSettableFuture.get(500, TimeUnit.MILLISECONDS);
}
use of com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole in project x-pipe by ctripcorp.
the class AddKeeperCommandTest method testIoExceptionNotRetry.
@Test
public void testIoExceptionNotRetry() throws Exception {
SlaveRole slaveRole = new SlaveRole(SERVER_ROLE.KEEPER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECT, 0);
final Server server = startServer(keeperPort, ByteBufUtils.readToString(slaveRole.format()));
new Thread(new Runnable() {
@Override
public void run() {
try {
sleep(timeoutMilli / 2);
LifecycleHelper.stopIfPossible(server);
LifecycleHelper.disposeIfPossible(server);
} catch (Exception e) {
logger.error("[run]" + server, e);
}
}
}).start();
try {
addKeeperCommand.execute().get();
Assert.fail();
} catch (ExecutionException e) {
Assert.assertTrue(ExceptionUtils.isSocketIoException(e));
}
}
use of com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole in project x-pipe by ctripcorp.
the class AddKeeperCommandTest method testSuccess.
@SuppressWarnings("unused")
@Test
public void testSuccess() throws Exception {
SlaveRole keeperRole = new SlaveRole(SERVER_ROLE.KEEPER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECTED, 0);
Server server = startServer(keeperPort, ByteBufUtils.readToString(keeperRole.format()));
SlaveRole real = addKeeperCommand.execute().get();
Assert.assertEquals(keeperRole, real);
}
Aggregations