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());
}
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());
}
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"));
}
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);
}
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);
}
}
Aggregations