Search in sources :

Example 26 with ClusterTbl

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

the class ClusterServiceTest method testLoad.

@Test
public void testLoad() {
    ClusterTbl target_result = new ClusterTbl().setId(1).setClusterName("cluster1").setClusterLastModifiedTime("1234567");
    assertEquals(clusterService.find("cluster1").getId(), target_result.getId());
    assertEquals(clusterService.find("cluster1").getClusterName(), target_result.getClusterName());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) Test(org.junit.Test) AbstractConsoleTest(com.ctrip.xpipe.redis.console.AbstractConsoleTest)

Example 27 with ClusterTbl

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

the class DefaultMigrationClusterTest method testCancelOnMigrating.

@Test
@DirtiesContext
public void testCancelOnMigrating() {
    mockSuccessCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB);
    mockSuccessPrevPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
    mockFailNewPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, new Throwable("mocked new fail"));
    mockSuccessOtherDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcA);
    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);
    DcMeta DcAMeta = dcMetaService.getDcMeta(dcA);
    DcMeta DcBMeta = dcMetaService.getDcMeta(dcB);
    Assert.assertEquals(dcA, DcAMeta.findCluster("cluster1").getActiveDc());
    Assert.assertEquals(dcB, DcBMeta.findCluster("cluster1").getActiveDc());
    ClusterTbl currentCluster = clusterService.find(1);
    Assert.assertEquals(ClusterStatus.Migrating.toString(), currentCluster.getStatus());
    Assert.assertEquals(1, currentCluster.getActivedcId());
    Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
    Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
    Assert.assertTrue(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.assertNull(migrationShard.getShardMigrationResult().getSteps().get(ShardMigrationStep.MIGRATE_OTHER_DC));
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
    migrationCluster.cancel();
    DcAMeta = dcMetaService.getDcMeta(dcA);
    DcBMeta = dcMetaService.getDcMeta(dcB);
    Assert.assertEquals(dcA, DcAMeta.findCluster("cluster1").getActiveDc());
    Assert.assertEquals(dcA, DcBMeta.findCluster("cluster1").getActiveDc());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) Test(org.junit.Test) AbstractMigrationTest(com.ctrip.xpipe.redis.console.migration.AbstractMigrationTest) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 28 with ClusterTbl

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

the class DefaultMigrationClusterTest method testCancelOnChecking.

@Test
@DirtiesContext
public void testCancelOnChecking() {
    mockFailCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB);
    mockSuccessPrevPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
    mockSuccessNewPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB);
    mockSuccessOtherDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcA);
    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));
    Assert.assertNull(migrationShard.getShardMigrationResult().getSteps().get(ShardMigrationStep.CHECK));
    migrationCluster.process();
    sleep(1000);
    ClusterTbl currentCluster = clusterService.find(1);
    Assert.assertEquals(ClusterStatus.Lock.toString(), currentCluster.getStatus());
    Assert.assertEquals(1, currentCluster.getActivedcId());
    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));
    Assert.assertFalse(migrationShard.getShardMigrationResult().getSteps().get(ShardMigrationStep.CHECK).equals(""));
    migrationCluster.cancel();
    ClusterTbl afterCacelledCluster = clusterService.find(1);
    Assert.assertEquals(ClusterStatus.Normal.toString(), afterCacelledCluster.getStatus());
    Assert.assertEquals(MigrationStatus.Aborted.toString(), migrationCluster.getStatus().toString());
    Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
    MigrationClusterTbl migrationCluster = migrationService.findMigrationCluster(1, 1);
    Assert.assertEquals(MigrationStatus.Aborted.toString(), migrationCluster.getStatus());
}
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) Test(org.junit.Test) AbstractMigrationTest(com.ctrip.xpipe.redis.console.migration.AbstractMigrationTest) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 29 with ClusterTbl

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

the class DefaultMigrationClusterTest method testCancelOnInitiated.

@Test
@DirtiesContext
public void testCancelOnInitiated() {
    mockSuccessCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB);
    mockSuccessPrevPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
    mockSuccessNewPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB);
    mockSuccessOtherDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcA);
    ClusterTbl originalCluster = clusterService.find(1);
    Assert.assertEquals(ClusterStatus.Lock.toString(), originalCluster.getStatus());
    Assert.assertEquals("Initiated", migrationCluster.getStatus().toString());
    Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
    migrationCluster.cancel();
    ClusterTbl afterCacelledCluster = clusterService.find(1);
    Assert.assertEquals(ClusterStatus.Normal.toString(), afterCacelledCluster.getStatus());
    Assert.assertEquals(MigrationStatus.Aborted.toString(), migrationCluster.getStatus().toString());
    Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
    MigrationClusterTbl migrationCluster = migrationService.findMigrationCluster(1, 1);
    Assert.assertEquals(MigrationStatus.Aborted.toString(), migrationCluster.getStatus());
}
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) Test(org.junit.Test) AbstractMigrationTest(com.ctrip.xpipe.redis.console.migration.AbstractMigrationTest) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 30 with ClusterTbl

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

the class MigrationStatTest method prepareData.

private void prepareData() {
    mockedMigrationCluster = (new MigrationClusterTbl()).setId(1).setEventId(1).setClusterId(1).setDestinationDcId(2).setStatus(MigrationStatus.Initiated.toString());
    ClusterTbl clusterTbl = new ClusterTbl().setId(1).setClusterName("test-cluster").setActivedcId(1).setStatus(ClusterStatus.Lock.toString());
    when(mockedClusterService.find(1)).thenReturn(clusterTbl);
    List<ShardTbl> shards = new LinkedList<>();
    shards.add((new ShardTbl()).setId(1).setClusterId(1).setShardName("test-shard"));
    when(mockedShardService.findAllByClusterName("test-cluster")).thenReturn(shards);
    List<DcTbl> dcs = new LinkedList<>();
    dcs.add((new DcTbl()).setId(1).setDcName("ADC"));
    dcs.add((new DcTbl()).setId(2).setDcName("BDC"));
    when(mockedDcService.findClusterRelatedDc("test-cluster")).thenReturn(dcs);
    when(mockedClusterService.find(anyString())).thenReturn(clusterTbl);
    when(mockedClusterService.find(anyInt())).thenReturn(clusterTbl);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            clusterTbl.setStatus(((ClusterStatus) invocation.getArguments()[1]).toString());
            return null;
        }
    }).when(mockedClusterService).updateStatusById(anyInt(), any());
}
Also used : MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) LinkedList(java.util.LinkedList) Answer(org.mockito.stubbing.Answer) DcTbl(com.ctrip.xpipe.redis.console.model.DcTbl) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

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