Search in sources :

Example 21 with Server

use of com.ctrip.xpipe.simpleserver.Server in project x-pipe by ctripcorp.

the class PingCommandTest method testTimeout.

@Test(expected = CommandTimeoutException.class)
public void testTimeout() throws Throwable {
    Server server = startServer((String) null);
    PingCommand command = new PingCommand(getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress("127.0.0.1", server.getPort())), scheduled);
    try {
        String result = command.execute().get();
    } catch (ExecutionException e) {
        throw e.getCause();
    }
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) FakeRedisServer(com.ctrip.xpipe.redis.core.server.FakeRedisServer) InetSocketAddress(java.net.InetSocketAddress) ExecutionException(java.util.concurrent.ExecutionException) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

Example 22 with Server

use of com.ctrip.xpipe.simpleserver.Server in project x-pipe by ctripcorp.

the class RoleCommandTest method test.

@Test
public void test() throws Exception {
    SlaveRole role = new SlaveRole(SERVER_ROLE.KEEPER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECT, 0L);
    Server server = startServer(ByteBufUtils.readToString(role.format()));
    RoleCommand roleCommand = new RoleCommand("localhost", server.getPort(), scheduled);
    Role real = roleCommand.execute().get();
    logger.info("[test]{}", real);
    Assert.assertEquals(role, real);
}
Also used : SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) Role(com.ctrip.xpipe.redis.core.protocal.pojo.Role) SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) Server(com.ctrip.xpipe.simpleserver.Server) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

Example 23 with Server

use of com.ctrip.xpipe.simpleserver.Server in project x-pipe by ctripcorp.

the class AtLeastOneCheckerTest method testCheckerSuccess.

@Test
public void testCheckerSuccess() throws Exception {
    int count = 3;
    List<RedisMeta> redises = new LinkedList<>();
    Set<Integer> ports = randomPorts(count);
    int i = 0;
    for (int port : ports) {
        if (i == count - 1) {
            Server server = startServer(port, toRedisProtocalString("PONG"));
        }
        redises.add(new RedisMeta().setIp("localhost").setPort(port));
        i++;
    }
    SimpleErrorMessage check = new AtLeastOneChecker(redises, getXpipeNettyClientKeyedObjectPool(), scheduled).check();
    Assert.assertEquals(SIMPLE_RETURN_CODE.SUCCESS, check.getErrorType());
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) AtLeastOneChecker(com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) SimpleErrorMessage(com.ctrip.xpipe.exception.SimpleErrorMessage) LinkedList(java.util.LinkedList) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 24 with Server

use of com.ctrip.xpipe.simpleserver.Server in project x-pipe by ctripcorp.

the class PrimaryDcKeeperMasterChooserAlgorithmTest method testLongConnection.

@Test
public void testLongConnection() throws Exception {
    SlaveRole role = new SlaveRole(SERVER_ROLE.MASTER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECT, 0L);
    RedisMeta chosen = redises.get(0);
    Server server = startServer(chosen.getPort(), ByteBufUtils.readToString(role.format()));
    Assert.assertEquals(0, server.getConnected());
    for (int i = 0; i < 10; i++) {
        primaryAlgorithm.choose();
        Assert.assertEquals(1, server.getConnected());
    }
}
Also used : SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) Server(com.ctrip.xpipe.simpleserver.Server) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) Test(org.junit.Test)

Example 25 with Server

use of com.ctrip.xpipe.simpleserver.Server in project x-pipe by ctripcorp.

the class TcpPortCheckCommandTest method testOk.

@Test
public void testOk() throws Exception {
    Server server = startEchoServer();
    for (int i = 0; i < count; i++) {
        TcpPortCheckCommand checkCommand = new TcpPortCheckCommand("localhost", server.getPort());
        CommandFuture<Boolean> future = checkCommand.execute();
        Assert.assertTrue(future.get(500, TimeUnit.SECONDS));
    }
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Aggregations

Server (com.ctrip.xpipe.simpleserver.Server)28 Test (org.junit.Test)25 AbstractTest (com.ctrip.xpipe.AbstractTest)9 SlaveRole (com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole)9 InetSocketAddress (java.net.InetSocketAddress)8 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)6 ExecutionException (java.util.concurrent.ExecutionException)6 AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)5 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)4 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)3 RoleCommand (com.ctrip.xpipe.redis.core.protocal.cmd.RoleCommand)3 Role (com.ctrip.xpipe.redis.core.protocal.pojo.Role)3 LinkedList (java.util.LinkedList)3 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)2 SimpleErrorMessage (com.ctrip.xpipe.exception.SimpleErrorMessage)2 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)2 AtLeastOneChecker (com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker)2 Socket (java.net.Socket)2 CommandTimeoutException (com.ctrip.xpipe.command.CommandTimeoutException)1 DefaultEndPoint (com.ctrip.xpipe.endpoint.DefaultEndPoint)1