Search in sources :

Example 46 with RedisMeta

use of com.ctrip.xpipe.redis.core.entity.RedisMeta 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 47 with RedisMeta

use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.

the class DefaultSlaveOfJobTest method testSlavesFail.

@Test
public void testSlavesFail() throws Exception {
    List<RedisMeta> slaves = new LinkedList<>();
    List<Integer> ports = new LinkedList<>(randomPorts(2));
    slaves.add(new RedisMeta().setIp("localhost").setPort(ports.get(0)));
    slaves.add(new RedisMeta().setIp("localhost").setPort(ports.get(1)));
    startServer(ports.get(0), "-Server0 FAIL\r\n");
    startServer(ports.get(1), "-Server1 JUST FAIL\r\n");
    try {
        Command<Void> command = new DefaultSlaveOfJob(slaves, "localhost", randomPort(), getXpipeNettyClientKeyedObjectPool(), scheduled, executors);
        command.execute().get(1, TimeUnit.SECONDS);
        Assert.fail();
    } catch (Exception e) {
        logger.info("{}", e.getMessage());
    }
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) LinkedList(java.util.LinkedList) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 48 with RedisMeta

use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.

the class SlaveofJobTest method getRedisSlaves.

private List<RedisMeta> getRedisSlaves(String[] redises) {
    List<RedisMeta> slaves = new LinkedList<>();
    for (String redis : redises) {
        Pair<String, Integer> addr = IpUtils.parseSingleAsPair(redis);
        RedisMeta redisMeta = new RedisMeta();
        redisMeta.setIp(addr.getKey());
        redisMeta.setPort(addr.getValue());
        slaves.add(redisMeta);
    }
    return slaves;
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) LinkedList(java.util.LinkedList)

Example 49 with RedisMeta

use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.

the class DefaultRedisMasterCollectorTest method before.

@Before
public void before() {
    MockitoAnnotations.initMocks(this);
    collector.postConstructDefaultRedisMasterCollector();
    plan = new RedisMasterSamplePlan("jq", "cluster1", "shard1");
    RedisMeta redisMeta = new RedisMeta().setIp("127.0.0.1").setPort(6379).setMaster(XPipeConsoleConstant.DEFAULT_ADDRESS);
    plan.addRedis("jq", redisMeta, new InstanceRedisMasterResult());
    RedisMeta redisMeta2 = new RedisMeta().setIp("127.0.0.1").setPort(6380).setMaster(XPipeConsoleConstant.DEFAULT_ADDRESS);
    plan.addRedis("jq", redisMeta2, new InstanceRedisMasterResult());
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) Before(org.junit.Before)

Example 50 with RedisMeta

use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.

the class KeeperSingleDc method testReFullSync.

@Test
public void testReFullSync() throws ExecuteException, IOException {
    RedisKeeperServer redisKeeperServer = getRedisKeeperServerActive(dc);
    DefaultReplicationStore replicationStore = (DefaultReplicationStore) redisKeeperServer.getReplicationStore();
    DcMeta dcMeta = getDcMeta();
    RedisMeta slave1 = createSlave(activeKeeper.getIp(), activeKeeper.getPort());
    int lastRdbUpdateCount = replicationStore.getRdbUpdateCount();
    logger.info(remarkableMessage("[testReFullSync][sendRandomMessage]"));
    sendRandomMessage(redisMaster, 1, replicationStoreCommandFileSize);
    for (int i = 0; i < 3; i++) {
        logger.info(remarkableMessage("[testReFullSync]{}"), i);
        startRedis(slave1);
        sleep(3000);
        int currentRdbUpdateCount = replicationStore.getRdbUpdateCount();
        logger.info("[testReFullSync]{},{}", lastRdbUpdateCount, currentRdbUpdateCount);
        Assert.assertEquals(lastRdbUpdateCount + 1, currentRdbUpdateCount);
        lastRdbUpdateCount = currentRdbUpdateCount;
        sendMesssageToMasterAndTest(100, getRedisMaster(), Lists.newArrayList(slave1));
    }
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) DefaultReplicationStore(com.ctrip.xpipe.redis.keeper.store.DefaultReplicationStore) Test(org.junit.Test)

Aggregations

RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)55 Test (org.junit.Test)26 LinkedList (java.util.LinkedList)14 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)9 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)8 Before (org.junit.Before)7 SimpleErrorMessage (com.ctrip.xpipe.exception.SimpleErrorMessage)5 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)5 AtLeastOneChecker (com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker)5 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)4 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)4 SlaveRole (com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole)4 Pair (com.ctrip.xpipe.tuple.Pair)4 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)3 PrimaryDcChangeMessage (com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcChangeMessage)3 Server (com.ctrip.xpipe.simpleserver.Server)3 InetSocketAddress (java.net.InetSocketAddress)3 SERVER_ROLE (com.ctrip.xpipe.api.server.Server.SERVER_ROLE)2 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)2 HostPort (com.ctrip.xpipe.endpoint.HostPort)2