Search in sources :

Example 11 with ServerStatus

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");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) Test(org.testng.annotations.Test)

Example 12 with ServerStatus

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");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) Test(org.testng.annotations.Test)

Example 13 with ServerStatus

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");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) Test(org.testng.annotations.Test)

Example 14 with ServerStatus

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");
}
Also used : ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) Test(org.testng.annotations.Test)

Example 15 with ServerStatus

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");
}
Also used : ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) Test(org.testng.annotations.Test)

Aggregations

ServerStatus (com.netflix.exhibitor.core.entities.ServerStatus)18 Test (org.testng.annotations.Test)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 ServerList (com.netflix.exhibitor.core.state.ServerList)4 InstanceStateTypes (com.netflix.exhibitor.core.state.InstanceStateTypes)3 ServerSpec (com.netflix.exhibitor.core.state.ServerSpec)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ClusterStatusTask (com.netflix.exhibitor.core.automanage.ClusterStatusTask)1 InstanceConfig (com.netflix.exhibitor.core.config.InstanceConfig)1 LoadedInstanceConfig (com.netflix.exhibitor.core.config.LoadedInstanceConfig)1 PseudoLock (com.netflix.exhibitor.core.config.PseudoLock)1 IOException (java.io.IOException)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 GenericEntity (javax.ws.rs.core.GenericEntity)1 JsonNode (org.codehaus.jackson.JsonNode)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1