use of com.twitter.heron.healthmgr.common.TopologyProvider in project incubator-heron by apache.
the class BufferSizeSensorTest method providesBufferSizeMetricForBolts.
@Test
public void providesBufferSizeMetricForBolts() {
TopologyProvider topologyProvider = mock(TopologyProvider.class);
when(topologyProvider.getBoltNames()).thenReturn(new String[] { "bolt-1", "bolt-2" });
String[] boltIds = new String[] { "container_1_bolt-1_1", "container_2_bolt-2_22", "container_1_bolt-2_333" };
PackingPlanProvider packingPlanProvider = mock(PackingPlanProvider.class);
when(packingPlanProvider.getBoltInstanceNames("bolt-1")).thenReturn(new String[] { boltIds[0] });
when(packingPlanProvider.getBoltInstanceNames("bolt-2")).thenReturn(new String[] { boltIds[1], boltIds[2] });
MetricsProvider metricsProvider = mock(MetricsProvider.class);
for (String boltId : boltIds) {
String metric = MetricName.METRIC_BUFFER_SIZE + boltId + MetricName.METRIC_BUFFER_SIZE_SUFFIX;
registerStMgrInstanceMetricResponse(metricsProvider, metric, boltId.length());
}
BufferSizeSensor bufferSizeSensor = new BufferSizeSensor(null, packingPlanProvider, topologyProvider, metricsProvider);
Map<String, ComponentMetrics> componentMetrics = bufferSizeSensor.get();
assertEquals(2, componentMetrics.size());
assertEquals(1, componentMetrics.get("bolt-1").getMetrics().size());
assertEquals(boltIds[0].length(), componentMetrics.get("bolt-1").getMetrics(boltIds[0]).getMetricValueSum(MetricName.METRIC_BUFFER_SIZE.text()).intValue());
assertEquals(2, componentMetrics.get("bolt-2").getMetrics().size());
assertEquals(boltIds[1].length(), componentMetrics.get("bolt-2").getMetrics(boltIds[1]).getMetricValueSum(MetricName.METRIC_BUFFER_SIZE.text()).intValue());
assertEquals(boltIds[2].length(), componentMetrics.get("bolt-2").getMetrics(boltIds[2]).getMetricValueSum(MetricName.METRIC_BUFFER_SIZE.text()).intValue());
}
use of com.twitter.heron.healthmgr.common.TopologyProvider in project incubator-heron by apache.
the class BackPressureSensorTest method providesBackPressureMetricForBolts.
@Test
public void providesBackPressureMetricForBolts() {
TopologyProvider topologyProvider = mock(TopologyProvider.class);
when(topologyProvider.getBoltNames()).thenReturn(new String[] { "bolt-1", "bolt-2" });
String[] boltIds = new String[] { "container_1_bolt-1_1", "container_2_bolt-2_22", "container_1_bolt-2_333" };
PackingPlanProvider packingPlanProvider = mock(PackingPlanProvider.class);
when(packingPlanProvider.getBoltInstanceNames("bolt-1")).thenReturn(new String[] { boltIds[0] });
when(packingPlanProvider.getBoltInstanceNames("bolt-2")).thenReturn(new String[] { boltIds[1], boltIds[2] });
MetricsProvider metricsProvider = mock(MetricsProvider.class);
for (String boltId : boltIds) {
String metric = MetricName.METRIC_BACK_PRESSURE + boltId;
// the back pressure sensor will return average bp per second, so multiply by duration
BufferSizeSensorTest.registerStMgrInstanceMetricResponse(metricsProvider, metric, boltId.length() * DEFAULT_METRIC_DURATION.getSeconds());
}
BackPressureSensor backPressureSensor = new BackPressureSensor(packingPlanProvider, topologyProvider, null, metricsProvider);
Map<String, ComponentMetrics> componentMetrics = backPressureSensor.get();
assertEquals(2, componentMetrics.size());
assertEquals(1, componentMetrics.get("bolt-1").getMetrics().size());
assertEquals(boltIds[0].length(), componentMetrics.get("bolt-1").getMetrics(boltIds[0]).getMetricValueSum(MetricName.METRIC_BACK_PRESSURE.text()).intValue());
assertEquals(2, componentMetrics.get("bolt-2").getMetrics().size());
assertEquals(boltIds[1].length(), componentMetrics.get("bolt-2").getMetrics(boltIds[1]).getMetricValueSum(MetricName.METRIC_BACK_PRESSURE.text()).intValue());
assertEquals(boltIds[2].length(), componentMetrics.get("bolt-2").getMetrics(boltIds[2]).getMetricValueSum(MetricName.METRIC_BACK_PRESSURE.text()).intValue());
}
use of com.twitter.heron.healthmgr.common.TopologyProvider in project incubator-heron by apache.
the class ScaleUpResolverTest method createTopologyProvider.
private TopologyProvider createTopologyProvider(TopologyAPI.Topology topology) {
TopologyProvider topologyProvider = mock(TopologyProvider.class);
when(topologyProvider.get()).thenReturn(topology);
return topologyProvider;
}
use of com.twitter.heron.healthmgr.common.TopologyProvider in project incubator-heron by apache.
the class ScaleUpResolverTest method testBuildPackingPlan.
@Test
public void testBuildPackingPlan() {
TopologyAPI.Topology topology = createTestTopology();
TopologyProvider topologyProvider = createTopologyProvider(topology);
Config config = createConfig(topology);
PackingPlan currentPlan = createPacking(topology, config);
Map<String, Integer> changeRequest = new HashMap<>();
changeRequest.put("bolt-2", 4);
Map<String, Integer> deltaChange = new HashMap<>();
deltaChange.put("bolt-2", 3);
IRepacking repacking = mock(IRepacking.class);
when(repacking.repack(currentPlan, deltaChange)).thenReturn(currentPlan);
ScaleUpResolver resolver = new ScaleUpResolver(topologyProvider, null, null, eventManager, config);
ScaleUpResolver spyResolver = spy(resolver);
doReturn(repacking).when(spyResolver).getRepackingClass("Repacking");
PackingPlan newPlan = spyResolver.buildNewPackingPlan(changeRequest, currentPlan);
assertEquals(currentPlan, newPlan);
}
use of com.twitter.heron.healthmgr.common.TopologyProvider in project incubator-heron by apache.
the class ExecuteCountSensorTest method providesBoltExecutionCountMetrics.
@Test
public void providesBoltExecutionCountMetrics() {
TopologyProvider topologyProvider = mock(TopologyProvider.class);
when(topologyProvider.getBoltNames()).thenReturn(new String[] { "bolt-1", "bolt-2" });
MetricsProvider metricsProvider = mock(MetricsProvider.class);
Map<String, ComponentMetrics> result = new HashMap<>();
ComponentMetrics metrics = new ComponentMetrics("bolt-1");
metrics.addInstanceMetric(createTestInstanceMetric("container_1_bolt-1_1", 123));
metrics.addInstanceMetric(createTestInstanceMetric("container_1_bolt-1_2", 345));
result.put("bolt-1", metrics);
metrics = new ComponentMetrics("bolt-2");
metrics.addInstanceMetric(createTestInstanceMetric("container_1_bolt-2_3", 321));
metrics.addInstanceMetric(createTestInstanceMetric("container_1_bolt-2_4", 543));
result.put("bolt-2", metrics);
when(metricsProvider.getComponentMetrics(METRIC_EXE_COUNT.text(), DEFAULT_METRIC_DURATION, "bolt-1", "bolt-2")).thenReturn(result);
ExecuteCountSensor executeCountSensor = new ExecuteCountSensor(topologyProvider, null, metricsProvider);
Map<String, ComponentMetrics> componentMetrics = executeCountSensor.get();
assertEquals(2, componentMetrics.size());
assertEquals(123, componentMetrics.get("bolt-1").getMetrics("container_1_bolt-1_1").getMetricValueSum(METRIC_EXE_COUNT.text()).intValue());
assertEquals(345, componentMetrics.get("bolt-1").getMetrics("container_1_bolt-1_2").getMetricValueSum(METRIC_EXE_COUNT.text()).intValue());
assertEquals(321, componentMetrics.get("bolt-2").getMetrics("container_1_bolt-2_3").getMetricValueSum(METRIC_EXE_COUNT.text()).intValue());
assertEquals(543, componentMetrics.get("bolt-2").getMetrics("container_1_bolt-2_4").getMetricValueSum(METRIC_EXE_COUNT.text()).intValue());
}
Aggregations