Search in sources :

Example 1 with ClusterNodeInformation

use of redis.clients.util.ClusterNodeInformation in project new-cloud by xie-summer.

the class JedisClusterNodeInformationParserTest method testParseNormalState.

@Test
public void testParseNormalState() {
    String nodeInfo = "5f4a2236d00008fba7ac0dd24b95762b446767bd 192.168.0.3:7380 master - 0 1400598804016 2 connected 5461-10922";
    HostAndPort current = new HostAndPort("localhost", 7379);
    ClusterNodeInformation clusterNodeInfo = parser.parse(nodeInfo, current);
    assertNotEquals(clusterNodeInfo.getNode(), current);
    assertEquals(clusterNodeInfo.getNode(), new HostAndPort("192.168.0.3", 7380));
    for (int slot = 5461; slot <= 10922; slot++) {
        assertTrue(clusterNodeInfo.getAvailableSlots().contains(slot));
    }
    assertTrue(clusterNodeInfo.getSlotsBeingImported().isEmpty());
    assertTrue(clusterNodeInfo.getSlotsBeingMigrated().isEmpty());
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) ClusterNodeInformation(redis.clients.util.ClusterNodeInformation) Test(org.junit.Test)

Example 2 with ClusterNodeInformation

use of redis.clients.util.ClusterNodeInformation in project new-cloud by xie-summer.

the class JedisClusterNodeInformationParserTest method testParseSlotBeingMigrated.

@Test
public void testParseSlotBeingMigrated() {
    String nodeInfo = "5f4a2236d00008fba7ac0dd24b95762b446767bd :7379 myself,master - 0 0 1 connected 0-5459 [5460->-5f4a2236d00008fba7ac0dd24b95762b446767bd] [5461-<-5f4a2236d00008fba7ac0dd24b95762b446767bd]";
    HostAndPort current = new HostAndPort("localhost", 7379);
    ClusterNodeInformation clusterNodeInfo = parser.parse(nodeInfo, current);
    assertEquals(clusterNodeInfo.getNode(), current);
    for (int slot = 0; slot <= 5459; slot++) {
        assertTrue(clusterNodeInfo.getAvailableSlots().contains(slot));
    }
    assertEquals(1, clusterNodeInfo.getSlotsBeingMigrated().size());
    assertTrue(clusterNodeInfo.getSlotsBeingMigrated().contains(5460));
    assertEquals(1, clusterNodeInfo.getSlotsBeingImported().size());
    assertTrue(clusterNodeInfo.getSlotsBeingImported().contains(5461));
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) ClusterNodeInformation(redis.clients.util.ClusterNodeInformation) Test(org.junit.Test)

Example 3 with ClusterNodeInformation

use of redis.clients.util.ClusterNodeInformation in project cachecloud by sohutv.

the class JedisClusterNodeInformationParserTest method testParseNormalState.

@Test
public void testParseNormalState() {
    String nodeInfo = "5f4a2236d00008fba7ac0dd24b95762b446767bd 192.168.0.3:7380 master - 0 1400598804016 2 connected 5461-10922";
    HostAndPort current = new HostAndPort("localhost", 7379);
    ClusterNodeInformation clusterNodeInfo = parser.parse(nodeInfo, current);
    assertNotEquals(clusterNodeInfo.getNode(), current);
    assertEquals(clusterNodeInfo.getNode(), new HostAndPort("192.168.0.3", 7380));
    for (int slot = 5461; slot <= 10922; slot++) {
        assertTrue(clusterNodeInfo.getAvailableSlots().contains(slot));
    }
    assertTrue(clusterNodeInfo.getSlotsBeingImported().isEmpty());
    assertTrue(clusterNodeInfo.getSlotsBeingMigrated().isEmpty());
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) ClusterNodeInformation(redis.clients.util.ClusterNodeInformation) Test(org.junit.Test)

Example 4 with ClusterNodeInformation

use of redis.clients.util.ClusterNodeInformation in project cachecloud by sohutv.

the class JedisClusterNodeInformationParserTest method testParseSlotBeingMigrated.

@Test
public void testParseSlotBeingMigrated() {
    String nodeInfo = "5f4a2236d00008fba7ac0dd24b95762b446767bd :7379 myself,master - 0 0 1 connected 0-5459 [5460->-5f4a2236d00008fba7ac0dd24b95762b446767bd] [5461-<-5f4a2236d00008fba7ac0dd24b95762b446767bd]";
    HostAndPort current = new HostAndPort("localhost", 7379);
    ClusterNodeInformation clusterNodeInfo = parser.parse(nodeInfo, current);
    assertEquals(clusterNodeInfo.getNode(), current);
    for (int slot = 0; slot <= 5459; slot++) {
        assertTrue(clusterNodeInfo.getAvailableSlots().contains(slot));
    }
    assertEquals(1, clusterNodeInfo.getSlotsBeingMigrated().size());
    assertTrue(clusterNodeInfo.getSlotsBeingMigrated().contains(5460));
    assertEquals(1, clusterNodeInfo.getSlotsBeingImported().size());
    assertTrue(clusterNodeInfo.getSlotsBeingImported().contains(5461));
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) ClusterNodeInformation(redis.clients.util.ClusterNodeInformation) Test(org.junit.Test)

Example 5 with ClusterNodeInformation

use of redis.clients.util.ClusterNodeInformation in project new-cloud by xie-summer.

the class JedisClusterInfoCache method discoverClusterNodesAndSlots.

public void discoverClusterNodesAndSlots(Jedis jedis) {
    w.lock();
    try {
        this.nodes.clear();
        this.slots.clear();
        String localNodes = jedis.clusterNodes();
        for (String nodeInfo : localNodes.split("\n")) {
            ClusterNodeInformation clusterNodeInfo = nodeInfoParser.parse(nodeInfo, new HostAndPort(jedis.getClient().getHost(), jedis.getClient().getPort()));
            HostAndPort targetNode = clusterNodeInfo.getNode();
            setNodeIfNotExist(targetNode);
            assignSlotsToNode(clusterNodeInfo.getAvailableSlots(), targetNode);
        }
    } finally {
        w.unlock();
    }
}
Also used : ClusterNodeInformation(redis.clients.util.ClusterNodeInformation)

Aggregations

ClusterNodeInformation (redis.clients.util.ClusterNodeInformation)8 Test (org.junit.Test)6 HostAndPort (redis.clients.jedis.HostAndPort)6