Search in sources :

Example 1 with MigrationMigratingState

use of com.ctrip.xpipe.redis.console.migration.status.migration.MigrationMigratingState 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 2 with MigrationMigratingState

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

the class MigrationStatTest method testCheckingToMigrating.

@Test
public void testCheckingToMigrating() {
    when(mockedMigrationShard.getCurrentShard()).thenReturn((new ShardTbl()).setShardName("test-shard"));
    Assert.assertEquals(MigrationStatus.Initiated, migrationCluster.getStatus());
    migrationCluster.updateStat(new MigrationMigratingState(migrationCluster));
    Assert.assertEquals(MigrationStatus.Migrating, migrationCluster.getStatus());
    migrationCluster.process();
    sleep(100);
    verify(mockedMigrationShard, times(1)).doMigrate();
}
Also used : ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) MigrationMigratingState(com.ctrip.xpipe.redis.console.migration.status.migration.MigrationMigratingState) Test(org.junit.Test) AbstractConsoleTest(com.ctrip.xpipe.redis.console.AbstractConsoleTest)

Aggregations

MigrationMigratingState (com.ctrip.xpipe.redis.console.migration.status.migration.MigrationMigratingState)2 Test (org.junit.Test)2 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)1 ClusterStatus (com.ctrip.xpipe.redis.console.migration.status.ClusterStatus)1 ShardTbl (com.ctrip.xpipe.redis.console.model.ShardTbl)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1