Search in sources :

Example 6 with Server

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);
}
Also used : Answer(org.mockito.stubbing.Answer) RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) Server(com.ctrip.xpipe.simpleserver.Server) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultEndPoint(com.ctrip.xpipe.endpoint.DefaultEndPoint) AbstractRedisKeeperTest(com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest) Test(org.junit.Test)

Example 7 with Server

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()));
    }
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) Test(org.junit.Test) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest)

Example 8 with Server

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();
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) CommandTimeoutException(com.ctrip.xpipe.command.CommandTimeoutException) Server(com.ctrip.xpipe.simpleserver.Server) InetSocketAddress(java.net.InetSocketAddress) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest)

Example 9 with Server

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());
}
Also used : SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) Server(com.ctrip.xpipe.simpleserver.Server) RoleCommand(com.ctrip.xpipe.redis.core.protocal.cmd.RoleCommand) Test(org.junit.Test)

Example 10 with Server

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);
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) ExecutionException(java.util.concurrent.ExecutionException) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

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