Search in sources :

Example 26 with Server

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

the class XpipeNettyClientKeyedObjectPoolTest method testSingleReuse.

@Test
public void testSingleReuse() throws Exception {
    Server echoServer = startEchoServer();
    Assert.assertEquals(0, echoServer.getTotalConnected());
    for (int i = 0; i < testCount; i++) {
        InetSocketAddress key = new InetSocketAddress("localhost", echoServer.getPort());
        NettyClient client = pool.borrowObject(key);
        sleep(10);
        Assert.assertEquals(1, echoServer.getTotalConnected());
        pool.returnObject(key, client);
    }
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) Server(com.ctrip.xpipe.simpleserver.Server) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 27 with Server

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

the class XpipeNettyClientKeyedObjectPoolTest method testDispose.

@Test
public void testDispose() throws Exception {
    Server echoServer = startEchoServer();
    InetSocketAddress key = new InetSocketAddress("localhost", echoServer.getPort());
    Assert.assertEquals(0, echoServer.getConnected());
    for (int i = 0; i < maxPerKey; i++) {
        pool.borrowObject(key);
        int finalI = i;
        waitConditionUntilTimeOut(() -> echoServer.getConnected() == finalI + 1);
    }
    LifecycleHelper.stopIfPossible(pool);
    LifecycleHelper.disposeIfPossible(pool);
    waitConditionUntilTimeOut(() -> echoServer.getConnected() == 0);
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 28 with Server

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

the class SimpleTest method testServer.

@Test
public void testServer() throws Exception {
    Server server = startServer(6379, new Function<String, String>() {

        @Override
        public String apply(String request) {
            if (request == null) {
                return null;
            }
            if (request.equalsIgnoreCase("PING")) {
                return "+PONG\r\n";
            }
            if (request.indexOf("SYNC") >= 0) {
                return "-ERRORXX\r\n";
            }
            return "+OK\r\n";
        }
    });
    waitForAnyKey();
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) Test(org.junit.Test) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest)

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