Search in sources :

Example 1 with SchedulerLocation

use of org.apache.heron.proto.scheduler.Scheduler.SchedulerLocation in project heron by twitter.

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);
    HealthManagerMetrics publishingMetrics = mock(HealthManagerMetrics.class);
    AbstractModule baseModule = HealthManager.buildBaseModule("127.0.0.1", TrackerMetricsProvider.class.getName(), publishingMetrics);
    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(org.apache.heron.spi.common.Config) SchedulerLocation(org.apache.heron.proto.scheduler.Scheduler.SchedulerLocation) Mockito.anyString(org.mockito.Mockito.anyString) TrackerMetricsProvider(org.apache.heron.healthmgr.sensors.TrackerMetricsProvider) SchedulerStateManagerAdaptor(org.apache.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 HashMap (java.util.HashMap)1 TrackerMetricsProvider (org.apache.heron.healthmgr.sensors.TrackerMetricsProvider)1 SchedulerLocation (org.apache.heron.proto.scheduler.Scheduler.SchedulerLocation)1 Config (org.apache.heron.spi.common.Config)1 SchedulerStateManagerAdaptor (org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)1 Test (org.junit.Test)1 Mockito.anyString (org.mockito.Mockito.anyString)1