Search in sources :

Example 16 with KeeperMeta

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

the class ConsoleNotifycationTaskTest method testDispose.

@Test(expected = RejectedExecutionException.class)
public void testDispose() throws Exception {
    consoleNotifycationTask.dispose();
    consoleNotifycationTask.keeperActiveElected("cluster1", "shard1", new KeeperMeta());
}
Also used : KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 17 with KeeperMeta

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

the class ConsoleNotifycationTaskTest method testSuccess.

@Test
public void testSuccess() throws Exception {
    int times = 100;
    for (int i = 0; i < times; i++) {
        consoleNotifycationTask.keeperActiveElected("cluster1", "shard1", new KeeperMeta());
        sleep(10);
        verify(consoleService, times(i + 1)).keeperActiveChanged(anyString(), anyString(), anyString(), any(KeeperMeta.class));
    }
}
Also used : KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 18 with KeeperMeta

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

the class DefaultKeeperStateControllerTest method testAdd.

@Test
public void testAdd() {
    Assert.assertFalse(addCommand.isBeginExecute());
    defaultKeeperStateController.addKeeper(new KeeperTransMeta(getClusterId(), getShardId(), new KeeperMeta()));
    sleep(10);
    Assert.assertTrue(addCommand.isBeginExecute());
}
Also used : KeeperTransMeta(com.ctrip.xpipe.redis.core.entity.KeeperTransMeta) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 19 with KeeperMeta

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

the class DefaultKeeperStateControllerTest method testDelete.

@Test
public void testDelete() throws TimeoutException {
    Assert.assertFalse(deleteCommand.isBeginExecute());
    defaultKeeperStateController.removeKeeper(new KeeperTransMeta(getClusterId(), getShardId(), new KeeperMeta()));
    waitConditionUntilTimeOut(() -> deleteCommand.isBeginExecute(), 1000);
}
Also used : KeeperTransMeta(com.ctrip.xpipe.redis.core.entity.KeeperTransMeta) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 20 with KeeperMeta

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

the class CurrentMetaTest method testSetInfo.

@Test
public void testSetInfo() {
    // set survice keepers
    Assert.assertEquals(0, currentMeta.getSurviveKeepers(clusterId, shardId).size());
    Assert.assertEquals(null, currentMeta.getKeeperActive(clusterId, shardId));
    List<KeeperMeta> allKeepers = getDcKeepers(getDc(), clusterId, shardId);
    KeeperMeta active = allKeepers.get(0);
    currentMeta.setSurviveKeepers(clusterId, shardId, allKeepers, active);
    Assert.assertEquals(allKeepers.size(), currentMeta.getSurviveKeepers(clusterId, shardId).size());
    active.setActive(true);
    Assert.assertEquals(active, currentMeta.getKeeperActive(clusterId, shardId));
    // set keeper active
    KeeperMeta keeperMeta = getDcKeepers(getDc(), clusterId, shardId).get(1);
    boolean result = currentMeta.setKeeperActive(clusterId, shardId, keeperMeta);
    Assert.assertTrue(result);
    keeperMeta.setActive(true);
    Assert.assertEquals(keeperMeta, currentMeta.getKeeperActive(clusterId, shardId));
    Assert.assertFalse(currentMeta.setKeeperActive(clusterId, shardId, keeperMeta));
    // set keeper active not exist
    keeperMeta.setIp(randomString(10));
    try {
        currentMeta.setKeeperActive(clusterId, shardId, keeperMeta);
        Assert.fail();
    } catch (Exception e) {
    }
    Assert.assertEquals(new Pair<String, Integer>("127.0.0.1", 6379), currentMeta.getKeeperMaster(clusterId, shardId));
    Pair<String, Integer> keeperMaster = new Pair<String, Integer>("localhost", randomPort());
    currentMeta.setKeeperMaster(clusterId, shardId, keeperMaster);
    Assert.assertEquals(keeperMaster, currentMeta.getKeeperMaster(clusterId, shardId));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Pair(com.ctrip.xpipe.tuple.Pair) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

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