use of com.ctrip.xpipe.simpleserver.Server in project x-pipe by ctripcorp.
the class DefaultRedisMasterReplicationTest method testTimeout.
@Test
public void testTimeout() throws Exception {
Server server = startEmptyServer();
when(redisMaster.masterEndPoint()).thenReturn(new DefaultEndPoint("localhost", server.getPort()));
AtomicInteger connectingCount = new AtomicInteger(0);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
connectingCount.incrementAndGet();
return null;
}
}).when(redisMaster).setMasterState(MASTER_STATE.REDIS_REPL_CONNECTING);
defaultRedisMasterReplication.setMasterConnectRetryDelaySeconds(0);
defaultRedisMasterReplication.initialize();
defaultRedisMasterReplication.start();
waitConditionUntilTimeOut(() -> connectingCount.get() >= 2);
}
use of com.ctrip.xpipe.simpleserver.Server in project x-pipe by ctripcorp.
the class SimpleTest method testPort.
@Test
public void testPort() throws Exception {
for (int i = 0; i < 10; i++) {
Server server = startEchoServer();
Assert.assertFalse(isUsable(server.getPort()));
}
}
use of com.ctrip.xpipe.simpleserver.Server in project x-pipe by ctripcorp.
the class RedisCommandTest method testTimeoutNext.
@Test
public void testTimeoutNext() throws Exception {
Server server = startEchoPrefixServer(String.valueOf((char) RedisClientProtocol.PLUS_BYTE));
SimpleObjectPool<NettyClient> keyPool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress("127.0.0.1", server.getPort()));
int sleepTime = timeoutMilli + 50;
String str1 = String.format("sleep %d %s\r\n", sleepTime, randomString(10));
String str2 = randomString(10) + "\r\n";
try {
new TestCommand(str1, timeoutMilli, keyPool, scheduled).execute().get();
Assert.fail();
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof CommandTimeoutException);
}
sleep(sleepTime * 2);
new TestCommand(str2, sleepTime, keyPool, scheduled).execute().get();
}
use of com.ctrip.xpipe.simpleserver.Server 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.simpleserver.Server 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);
}
Aggregations