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