Search in sources :

Example 11 with Server

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

the class AddKeeperCommandTest method testIoExceptionNotRetry.

@Test
public void testIoExceptionNotRetry() throws Exception {
    SlaveRole slaveRole = new SlaveRole(SERVER_ROLE.KEEPER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECT, 0);
    final Server server = startServer(keeperPort, ByteBufUtils.readToString(slaveRole.format()));
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                sleep(timeoutMilli / 2);
                LifecycleHelper.stopIfPossible(server);
                LifecycleHelper.disposeIfPossible(server);
            } catch (Exception e) {
                logger.error("[run]" + server, e);
            }
        }
    }).start();
    try {
        addKeeperCommand.execute().get();
        Assert.fail();
    } catch (ExecutionException e) {
        Assert.assertTrue(ExceptionUtils.isSocketIoException(e));
    }
}
Also used : SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) Server(com.ctrip.xpipe.simpleserver.Server) ExecutionException(java.util.concurrent.ExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 12 with Server

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

the class AddKeeperCommandTest method testSuccess.

@SuppressWarnings("unused")
@Test
public void testSuccess() throws Exception {
    SlaveRole keeperRole = new SlaveRole(SERVER_ROLE.KEEPER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECTED, 0);
    Server server = startServer(keeperPort, ByteBufUtils.readToString(keeperRole.format()));
    SlaveRole real = addKeeperCommand.execute().get();
    Assert.assertEquals(keeperRole, real);
}
Also used : SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) Server(com.ctrip.xpipe.simpleserver.Server) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 13 with Server

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

the class DeleteKeeperCommandTest method testDeleteWaitTimeoutThenSuccess.

@Test
public void testDeleteWaitTimeoutThenSuccess() throws Exception {
    List<KeeperMeta> keepers = new LinkedList<>();
    keepers.add(keeperMeta);
    final Server server = startEchoServer(keeperMeta.getPort());
    scheduled.schedule(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            LifecycleHelper.stopIfPossible(server);
            LifecycleHelper.disposeIfPossible(server);
        }
    }, checkIntervalMili / 2, TimeUnit.MILLISECONDS);
    deleteKeeperCommand.execute().get();
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) LinkedList(java.util.LinkedList) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 14 with Server

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

the class FirstNewMasterChooserTest method startSlaveFakeRedis.

private Server startSlaveFakeRedis(Integer port, SERVER_ROLE serverRole) throws Exception {
    Role role = null;
    if (serverRole == SERVER_ROLE.MASTER) {
        role = new MasterRole();
    } else {
        role = new SlaveRole(serverRole, "localhost", port, MASTER_STATE.REDIS_REPL_CONNECT, 0L);
    }
    Server server = startServer(port, ByteBufUtils.readToString(role.format()));
    return server;
}
Also used : Role(com.ctrip.xpipe.redis.core.protocal.pojo.Role) SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) MasterRole(com.ctrip.xpipe.redis.core.protocal.pojo.MasterRole) SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) Server(com.ctrip.xpipe.simpleserver.Server) MasterRole(com.ctrip.xpipe.redis.core.protocal.pojo.MasterRole)

Example 15 with Server

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

the class StreamTest method testClose.

@SuppressWarnings("resource")
@Test
public void testClose() throws Exception {
    Server server = startEchoServer();
    Socket s = new Socket("localhost", server.getPort());
    OutputStream ous = s.getOutputStream();
    ous.write("123".getBytes());
    ous.close();
    ous.write("123".getBytes());
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) OutputStream(java.io.OutputStream) Socket(java.net.Socket) 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