use of com.netflix.exhibitor.core.entities.ServerStatus in project exhibitor by soabase.
the class TestFixedAutoInstanceManagement method testReplacement.
@Test
public void testReplacement() throws Exception {
MockExhibitorInstance mockExhibitorInstance = new MockExhibitorInstance("new");
mockExhibitorInstance.getMockConfigProvider().setConfig(StringConfigs.SERVERS_SPEC, "1:a,2:b,3:c");
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES, 1);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_FIXED_ENSEMBLE_SIZE, 3);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_SETTLING_PERIOD_MS, 0);
List<ServerStatus> statuses = Lists.newArrayList();
statuses.add(new ServerStatus("a", InstanceStateTypes.SERVING.getCode(), "", true));
statuses.add(new ServerStatus("b", InstanceStateTypes.DOWN.getCode(), "", false));
statuses.add(new ServerStatus("c", InstanceStateTypes.SERVING.getCode(), "", false));
Mockito.when(mockExhibitorInstance.getMockForkJoinPool().invoke(Mockito.isA(ClusterStatusTask.class))).thenReturn(statuses);
final AtomicBoolean configWasChanged = new AtomicBoolean(false);
AutomaticInstanceManagement management = new AutomaticInstanceManagement(mockExhibitorInstance.getMockExhibitor()) {
@Override
void adjustConfig(String newSpec, String leaderHostname) throws Exception {
super.adjustConfig(newSpec, leaderHostname);
configWasChanged.set(true);
}
};
management.call();
Assert.assertTrue(configWasChanged.get());
Assert.assertEquals(mockExhibitorInstance.getMockExhibitor().getConfigManager().getConfig().getString(StringConfigs.SERVERS_SPEC), "1:a,3:c,4:new");
}
use of com.netflix.exhibitor.core.entities.ServerStatus in project exhibitor by soabase.
the class TestFixedAutoInstanceManagement method testNoRoom.
@Test
public void testNoRoom() throws Exception {
MockExhibitorInstance mockExhibitorInstance = new MockExhibitorInstance("new");
mockExhibitorInstance.getMockConfigProvider().setConfig(StringConfigs.SERVERS_SPEC, "1:a,2:b,3:c");
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES, 1);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_FIXED_ENSEMBLE_SIZE, 3);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_SETTLING_PERIOD_MS, 0);
List<ServerStatus> statuses = Lists.newArrayList();
statuses.add(new ServerStatus("a", InstanceStateTypes.SERVING.getCode(), "", true));
statuses.add(new ServerStatus("b", InstanceStateTypes.SERVING.getCode(), "", false));
statuses.add(new ServerStatus("c", InstanceStateTypes.SERVING.getCode(), "", false));
Mockito.when(mockExhibitorInstance.getMockForkJoinPool().invoke(Mockito.isA(ClusterStatusTask.class))).thenReturn(statuses);
final AtomicBoolean configWasChanged = new AtomicBoolean(false);
AutomaticInstanceManagement management = new AutomaticInstanceManagement(mockExhibitorInstance.getMockExhibitor()) {
@Override
void adjustConfig(String newSpec, String leaderHostname) throws Exception {
super.adjustConfig(newSpec, leaderHostname);
configWasChanged.set(true);
}
};
management.call();
Assert.assertFalse(configWasChanged.get());
Assert.assertEquals(mockExhibitorInstance.getMockExhibitor().getConfigManager().getConfig().getString(StringConfigs.SERVERS_SPEC), "1:a,2:b,3:c");
}
use of com.netflix.exhibitor.core.entities.ServerStatus in project exhibitor by soabase.
the class TestFixedAutoInstanceManagement method testSimpleAddition.
@Test
public void testSimpleAddition() throws Exception {
MockExhibitorInstance mockExhibitorInstance = new MockExhibitorInstance("new");
mockExhibitorInstance.getMockConfigProvider().setConfig(StringConfigs.SERVERS_SPEC, "1:a,2:b");
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES, 1);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_FIXED_ENSEMBLE_SIZE, 3);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_SETTLING_PERIOD_MS, 0);
List<ServerStatus> statuses = Lists.newArrayList();
statuses.add(new ServerStatus("a", InstanceStateTypes.SERVING.getCode(), "", true));
statuses.add(new ServerStatus("b", InstanceStateTypes.SERVING.getCode(), "", false));
Mockito.when(mockExhibitorInstance.getMockForkJoinPool().invoke(Mockito.isA(ClusterStatusTask.class))).thenReturn(statuses);
final AtomicBoolean configWasChanged = new AtomicBoolean(false);
AutomaticInstanceManagement management = new AutomaticInstanceManagement(mockExhibitorInstance.getMockExhibitor()) {
@Override
void adjustConfig(String newSpec, String leaderHostname) throws Exception {
super.adjustConfig(newSpec, leaderHostname);
configWasChanged.set(true);
}
};
management.call();
Assert.assertTrue(configWasChanged.get());
Assert.assertEquals(mockExhibitorInstance.getMockExhibitor().getConfigManager().getConfig().getString(StringConfigs.SERVERS_SPEC), "1:a,2:b,3:new");
}
use of com.netflix.exhibitor.core.entities.ServerStatus in project exhibitor by soabase.
the class TestFlexibleAutoInstanceManagement method testRemoval.
@Test
public void testRemoval() throws Exception {
MockExhibitorInstance mockExhibitorInstance = new MockExhibitorInstance("a");
mockExhibitorInstance.getMockConfigProvider().setConfig(StringConfigs.SERVERS_SPEC, "1:a,2:b,3:c");
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES, 1);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_SETTLING_PERIOD_MS, 0);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_FIXED_ENSEMBLE_SIZE, 0);
List<ServerStatus> statuses = Lists.newArrayList();
statuses.add(new ServerStatus("a", InstanceStateTypes.SERVING.getCode(), "", true));
statuses.add(new ServerStatus("b", InstanceStateTypes.DOWN.getCode(), "", false));
statuses.add(new ServerStatus("c", InstanceStateTypes.SERVING.getCode(), "", false));
Mockito.when(mockExhibitorInstance.getMockForkJoinPool().invoke(Mockito.isA(ClusterStatusTask.class))).thenReturn(statuses);
AutomaticInstanceManagement management = new AutomaticInstanceManagement(mockExhibitorInstance.getMockExhibitor());
management.call();
Assert.assertEquals(mockExhibitorInstance.getMockExhibitor().getConfigManager().getConfig().getString(StringConfigs.SERVERS_SPEC), "1:a,3:c");
}
use of com.netflix.exhibitor.core.entities.ServerStatus in project exhibitor by soabase.
the class TestFlexibleAutoInstanceManagement method testAdditionWithRemoval.
@Test
public void testAdditionWithRemoval() throws Exception {
MockExhibitorInstance mockExhibitorInstance = new MockExhibitorInstance("new");
mockExhibitorInstance.getMockConfigProvider().setConfig(StringConfigs.SERVERS_SPEC, "1:a,2:b,3:c");
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES, 1);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_SETTLING_PERIOD_MS, 0);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_FIXED_ENSEMBLE_SIZE, 0);
List<ServerStatus> statuses = Lists.newArrayList();
statuses.add(new ServerStatus("a", InstanceStateTypes.SERVING.getCode(), "", true));
statuses.add(new ServerStatus("b", InstanceStateTypes.SERVING.getCode(), "", false));
statuses.add(new ServerStatus("c", InstanceStateTypes.DOWN.getCode(), "", false));
Mockito.when(mockExhibitorInstance.getMockForkJoinPool().invoke(Mockito.isA(ClusterStatusTask.class))).thenReturn(statuses);
AutomaticInstanceManagement management = new AutomaticInstanceManagement(mockExhibitorInstance.getMockExhibitor());
management.call();
Assert.assertEquals(mockExhibitorInstance.getMockExhibitor().getConfigManager().getConfig().getString(StringConfigs.SERVERS_SPEC), "1:a,2:b,4:new");
}
Aggregations