Search in sources :

Example 21 with ShardMeta

use of com.ctrip.xpipe.redis.core.entity.ShardMeta 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 22 with ShardMeta

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

the class DcMetaBuilderTest method getOrCreateShardMeta.

@Test
public void getOrCreateShardMeta() throws Exception {
    DcClusterShardTbl dcClusterShard = dcClusterShards.get(0);
    builder.getOrCreateClusterMeta(dcClusterShards.get(0).getClusterInfo());
    ClusterMeta clusterMeta = dcMeta.getClusters().get(dcClusterShard.getClusterInfo().getClusterName());
    logger.info("{}", dcClusterShard.getShardInfo());
    builder.getOrCreateShardMeta(clusterMeta.getId(), dcClusterShard.getShardInfo(), dcClusterShard.getSetinelId());
    String clusterId = dcClusterShard.getClusterInfo().getClusterName(), shardId = dcClusterShard.getShardInfo().getShardName();
    ShardMeta shardMeta = dcMeta.findCluster(clusterId).findShard(shardId);
    Assert.assertNotNull(shardMeta);
    logger.info("{}", shardMeta);
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) DcClusterShardTbl(com.ctrip.xpipe.redis.console.model.DcClusterShardTbl) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 23 with ShardMeta

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

the class ClusterMetaComparator method compare.

@Override
public void compare() {
    Triple<Set<String>, Set<String>, Set<String>> result = getDiff(current.getShards().keySet(), future.getShards().keySet());
    for (String shardId : result.getFirst()) {
        added.add(future.findShard(shardId));
    }
    for (String shardId : result.getLast()) {
        removed.add(current.findShard(shardId));
    }
    for (String shardId : result.getMiddle()) {
        ShardMeta currentMeta = current.findShard(shardId);
        ShardMeta futureMeta = future.findShard(shardId);
        if (!reflectionEquals(currentMeta, futureMeta)) {
            ShardMetaComparator comparator = new ShardMetaComparator(currentMeta, futureMeta);
            comparator.compare();
            modified.add(comparator);
        }
    }
}
Also used : Set(java.util.Set) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta)

Aggregations

ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)23 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)13 Test (org.junit.Test)11 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)4 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)4 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)3 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)3 Releasable (com.ctrip.xpipe.api.lifecycle.Releasable)1 HostPort (com.ctrip.xpipe.endpoint.HostPort)1 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)1 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)1 DataNotFoundException (com.ctrip.xpipe.redis.console.exception.DataNotFoundException)1 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)1 DcClusterShardTbl (com.ctrip.xpipe.redis.console.model.DcClusterShardTbl)1 XpipeMeta (com.ctrip.xpipe.redis.core.entity.XpipeMeta)1 XpipeMetaManager (com.ctrip.xpipe.redis.core.meta.XpipeMetaManager)1 ClusterMetaComparator (com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator)1 DefaultXpipeMetaManager (com.ctrip.xpipe.redis.core.meta.impl.DefaultXpipeMetaManager)1 AbstractMetaServerClusterTest (com.ctrip.xpipe.redis.meta.server.cluster.AbstractMetaServerClusterTest)1 DefaultSlaveOfJob (com.ctrip.xpipe.redis.meta.server.job.DefaultSlaveOfJob)1