Search in sources :

Example 91 with HostAndPort

use of redis.clients.jedis.HostAndPort in project cachecloud by sohutv.

the class JedisSentinelTest method sentinelFailover.

@Test
public void sentinelFailover() throws InterruptedException {
    Jedis j = new Jedis(sentinelForFailover.getHost(), sentinelForFailover.getPort());
    Jedis j2 = new Jedis(sentinelForFailover.getHost(), sentinelForFailover.getPort());
    try {
        List<String> masterHostAndPort = j.sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME);
        HostAndPort currentMaster = new HostAndPort(masterHostAndPort.get(0), Integer.parseInt(masterHostAndPort.get(1)));
        JedisSentinelTestUtil.waitForNewPromotedMaster(FAILOVER_MASTER_NAME, j, j2);
        masterHostAndPort = j.sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME);
        HostAndPort newMaster = new HostAndPort(masterHostAndPort.get(0), Integer.parseInt(masterHostAndPort.get(1)));
        assertNotEquals(newMaster, currentMaster);
    } finally {
        j.close();
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) HostAndPort(redis.clients.jedis.HostAndPort) Test(org.junit.Test)

Example 92 with HostAndPort

use of redis.clients.jedis.HostAndPort in project cachecloud by sohutv.

the class JedisSentinelTest method sentinel.

@Test
public void sentinel() {
    Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());
    try {
        List<Map<String, String>> masters = j.sentinelMasters();
        boolean inMasters = false;
        for (Map<String, String> master : masters) if (MASTER_NAME.equals(master.get("name")))
            inMasters = true;
        assertTrue(inMasters);
        List<String> masterHostAndPort = j.sentinelGetMasterAddrByName(MASTER_NAME);
        HostAndPort masterFromSentinel = new HostAndPort(masterHostAndPort.get(0), Integer.parseInt(masterHostAndPort.get(1)));
        assertEquals(master, masterFromSentinel);
        List<Map<String, String>> slaves = j.sentinelSlaves(MASTER_NAME);
        assertTrue(slaves.size() > 0);
        assertEquals(master.getPort(), Integer.parseInt(slaves.get(0).get("master-port")));
        // DO NOT RE-RUN TEST TOO FAST, RESET TAKES SOME TIME TO... RESET
        assertEquals(Long.valueOf(1), j.sentinelReset(MASTER_NAME));
        assertEquals(Long.valueOf(0), j.sentinelReset("woof" + MASTER_NAME));
    } finally {
        j.close();
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) HostAndPort(redis.clients.jedis.HostAndPort) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 93 with HostAndPort

use of redis.clients.jedis.HostAndPort in project cachecloud by sohutv.

the class JedisSentinelPoolTest method waitForFailover.

private void waitForFailover(JedisSentinelPool pool, HostAndPort oldMaster) throws InterruptedException {
    HostAndPort newMaster = JedisSentinelTestUtil.waitForNewPromotedMaster(MASTER_NAME, sentinelJedis1, sentinelJedis2);
    waitForJedisSentinelPoolRecognizeNewMaster(pool, newMaster);
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort)

Example 94 with HostAndPort

use of redis.clients.jedis.HostAndPort in project cachecloud by sohutv.

the class JedisSentinelPoolTest method forceFailover.

private void forceFailover(JedisSentinelPool pool) throws InterruptedException {
    HostAndPort oldMaster = pool.getCurrentHostMaster();
    // jedis connection should be master
    Jedis beforeFailoverJedis = pool.getResource();
    assertEquals("PONG", beforeFailoverJedis.ping());
    waitForFailover(pool, oldMaster);
    Jedis afterFailoverJedis = pool.getResource();
    assertEquals("PONG", afterFailoverJedis.ping());
    assertEquals("foobared", afterFailoverJedis.configGet("requirepass").get(1));
    assertEquals(2, afterFailoverJedis.getDB());
    // returning both connections to the pool should not throw
    beforeFailoverJedis.close();
    afterFailoverJedis.close();
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) Jedis(redis.clients.jedis.Jedis)

Example 95 with HostAndPort

use of redis.clients.jedis.HostAndPort in project cachecloud by sohutv.

the class JedisClusterNodeInformationParserTest method testParseNodeMyself.

@Test
public void testParseNodeMyself() {
    String nodeInfo = "9b0d2ab38ee31482c95fdb2c7847a0d40e88d518 :7379 myself,master - 0 0 1 connected 0-5460";
    HostAndPort current = new HostAndPort("localhost", 7379);
    ClusterNodeInformation clusterNodeInfo = parser.parse(nodeInfo, current);
    assertEquals(clusterNodeInfo.getNode(), current);
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) ClusterNodeInformation(redis.clients.util.ClusterNodeInformation) Test(org.junit.Test)

Aggregations

HostAndPort (redis.clients.jedis.HostAndPort)102 Test (org.junit.Test)42 HashSet (java.util.HashSet)35 JedisCluster (redis.clients.jedis.JedisCluster)35 Jedis (redis.clients.jedis.Jedis)25 LinkedHashSet (java.util.LinkedHashSet)18 JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)12 Before (org.junit.Before)9 JedisPool (redis.clients.jedis.JedisPool)9 ArrayList (java.util.ArrayList)8 ClusterNodeInformation (redis.clients.util.ClusterNodeInformation)6 AppDesc (com.sohu.cache.entity.AppDesc)5 InstanceInfo (com.sohu.cache.entity.InstanceInfo)5 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)5 IOException (java.io.IOException)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 JedisPubSub (redis.clients.jedis.JedisPubSub)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Properties (java.util.Properties)3