Search in sources :

Example 1 with Server

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

the class AtLeastOneCheckerTest method testCheckerTimeout.

@Test
public void testCheckerTimeout() throws Exception {
    Server server = startServer((String) null);
    List<RedisMeta> redises = new LinkedList<>();
    redises.add(new RedisMeta().setIp("localhost").setPort(server.getPort()));
    SimpleErrorMessage check = new AtLeastOneChecker(redises, getXpipeNettyClientKeyedObjectPool(), scheduled).check();
    Assert.assertEquals(SIMPLE_RETURN_CODE.FAIL, 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 2 with Server

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

the class TcpPortCheckCommandTest method testResource.

// @Test
public void testResource() throws Exception {
    Server server = startEchoServer();
    int i = 0;
    try {
        for (; i < (1 << 10); i++) {
            TcpPortCheckCommand checkCommand = new TcpPortCheckCommand("localhost", server.getPort());
            CommandFuture<Boolean> future = checkCommand.execute();
            Assert.assertTrue(future.get(500, TimeUnit.SECONDS));
        }
    } catch (Exception e) {
        logger.error("[testResource]" + i, e);
    }
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException)

Example 3 with Server

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

the class XpipeNettyClientKeyedObjectPoolTest method testIdleClose.

@Test
public void testIdleClose() throws Exception {
    Server echoServer = startEchoServer();
    InetSocketAddress key = new InetSocketAddress("localhost", echoServer.getPort());
    pool.setKeyPooConfig(0, 200, 500, 100);
    SimpleObjectPool<NettyClient> objectPool = pool.getKeyPool(key);
    NettyClient nettyClient1 = objectPool.borrowObject();
    NettyClient nettyClient2 = objectPool.borrowObject();
    waitConditionUntilTimeOut(() -> echoServer.getConnected() == 2);
    objectPool.returnObject(nettyClient1);
    objectPool.returnObject(nettyClient2);
    waitConditionUntilTimeOut(() -> echoServer.getConnected() == 0, 60000);
}
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 4 with Server

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

the class XpipeNettyClientKeyedObjectPoolTest method testKeyPoolReuse.

@Test
public void testKeyPoolReuse() throws Exception {
    Server echoServer = startEchoServer();
    InetSocketAddress key = new InetSocketAddress("localhost", echoServer.getPort());
    Assert.assertEquals(0, echoServer.getConnected());
    SimpleObjectPool<NettyClient> objectPool = pool.getKeyPool(key);
    for (int i = 0; i < testCount; i++) {
        NettyClient client = objectPool.borrowObject();
        sleep(10);
        Assert.assertEquals(1, echoServer.getTotalConnected());
        objectPool.returnObject(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 5 with Server

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

the class XpipeNettyClientKeyedObjectPoolTest method testMax.

@Test
public void testMax() 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);
        sleep(100);
        Assert.assertEquals(i + 1, echoServer.getConnected());
    }
    try {
        pool.borrowObject(key);
        Assert.fail();
    } catch (BorrowObjectException e) {
    }
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) InetSocketAddress(java.net.InetSocketAddress) 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