Search in sources :

Example 36 with ClusterMeta

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

the class DcMetaComparator method compare.

public void compare() {
    Triple<Set<String>, Set<String>, Set<String>> result = getDiff(current.getClusters().keySet(), future.getClusters().keySet());
    Set<String> addedClusterIds = result.getFirst();
    Set<String> intersectionClusterIds = result.getMiddle();
    Set<String> deletedClusterIds = result.getLast();
    for (String clusterId : addedClusterIds) {
        added.add(future.findCluster(clusterId));
    }
    for (String clusterId : deletedClusterIds) {
        removed.add(current.findCluster(clusterId));
    }
    for (String clusterId : intersectionClusterIds) {
        ClusterMeta currentMeta = current.findCluster(clusterId);
        ClusterMeta futureMeta = future.findCluster(clusterId);
        if (!reflectionEquals(currentMeta, futureMeta)) {
            ClusterMetaComparator clusterMetaComparator = new ClusterMetaComparator(currentMeta, futureMeta);
            clusterMetaComparator.compare();
            modified.add(clusterMetaComparator);
        }
    }
}
Also used : Set(java.util.Set) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta)

Example 37 with ClusterMeta

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

the class ClusterMetaModifiedNotifierTest method initMockData.

@Before
public void initMockData() {
    dcName = "mockedDc";
    mockedDcTbl = new DcTbl().setDcName(dcName);
    clusterName = "mockedClusterName";
    mockedClusterMeta = new ClusterMeta().setId(clusterName).setActiveDc(dcName);
    when(config.getConsoleNotifyRetryTimes()).thenReturn(retryTimes - 1);
    when(config.getConsoleNotifyRetryInterval()).thenReturn(10);
    when(config.getConsoleNotifyThreads()).thenReturn(20);
    notifier.postConstruct();
    when(metaServerConsoleServiceManagerWrapper.get(dcName)).thenReturn(mockedMetaServerConsoleService);
    doThrow(new ResourceAccessException("test")).when(mockedMetaServerConsoleService).clusterAdded(clusterName, mockedClusterMeta);
    doThrow(new ResourceAccessException("test")).when(mockedMetaServerConsoleService).clusterDeleted(clusterName);
    doThrow(new ResourceAccessException("test")).when(mockedMetaServerConsoleService).clusterModified(clusterName, mockedClusterMeta);
    when(clusterMetaService.getClusterMeta(dcName, clusterName)).thenReturn(mockedClusterMeta);
}
Also used : DcTbl(com.ctrip.xpipe.redis.console.model.DcTbl) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ResourceAccessException(org.springframework.web.client.ResourceAccessException) Before(org.junit.Before)

Example 38 with ClusterMeta

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

the class ClusterMetaServiceTest method testFindMigratingClusterMeta.

@Test
@DirtiesContext
public void testFindMigratingClusterMeta() {
    ClusterTbl cluster = clusterService.find(clusterName2);
    Assert.assertEquals(ClusterStatus.Migrating.toString(), cluster.getStatus());
    ClusterMeta clusterMetaA = clusterMetaService.getClusterMeta(dcA, clusterName2);
    ClusterMeta clusterMetaB = clusterMetaService.getClusterMeta(dcB, clusterName2);
    Assert.assertEquals(dcA, clusterMetaA.getActiveDc());
    Assert.assertEquals(dcB, clusterMetaB.getActiveDc());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 39 with ClusterMeta

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

the class ClusterMetaServiceTest method testFindNonMigratingClusterMeta.

@Test
@DirtiesContext
public void testFindNonMigratingClusterMeta() {
    ClusterMeta clusterMetaA = clusterMetaService.getClusterMeta(dcA, clusterName1);
    ClusterMeta clusterMetaB = clusterMetaService.getClusterMeta(dcB, clusterName1);
    ClusterTbl cluster = clusterService.find(clusterName1);
    Assert.assertEquals(ClusterStatus.Normal.toString(), cluster.getStatus());
    Assert.assertNotNull(clusterMetaA);
    Assert.assertNotNull(clusterMetaB);
    Assert.assertEquals(dcA, clusterMetaA.getActiveDc());
    Assert.assertEquals(dcA, clusterMetaB.getActiveDc());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 40 with ClusterMeta

use of com.ctrip.xpipe.redis.core.entity.ClusterMeta 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)

Aggregations

ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)41 Test (org.junit.Test)25 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)13 ClusterTbl (com.ctrip.xpipe.redis.console.model.ClusterTbl)10 DirtiesContext (org.springframework.test.annotation.DirtiesContext)10 MigrationClusterTbl (com.ctrip.xpipe.redis.console.model.MigrationClusterTbl)8 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)5 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)4 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)4 ClusterMetaComparator (com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator)3 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)3 AbstractMetaServerClusterTest (com.ctrip.xpipe.redis.meta.server.cluster.AbstractMetaServerClusterTest)3 IOException (java.io.IOException)2 HttpServerErrorException (org.springframework.web.client.HttpServerErrorException)2 HostPort (com.ctrip.xpipe.endpoint.HostPort)1 NodeAdded (com.ctrip.xpipe.observer.NodeAdded)1 NodeDeleted (com.ctrip.xpipe.observer.NodeDeleted)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