Search in sources :

Example 46 with KeeperMeta

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

the class OneDcKeepers method killActive.

@Test
public void killActive() throws Exception {
    RedisMeta redisMaster = getRedisMaster();
    sendMessageToMasterAndTestSlaveRedis();
    System.out.println("press any key to make back keeper active");
    waitForAnyKey();
    KeeperMeta backupKeeper = getKeepersBackup().get(0);
    RedisKeeperServer redisKeeperServer = getRedisKeeperServer(backupKeeper);
    Assert.assertEquals(PARTIAL_STATE.FULL, redisKeeperServer.getRedisMaster().partialState());
    logger.info(remarkableMessage("make keeper active{}"), backupKeeper);
    setKeeperState(backupKeeper, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort());
    waitForAnyKeyToExit();
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test)

Example 47 with KeeperMeta

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

the class DefaultRedisKeeperServerTest method testKeeperServerInitState.

@Test
public void testKeeperServerInitState() throws Exception {
    KeeperMeta keeperMeta = createKeeperMeta();
    RedisKeeperServer redisKeeperServer = createRedisKeeperServer(keeperMeta);
    redisKeeperServer.initialize();
    Assert.assertEquals(KeeperState.UNKNOWN, redisKeeperServer.getRedisKeeperServerState().keeperState());
    redisKeeperServer.setRedisKeeperServerState(new RedisKeeperServerStateActive(redisKeeperServer));
    redisKeeperServer.getReplicationStore().getMetaStore().becomeActive();
    redisKeeperServer.dispose();
    redisKeeperServer = createRedisKeeperServer(keeperMeta);
    redisKeeperServer.initialize();
    Assert.assertEquals(KeeperState.PRE_ACTIVE, redisKeeperServer.getRedisKeeperServerState().keeperState());
    redisKeeperServer.setRedisKeeperServerState(new RedisKeeperServerStateBackup(redisKeeperServer));
    redisKeeperServer.getReplicationStore().getMetaStore().becomeBackup();
    redisKeeperServer.dispose();
    redisKeeperServer = createRedisKeeperServer(keeperMeta);
    redisKeeperServer.initialize();
    Assert.assertEquals(KeeperState.PRE_BACKUP, redisKeeperServer.getRedisKeeperServerState().keeperState());
}
Also used : KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test)

Example 48 with KeeperMeta

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

the class RedisKeeperServerStateActiveTest method getMaster.

@Test
public void getMaster() throws IOException, SAXException {
    Assert.assertEquals(new InetSocketAddress(redisMasterMeta.getIp(), redisMasterMeta.getPort()), active.getMaster().getSocketAddress());
    KeeperMeta upstreamKeeper = createKeeperMeta();
    upstreamKeeper.setPort(redisMasterMeta.getPort() + 1);
    ShardStatus newStatus = createShardStatus(redisKeeperServer.getCurrentKeeperMeta(), upstreamKeeper, null);
    active.setShardStatus(newStatus);
    Assert.assertEquals(new InetSocketAddress(upstreamKeeper.getIp(), upstreamKeeper.getPort()), active.getMaster().getSocketAddress());
}
Also used : ShardStatus(com.ctrip.xpipe.redis.core.meta.ShardStatus) InetSocketAddress(java.net.InetSocketAddress) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test)

Example 49 with KeeperMeta

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

the class KeeperContainerServiceTest method setUp.

@Before
public void setUp() throws Exception {
    keeperContainerService = new KeeperContainerService();
    ReflectionTestUtils.setField(keeperContainerService, "leaderElectorManager", leaderElectorManager);
    ReflectionTestUtils.setField(keeperContainerService, "metaService", metaService);
    ReflectionTestUtils.setField(keeperContainerService, "leaderElectorManager", leaderElectorManager);
    ReflectionTestUtils.setField(keeperContainerService, "keeperContainerConfig", keeperContainerConfig);
    ReflectionTestUtils.setField(keeperContainerService, "keeperConfig", keeperConfig);
    ReflectionTestUtils.setField(keeperContainerService, "keepersMonitorManager", keepersMonitorManager);
    someCluster = "someCluster";
    someShard = "someShard";
    somePort = 6789;
    someKeeperMeta = new KeeperMeta();
    someKeeperMeta.setPort(somePort);
    someKeeperTransMeta = new KeeperTransMeta();
    someKeeperTransMeta.setClusterId(someCluster);
    someKeeperTransMeta.setShardId(someShard);
    someKeeperTransMeta.setKeeperMeta(someKeeperMeta);
    when(keeperContainerConfig.getReplicationStoreDir()).thenReturn(System.getProperty("user.dir"));
    ReflectionTestUtils.setField(ComponentRegistryHolder.class, "componentRegistry", componentRegistry);
}
Also used : KeeperTransMeta(com.ctrip.xpipe.redis.core.entity.KeeperTransMeta) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Before(org.junit.Before)

Example 50 with KeeperMeta

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

the class KeeperContainerServiceTest method testAddKeeperWithSamePortMultipleTimes.

@Test(expected = RedisKeeperRuntimeException.class)
public void testAddKeeperWithSamePortMultipleTimes() throws Exception {
    String anotherShard = "anotherShard";
    KeeperMeta anotherKeeperMeta = new KeeperMeta();
    anotherKeeperMeta.setPort(somePort);
    KeeperTransMeta anotherKeeperTransMeta = new KeeperTransMeta();
    anotherKeeperTransMeta.setKeeperMeta(anotherKeeperMeta);
    anotherKeeperTransMeta.setClusterId(someCluster);
    anotherKeeperTransMeta.setShardId(anotherShard);
    keeperContainerService.add(someKeeperTransMeta);
    keeperContainerService.add(anotherKeeperTransMeta);
}
Also used : KeeperTransMeta(com.ctrip.xpipe.redis.core.entity.KeeperTransMeta) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test)

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