Search in sources :

Example 16 with HostPort

use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.

the class DefaultMigrationShardTest method testMigrateSuccess.

@Test
public void testMigrateSuccess() {
    when(mockedCommandBuilder.buildPrevPrimaryDcCommand("test-cluster", "test-shard", "dc-a")).thenReturn(new AbstractCommand<MetaServerConsoleService.PreviousPrimaryDcMessage>() {

        @Override
        protected void doExecute() throws Exception {
            future().setSuccess(new MetaServerConsoleService.PreviousPrimaryDcMessage(new HostPort("127.0.0.1", 0), null, "Test-Success"));
        }

        @Override
        protected void doReset() {
        }

        @Override
        public String getName() {
            return "testPrevPrimaryDcSuccess";
        }
    });
    when(mockedCommandBuilder.buildNewPrimaryDcCommand(eq("test-cluster"), eq("test-shard"), eq("dc-b"), anyObject())).thenReturn(new AbstractCommand<MetaServerConsoleService.PrimaryDcChangeMessage>() {

        @Override
        protected void doExecute() throws Exception {
            future().setSuccess(new MetaServerConsoleService.PrimaryDcChangeMessage(MetaServerConsoleService.PRIMARY_DC_CHANGE_RESULT.SUCCESS, "Test-success"));
        }

        @Override
        protected void doReset() {
        }

        @Override
        public String getName() {
            return "testNewPrimaryDcSuccess";
        }
    });
    when(mockedCommandBuilder.buildOtherDcCommand("test-cluster", "test-shard", "dc-b", "dc-a")).thenReturn(new AbstractCommand<MetaServerConsoleService.PrimaryDcChangeMessage>() {

        @Override
        protected void doExecute() throws Exception {
            future().setSuccess(new MetaServerConsoleService.PrimaryDcChangeMessage(MetaServerConsoleService.PRIMARY_DC_CHANGE_RESULT.SUCCESS, "Test-success"));
        }

        @Override
        protected void doReset() {
        }

        @Override
        public String getName() {
            return "testNewPrimaryDcSuccess";
        }
    });
    Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC));
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_PREVIOUS_PRIMARY_DC));
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_OTHER_DC));
    migrationShard.doMigrate();
    verify(mockedMigrationService, times(5)).updateMigrationShardLogById(anyLong(), anyString());
    Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
    Assert.assertEquals(ShardMigrationResultStatus.SUCCESS, migrationShard.getShardMigrationResult().getStatus());
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) Test(org.junit.Test) AbstractConsoleTest(com.ctrip.xpipe.redis.console.AbstractConsoleTest)

Example 17 with HostPort

use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.

the class SentinelUpdateControllerTest method testConvert2SentinelTbl.

@Test
public void testConvert2SentinelTbl() throws Exception {
    when(dcService.find(anyString())).thenReturn(new DcTbl().setId(1));
    SentinelModel sentinelModel = new SentinelModel().setDcName("JQ").setDesc("test").setSentinels(Arrays.asList(new HostPort("127.0.0.1", 6379), new HostPort("127.0.0.1", 6380), new HostPort("127.0.0.1", 6381)));
    SetinelTbl setinelTbl = controller.convert2SentinelTbl(sentinelModel);
    Assert.assertEquals(1, setinelTbl.getDcId());
    Assert.assertEquals("test", setinelTbl.getSetinelDescription());
    Assert.assertEquals("127.0.0.1:6379,127.0.0.1:6380,127.0.0.1:6381", setinelTbl.getSetinelAddress());
}
Also used : DcTbl(com.ctrip.xpipe.redis.console.model.DcTbl) SentinelModel(com.ctrip.xpipe.redis.console.model.SentinelModel) HostPort(com.ctrip.xpipe.endpoint.HostPort) SetinelTbl(com.ctrip.xpipe.redis.console.model.SetinelTbl) Test(org.junit.Test)

Example 18 with HostPort

use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.

the class AlertEntityTest method testRemoveSpecialCharacters.

@Test
public void testRemoveSpecialCharacters() {
    AlertEntity alertEntity = new AlertEntity(new HostPort("", 6379), "dc", "cluster", "shard", "message\nmessage1", ALERT_TYPE.CLIENT_INCONSIS);
    System.out.println(alertEntity.getMessage());
    alertEntity.removeSpecialCharacters();
    System.out.println(alertEntity.getMessage());
    Assert.assertFalse(alertEntity.getMessage().contains("\n"));
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) Test(org.junit.Test)

Example 19 with HostPort

use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.

the class NotificationManagerTest method beforeNotificationManagerTest.

@Before
public void beforeNotificationManagerTest() {
    MockitoAnnotations.initMocks(this);
    cluster = "cluster-test";
    shard = "shard-test";
    message = "test-message";
    hostPort = new HostPort("192.168.1.10", 6379);
    when(mockServer.amILeader()).thenReturn(Boolean.TRUE);
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) Before(org.junit.Before)

Example 20 with HostPort

use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.

the class DefaultDelayMonitorTest method avoidNullPointerException.

@Test
public void avoidNullPointerException() {
    DelaySampleResult sampleResult = new DelaySampleResult(System.currentTimeMillis(), "cluster", "shard");
    sampleResult.addSlaveDelayNanos(new HostPort("127.0.0.1", 6379), System.nanoTime());
    sampleResult.addSlaveDelayNanos(new HostPort("127.0.0.1", 6380), System.nanoTime());
    try {
        delayMonitor.getDelayCollectors().forEach(collector -> collector.collect(sampleResult));
    } catch (Exception e) {
        Assert.assertFalse(e instanceof NullPointerException);
    }
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) IOException(java.io.IOException) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Aggregations

HostPort (com.ctrip.xpipe.endpoint.HostPort)79 Test (org.junit.Test)31 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)7 LinkedList (java.util.LinkedList)7 ALERT_TYPE (com.ctrip.xpipe.redis.console.alert.ALERT_TYPE)6 MasterInfo (com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo)6 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)6 ClusterShardHostPort (com.ctrip.xpipe.endpoint.ClusterShardHostPort)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Map (java.util.Map)5 RedisConf (com.ctrip.xpipe.redis.console.health.redisconf.RedisConf)4 MasterNotFoundException (com.ctrip.xpipe.redis.console.resources.MasterNotFoundException)4 XpipeMetaManager (com.ctrip.xpipe.redis.core.meta.XpipeMetaManager)4 Set (java.util.Set)4 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)3 AlertEntity (com.ctrip.xpipe.redis.console.alert.AlertEntity)3 AlertManager (com.ctrip.xpipe.redis.console.alert.AlertManager)3 DefaultRedisSessionManager (com.ctrip.xpipe.redis.console.health.DefaultRedisSessionManager)3 ClusterListClusterModel (com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel)3