use of com.ctrip.xpipe.simpleserver.Server 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.simpleserver.Server 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);
}
use of com.ctrip.xpipe.simpleserver.Server in project x-pipe by ctripcorp.
the class DeleteKeeperCommandTest method testDeleteWaitTimeoutThenSuccess.
@Test
public void testDeleteWaitTimeoutThenSuccess() throws Exception {
List<KeeperMeta> keepers = new LinkedList<>();
keepers.add(keeperMeta);
final Server server = startEchoServer(keeperMeta.getPort());
scheduled.schedule(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
LifecycleHelper.stopIfPossible(server);
LifecycleHelper.disposeIfPossible(server);
}
}, checkIntervalMili / 2, TimeUnit.MILLISECONDS);
deleteKeeperCommand.execute().get();
}
use of com.ctrip.xpipe.simpleserver.Server in project x-pipe by ctripcorp.
the class FirstNewMasterChooserTest method startSlaveFakeRedis.
private Server startSlaveFakeRedis(Integer port, SERVER_ROLE serverRole) throws Exception {
Role role = null;
if (serverRole == SERVER_ROLE.MASTER) {
role = new MasterRole();
} else {
role = new SlaveRole(serverRole, "localhost", port, MASTER_STATE.REDIS_REPL_CONNECT, 0L);
}
Server server = startServer(port, ByteBufUtils.readToString(role.format()));
return server;
}
use of com.ctrip.xpipe.simpleserver.Server in project x-pipe by ctripcorp.
the class StreamTest method testClose.
@SuppressWarnings("resource")
@Test
public void testClose() throws Exception {
Server server = startEchoServer();
Socket s = new Socket("localhost", server.getPort());
OutputStream ous = s.getOutputStream();
ous.write("123".getBytes());
ous.close();
ous.write("123".getBytes());
}
Aggregations