Search in sources :

Example 16 with MigrationClusterTbl

use of com.ctrip.xpipe.redis.console.model.MigrationClusterTbl 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)

Example 17 with MigrationClusterTbl

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

the class MigrationServiceTest method createTest.

@Test
@DirtiesContext
public void createTest() throws ComponentLookupException {
    long eventId = migrationService.createMigrationEvent(createEventDemo(1, 2));
    MigrationEventTbl result = migrationService.find(eventId);
    MigrationClusterTbl result_cluster = migrationService.findMigrationCluster(eventId, 1);
    ClusterTbl cluster = clusterService.find(1);
    List<MigrationShardTbl> result_shards = migrationService.findMigrationShards(result_cluster.getId());
    Assert.assertEquals(eventId, result.getId());
    Assert.assertEquals("unit test", result.getOperator());
    Assert.assertNotNull(result_cluster);
    Assert.assertEquals(1, result_cluster.getClusterId());
    Assert.assertEquals(2, result_cluster.getDestinationDcId());
    Assert.assertEquals(MigrationStatus.Initiated.toString(), result_cluster.getStatus());
    Assert.assertEquals(ClusterStatus.Lock.toString(), cluster.getStatus());
    Assert.assertEquals(2, result_shards.size());
}
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) MigrationShardTbl(com.ctrip.xpipe.redis.console.model.MigrationShardTbl) MigrationEventTbl(com.ctrip.xpipe.redis.console.model.MigrationEventTbl) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Aggregations

MigrationClusterTbl (com.ctrip.xpipe.redis.console.model.MigrationClusterTbl)17 Test (org.junit.Test)9 ClusterTbl (com.ctrip.xpipe.redis.console.model.ClusterTbl)6 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)5 DcTbl (com.ctrip.xpipe.redis.console.model.DcTbl)5 DirtiesContext (org.springframework.test.annotation.DirtiesContext)3 DalException (org.unidal.dal.jdbc.DalException)3 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)2 AbstractMigrationTest (com.ctrip.xpipe.redis.console.migration.AbstractMigrationTest)2 DefaultMigrationCluster (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationCluster)2 DefaultMigrationShard (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationShard)2 MigrationStatus (com.ctrip.xpipe.redis.console.migration.status.MigrationStatus)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 ClusterStatus (com.ctrip.xpipe.redis.console.migration.status.ClusterStatus)1 MigrationEventTbl (com.ctrip.xpipe.redis.console.model.MigrationEventTbl)1 MigrationShardTbl (com.ctrip.xpipe.redis.console.model.MigrationShardTbl)1 ShardTbl (com.ctrip.xpipe.redis.console.model.ShardTbl)1 LinkedList (java.util.LinkedList)1