Search in sources :

Example 6 with ClusterTbl

use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.

the class SingleShardMigrationTest method testMigrateOtherDcExceptionFail.

@Test
@DirtiesContext
public void testMigrateOtherDcExceptionFail() {
    mockSuccessCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB);
    mockSuccessPrevPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
    mockSuccessNewPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB);
    mockFailOtherDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcA, new Throwable("mocked other fail"));
    ClusterTbl originalCluster = clusterService.find(1);
    Assert.assertEquals(ClusterStatus.Lock.toString(), originalCluster.getStatus());
    Assert.assertEquals(1, originalCluster.getActivedcId());
    Assert.assertEquals(1, migrationCluster.getMigrationCluster().getSourceDcId());
    Assert.assertEquals(2, migrationCluster.getMigrationCluster().getDestinationDcId());
    Assert.assertEquals("Initiated", migrationCluster.getStatus().toString());
    Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_PREVIOUS_PRIMARY_DC));
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC));
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_OTHER_DC));
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
    migrationCluster.process();
    sleep(1000);
    ClusterTbl currentCluster = clusterService.find(1);
    Assert.assertEquals(ClusterStatus.Normal.toString(), currentCluster.getStatus());
    Assert.assertEquals(2, currentCluster.getActivedcId());
    Assert.assertEquals(ShardMigrationResultStatus.SUCCESS, migrationShard.getShardMigrationResult().getStatus());
    Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
    Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_PREVIOUS_PRIMARY_DC));
    Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC));
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_OTHER_DC));
    Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
    ClusterMeta prevPrimaryDcMeta = clusterMetaService.getClusterMeta(dcA, "cluster1");
    Assert.assertEquals(dcB, prevPrimaryDcMeta.getActiveDc());
    ClusterMeta newPrimaryDcMeta = clusterMetaService.getClusterMeta(dcB, "cluster1");
    Assert.assertEquals(dcB, newPrimaryDcMeta.getActiveDc());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 7 with ClusterTbl

use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.

the class ClusterDaoTest method testCreateCluster.

@Test
public void testCreateCluster() throws DalException {
    ClusterTbl newCluster = clusterDao.createCluster(clusterTbl);
    Assert.assertEquals(clusterTbl.getId(), newCluster.getId());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 8 with ClusterTbl

use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.

the class ClusterDaoTest method testFindClusterAndOrgByName.

@Test
public void testFindClusterAndOrgByName() throws DalException {
    String clusterName = "cluster2";
    ClusterTbl clusterTbl1 = clusterDao.findClusterAndOrgByName(clusterName);
    List<OrganizationTbl> orgs = organizationService.getAllOrganizations();
    orgs.forEach(org -> logger.info("{}", org));
    logger.info("{}", clusterTbl1);
    Assert.assertEquals(2L, (long) clusterTbl1.getOrganizationInfo().getId());
    Assert.assertEquals("org-1", clusterTbl1.getClusterOrgName());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) OrganizationTbl(com.ctrip.xpipe.redis.console.model.OrganizationTbl) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 9 with ClusterTbl

use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.

the class KeepercontainerServiceImplTest method testFindKeeperCountByClusterWithAllKeeperDeleted.

@Test
@DirtiesContext
public void testFindKeeperCountByClusterWithAllKeeperDeleted() {
    String clusterName = "cluster4";
    ClusterTbl clusterTbl = clusterDao.findClusterAndOrgByName(clusterName);
    List<KeepercontainerTbl> keeperCount = keepercontainerService.findBestKeeperContainersByDcCluster(dcNames[0], clusterName);
    keeperCount.forEach(kc -> logger.info("{}", kc));
    Assert.assertTrue(keeperCount.stream().allMatch(kc -> kc.getKeepercontainerOrgId() == clusterTbl.getClusterOrgId()));
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) DirtiesContext(org.springframework.test.annotation.DirtiesContext) ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) ClusterDao(com.ctrip.xpipe.redis.console.dao.ClusterDao) List(java.util.List) KeepercontainerTbl(com.ctrip.xpipe.redis.console.model.KeepercontainerTbl) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) IOException(java.io.IOException) Assert(org.junit.Assert) KeeperContainerCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.KeeperContainerCreateInfo) XPipeConsoleConstant(com.ctrip.xpipe.redis.console.constant.XPipeConsoleConstant) Before(org.junit.Before) KeepercontainerTbl(com.ctrip.xpipe.redis.console.model.KeepercontainerTbl) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 10 with ClusterTbl

use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.

the class ClusterMetaServiceImplTest method testGetClusterMetaCurrentPrimaryDcNotMigrating.

@Test
public void testGetClusterMetaCurrentPrimaryDcNotMigrating() {
    long currentActiveDcId = randomInt();
    long clusterId = randomInt();
    long destinationDcId = currentActiveDcId + 1;
    DcTbl dcTbl = new DcTbl();
    ClusterTbl clusterTbl = new ClusterTbl();
    clusterTbl.setId(clusterId);
    clusterTbl.setActivedcId(currentActiveDcId);
    when(migrationService.findLatestUnfinishedMigrationCluster(clusterId)).thenReturn(new MigrationClusterTbl().setDestinationDcId(destinationDcId));
    dcTbl.setId(destinationDcId);
    for (ClusterStatus clusterStatus : ClusterStatus.values()) {
        if (clusterStatus == ClusterStatus.Migrating) {
            continue;
        }
        clusterTbl.setStatus(clusterStatus.toString());
        Assert.assertEquals(currentActiveDcId, clusterMetaServiceImpl.getClusterMetaCurrentPrimaryDc(dcTbl, clusterTbl));
    }
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) DcTbl(com.ctrip.xpipe.redis.console.model.DcTbl) ClusterStatus(com.ctrip.xpipe.redis.console.migration.status.ClusterStatus) Test(org.junit.Test) AbstractConsoleTest(com.ctrip.xpipe.redis.console.AbstractConsoleTest)

Aggregations

ClusterTbl (com.ctrip.xpipe.redis.console.model.ClusterTbl)34 Test (org.junit.Test)28 MigrationClusterTbl (com.ctrip.xpipe.redis.console.model.MigrationClusterTbl)20 DirtiesContext (org.springframework.test.annotation.DirtiesContext)19 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)10 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)10 AbstractMigrationTest (com.ctrip.xpipe.redis.console.migration.AbstractMigrationTest)6 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)5 DcTbl (com.ctrip.xpipe.redis.console.model.DcTbl)4 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)3 RetMessage (com.ctrip.xpipe.redis.console.controller.api.RetMessage)3 ClusterCreateInfo (com.ctrip.xpipe.redis.console.controller.api.data.meta.ClusterCreateInfo)3 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)1 XPipeConsoleConstant (com.ctrip.xpipe.redis.console.constant.XPipeConsoleConstant)1 KeeperContainerCreateInfo (com.ctrip.xpipe.redis.console.controller.api.data.meta.KeeperContainerCreateInfo)1 ClusterDao (com.ctrip.xpipe.redis.console.dao.ClusterDao)1 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)1 RetryCondition (com.ctrip.xpipe.redis.console.job.retry.RetryCondition)1 RetryNTimesOnCondition (com.ctrip.xpipe.redis.console.job.retry.RetryNTimesOnCondition)1 ClusterStatus (com.ctrip.xpipe.redis.console.migration.status.ClusterStatus)1