Search in sources :

Example 1 with SchedulerLocation

use of com.twitter.heron.proto.scheduler.Scheduler.SchedulerLocation in project incubator-heron by apache.

the class HealthManagerTest method testInitialize.

@Test
public void testInitialize() throws Exception {
    String topologyName = "testTopology";
    Config config = Config.newBuilder().put(Key.SCHEDULER_IS_SERVICE, true).put(Key.TOPOLOGY_NAME, topologyName).put(Key.ENVIRON, "environ").put(Key.CLUSTER, "cluster").build();
    SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
    SchedulerLocation schedulerLocation = SchedulerLocation.newBuilder().setTopologyName(topologyName).setHttpEndpoint("http://127.0.0.1").build();
    when(adaptor.getSchedulerLocation(anyString())).thenReturn(schedulerLocation);
    AbstractModule baseModule = HealthManager.buildMetricsProviderModule("127.0.0.1", TrackerMetricsProvider.class.getName());
    HealthManager healthManager = new HealthManager(config, baseModule);
    Map<String, Object> policy = new HashMap<>();
    policy.put(PolicyConfigKey.HEALTH_POLICY_CLASS.key(), TestPolicy.class.getName());
    policy.put("test-config", "test-value");
    String[] policyIds = { "policy" };
    HealthPolicyConfigReader policyConfigProvider = mock(HealthPolicyConfigReader.class);
    when(policyConfigProvider.getPolicyIds()).thenReturn(Arrays.asList(policyIds));
    when(policyConfigProvider.getPolicyConfig("policy")).thenReturn(policy);
    HealthManager spyHealthMgr = spy(healthManager);
    doReturn(adaptor).when(spyHealthMgr).createStateMgrAdaptor();
    doReturn(policyConfigProvider).when(spyHealthMgr).createPolicyConfigReader();
    spyHealthMgr.initialize();
    List<IHealthPolicy> healthPolicies = spyHealthMgr.getHealthPolicies();
    assertEquals(1, healthPolicies.size());
    TestPolicy healthPolicy = (TestPolicy) healthPolicies.iterator().next();
    assertNotNull(healthPolicy.schedulerClient);
    assertEquals(healthPolicy.stateMgrAdaptor, adaptor);
    assertNotNull(healthPolicy.metricsProvider);
    assertEquals(healthPolicy.config.getConfig("test-config"), "test-value");
}
Also used : HashMap(java.util.HashMap) Config(com.twitter.heron.spi.common.Config) SchedulerLocation(com.twitter.heron.proto.scheduler.Scheduler.SchedulerLocation) Mockito.anyString(org.mockito.Mockito.anyString) TrackerMetricsProvider(com.twitter.heron.healthmgr.sensors.TrackerMetricsProvider) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) AbstractModule(com.google.inject.AbstractModule) IHealthPolicy(com.microsoft.dhalion.api.IHealthPolicy) Test(org.junit.Test)

Aggregations

AbstractModule (com.google.inject.AbstractModule)1 IHealthPolicy (com.microsoft.dhalion.api.IHealthPolicy)1 TrackerMetricsProvider (com.twitter.heron.healthmgr.sensors.TrackerMetricsProvider)1 SchedulerLocation (com.twitter.heron.proto.scheduler.Scheduler.SchedulerLocation)1 Config (com.twitter.heron.spi.common.Config)1 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 Mockito.anyString (org.mockito.Mockito.anyString)1