Search in sources :

Example 36 with KeeperMeta

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

the class ConsoleNotifycationTaskTest method testException.

@Test
public void testException() throws Exception {
    ConsoleNotifycationTask task = new ConsoleNotifycationTask(100);
    task.initialize();
    task.setConsoleService(consoleService);
    doThrow(new Exception()).when(consoleService).keeperActiveChanged(anyString(), anyString(), anyString(), (KeeperMeta) anyObject());
    task.keeperActiveElected("cluster1", "shard1", new KeeperMeta());
    sleep(300);
    verify(consoleService, atLeast(2)).keeperActiveChanged(anyString(), anyString(), anyString(), any(KeeperMeta.class));
    task.dispose();
}
Also used : RejectedExecutionException(java.util.concurrent.RejectedExecutionException) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 37 with KeeperMeta

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

the class MetaInfoChange method testGetKeeperActive.

@Test
public void testGetKeeperActive() {
    KeeperMeta keeperMeta = metaServerMultiDcService.getActiveKeeper(clusterId, shardId);
    logger.info("[testGetKeeperActive]{}, {}, {}", clusterId, shardId, keeperMeta);
}
Also used : KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) AbstractMetaServerClusterTest(com.ctrip.xpipe.redis.meta.server.cluster.AbstractMetaServerClusterTest) Test(org.junit.Test)

Example 38 with KeeperMeta

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

the class BackupDcKeeperMasterChooserAlgorithmTest method testGetUpstream.

@Test
public void testGetUpstream() throws Exception {
    backupAlgorithm.choose();
    verify(multiDcService, atLeast(1)).getActiveKeeper(primaryDc, clusterId, shardId);
    logger.info("[testGetUpstream][getActiveKeeper give a result]");
    KeeperMeta keeperMeta = new KeeperMeta();
    keeperMeta.setIp("localhost");
    keeperMeta.setPort(randomPort());
    when(multiDcService.getActiveKeeper(primaryDc, clusterId, shardId)).thenReturn(keeperMeta);
    Assert.assertEquals(new Pair<>(keeperMeta.getIp(), keeperMeta.getPort()), backupAlgorithm.choose());
    verify(multiDcService, atLeast(1)).getActiveKeeper(primaryDc, clusterId, shardId);
}
Also used : KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test)

Example 39 with KeeperMeta

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

the class CurrentMetaTest method testToString.

@Test
public void testToString() {
    List<KeeperMeta> allKeepers = getDcKeepers(getDc(), clusterId, shardId);
    currentMeta.setSurviveKeepers(clusterId, shardId, allKeepers, allKeepers.get(0));
    currentMeta.addResource(clusterId, shardId, new Releasable() {

        @Override
        public void release() throws Exception {
        }
    });
    String json = currentMeta.toString();
    CurrentMeta de = CurrentMeta.fromJson(json);
    Assert.assertEquals(json, de.toString());
    Assert.assertTrue(currentMeta.hasCluster(clusterId));
    for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
        Assert.assertTrue(currentMeta.hasShard(clusterId, shardMeta.getId()));
    }
}
Also used : ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) Releasable(com.ctrip.xpipe.api.lifecycle.Releasable) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 40 with KeeperMeta

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

the class DefaultKeeperElectorManagerTest method testUpdateShardLeader.

@Test
public void testUpdateShardLeader() {
    String prefix = "/path";
    List<ChildData> dataList = new LinkedList<>();
    final int portBegin = 4000;
    final int count = 3;
    dataList.add(new ChildData(prefix + "/" + randomString(10) + "-latch-02", null, JsonCodec.INSTANCE.encodeAsBytes(new KeeperMeta().setId("127.0.0.1").setPort(portBegin + 1))));
    dataList.add(new ChildData(prefix + "/" + randomString(10) + "-latch-03", null, JsonCodec.INSTANCE.encodeAsBytes(new KeeperMeta().setId("127.0.0.1").setPort(portBegin + 2))));
    dataList.add(new ChildData(prefix + "/" + randomString(10) + "-latch-01", null, JsonCodec.INSTANCE.encodeAsBytes(new KeeperMeta().setId("127.0.0.1").setPort(portBegin))));
    keeperElectorManager.updateShardLeader(prefix, dataList, clusterMeta.getId(), shardMeta.getId());
    verify(keeperActiveElectAlgorithm).select(eq(clusterMeta.getId()), eq(shardMeta.getId()), argThat(new BaseMatcher<List<KeeperMeta>>() {

        @Override
        public boolean matches(Object item) {
            List<KeeperMeta> keepers = (List<KeeperMeta>) item;
            if (keepers.size() != count) {
                return false;
            }
            KeeperMeta prefix = null;
            for (KeeperMeta keeperMeta : keepers) {
                if (prefix != null) {
                    if (keeperMeta.getPort() < prefix.getPort()) {
                        return false;
                    }
                }
                prefix = keeperMeta;
            }
            return true;
        }

        @Override
        public void describeTo(Description description) {
        }
    }));
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) ChildData(org.apache.curator.framework.recipes.cache.ChildData) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test) AbstractMetaServerContextTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerContextTest)

Aggregations

KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)50 Test (org.junit.Test)28 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)9 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)8 KeeperTransMeta (com.ctrip.xpipe.redis.core.entity.KeeperTransMeta)6 LinkedList (java.util.LinkedList)6 AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)4 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)4 KeeperStateChangeJob (com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob)4 InetSocketAddress (java.net.InetSocketAddress)4 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)3 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)3 ShardStatus (com.ctrip.xpipe.redis.core.meta.ShardStatus)3 Before (org.junit.Before)3 RedisKeeperServerState (com.ctrip.xpipe.redis.keeper.RedisKeeperServerState)2 DefaultSlaveOfJob (com.ctrip.xpipe.redis.meta.server.job.DefaultSlaveOfJob)2 Server (com.ctrip.xpipe.simpleserver.Server)2 Pair (com.ctrip.xpipe.tuple.Pair)2 ExecutionException (java.util.concurrent.ExecutionException)2 ChildData (org.apache.curator.framework.recipes.cache.ChildData)2