Search in sources :

Example 1 with ClusterStatus

use of com.ctrip.xpipe.redis.console.migration.status.ClusterStatus in project x-pipe by ctripcorp.

the class ClusterServiceImplTest method testUpdateStatusById.

@Test
public void testUpdateStatusById() {
    ClusterTbl clusterTbl = clusterService.find(clusterName);
    ClusterStatus oldStatus = ClusterStatus.valueOf(clusterTbl.getStatus());
    ClusterStatus newStatus = ClusterStatus.different(oldStatus);
    clusterService.updateStatusById(clusterTbl.getId(), newStatus);
    ClusterTbl newCluster = clusterService.find(clusterName);
    Assert.assertEquals(newStatus.toString(), newCluster.getStatus().toString());
    newCluster.setStatus(oldStatus.toString());
    Assert.assertEquals(clusterTbl.toString(), newCluster.toString());
}
Also used : ClusterStatus(com.ctrip.xpipe.redis.console.migration.status.ClusterStatus) Test(org.junit.Test)

Example 2 with ClusterStatus

use of com.ctrip.xpipe.redis.console.migration.status.ClusterStatus 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)

Example 3 with ClusterStatus

use of com.ctrip.xpipe.redis.console.migration.status.ClusterStatus in project x-pipe by ctripcorp.

the class DefaultMigrationClusterTest2 method testUpdateStat2.

@Test(expected = ServerException.class)
public void testUpdateStat2() throws Exception {
    AtomicInteger counter = new AtomicInteger(1);
    when(clusterService.find(anyString())).thenReturn(clusterTbl);
    doAnswer(new Answer() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            int currentCounter = counter.getAndIncrement();
            if (currentCounter % 9 == 0) {
                clusterTbl.setStatus(((ClusterStatus) invocation.getArguments()[1]).toString());
            }
            return null;
        }
    }).when(clusterService).updateStatusById(anyLong(), any());
    migrationCluster.updateStat(new MigrationMigratingState(migrationCluster));
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MigrationMigratingState(com.ctrip.xpipe.redis.console.migration.status.migration.MigrationMigratingState) ClusterStatus(com.ctrip.xpipe.redis.console.migration.status.ClusterStatus) Test(org.junit.Test)

Example 4 with ClusterStatus

use of com.ctrip.xpipe.redis.console.migration.status.ClusterStatus in project x-pipe by ctripcorp.

the class DefaultMigrationClusterTest2 method testUpdateStorageClusterStatus.

@Test
public void testUpdateStorageClusterStatus() throws Exception {
    AtomicInteger counter = new AtomicInteger(1);
    when(clusterService.find(anyString())).thenReturn(clusterTbl);
    doAnswer(new Answer() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            int currentCounter = counter.getAndIncrement();
            if (currentCounter % 3 == 0) {
                clusterTbl.setStatus(((ClusterStatus) invocation.getArguments()[1]).toString());
            }
            return null;
        }
    }).when(clusterService).updateStatusById(anyLong(), any());
    migrationClusterTbl.setStatus("Checking");
    migrationCluster.updateStorageClusterStatus();
    Assert.assertEquals(MigrationStatus.Checking.getClusterStatus().toString(), clusterTbl.getStatus());
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ClusterStatus(com.ctrip.xpipe.redis.console.migration.status.ClusterStatus) Test(org.junit.Test)

Example 5 with ClusterStatus

use of com.ctrip.xpipe.redis.console.migration.status.ClusterStatus in project x-pipe by ctripcorp.

the class DefaultMigrationClusterTest2 method testUpdateStat3.

@Test(expected = ServerException.class)
public void testUpdateStat3() throws Exception {
    AtomicInteger counter = new AtomicInteger(1);
    when(clusterService.find(anyString())).thenReturn(clusterTbl);
    doAnswer(new Answer() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            int currentCounter = counter.getAndIncrement();
            if (currentCounter % 7 == 0) {
                clusterTbl.setStatus(((ClusterStatus) invocation.getArguments()[1]).toString());
            }
            return null;
        }
    }).when(clusterService).updateStatusById(anyLong(), any());
    migrationCluster.updateStat(new MigrationPublishState(migrationCluster));
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ClusterStatus(com.ctrip.xpipe.redis.console.migration.status.ClusterStatus) MigrationPublishState(com.ctrip.xpipe.redis.console.migration.status.migration.MigrationPublishState) Test(org.junit.Test)

Aggregations

ClusterStatus (com.ctrip.xpipe.redis.console.migration.status.ClusterStatus)6 Test (org.junit.Test)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Mockito.doAnswer (org.mockito.Mockito.doAnswer)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Answer (org.mockito.stubbing.Answer)4 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)1 MigrationCheckingState (com.ctrip.xpipe.redis.console.migration.status.migration.MigrationCheckingState)1 MigrationMigratingState (com.ctrip.xpipe.redis.console.migration.status.migration.MigrationMigratingState)1 MigrationPublishState (com.ctrip.xpipe.redis.console.migration.status.migration.MigrationPublishState)1 ClusterTbl (com.ctrip.xpipe.redis.console.model.ClusterTbl)1 DcTbl (com.ctrip.xpipe.redis.console.model.DcTbl)1 MigrationClusterTbl (com.ctrip.xpipe.redis.console.model.MigrationClusterTbl)1