use of org.apache.heron.healthmgr.common.PhysicalPlanProvider in project heron by twitter.
the class ScaleUpResolverTest method createPhysicalPlanProvider.
private PhysicalPlanProvider createPhysicalPlanProvider(TopologyAPI.Topology topology) {
PhysicalPlan pp = PhysicalPlan.newBuilder().setTopology(topology).build();
PhysicalPlanProvider physicalPlanProvider = mock(PhysicalPlanProvider.class);
when(physicalPlanProvider.get()).thenReturn(pp);
return physicalPlanProvider;
}
use of org.apache.heron.healthmgr.common.PhysicalPlanProvider in project heron by twitter.
the class BufferSizeSensorTest method providesBufferSizeMetricForBolts.
@Test
public void providesBufferSizeMetricForBolts() {
PhysicalPlanProvider topologyProvider = mock(PhysicalPlanProvider.class);
when(topologyProvider.getBoltNames()).thenReturn(Arrays.asList(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 = METRIC_WAIT_Q_SIZE + boltId + MetricName.METRIC_WAIT_Q_SIZE_SUFFIX;
BackPressureSensorTest.registerStMgrInstanceMetricResponse(metricsProvider, metric, boltId.length());
}
BufferSizeSensor bufferSizeSensor = new BufferSizeSensor(null, packingPlanProvider, topologyProvider, metricsProvider);
PoliciesExecutor.ExecutionContext context = mock(PoliciesExecutor.ExecutionContext.class);
when(context.checkpoint()).thenReturn(Instant.now());
bufferSizeSensor.initialize(context);
Collection<Measurement> componentMetrics = bufferSizeSensor.fetch();
assertEquals(3, componentMetrics.size());
MeasurementsTable table = MeasurementsTable.of(componentMetrics);
assertEquals(1, table.component("bolt-1").size());
assertEquals(boltIds[0].length(), table.component("bolt-1").instance(boltIds[0]).type(METRIC_WAIT_Q_SIZE.text()).sum(), 0.01);
assertEquals(2, table.component("bolt-2").size());
assertEquals(boltIds[1].length(), table.component("bolt-2").instance(boltIds[1]).type(METRIC_WAIT_Q_SIZE.text()).sum(), 0.01);
assertEquals(boltIds[2].length(), table.component("bolt-2").instance(boltIds[2]).type(METRIC_WAIT_Q_SIZE.text()).sum(), 0.01);
}
use of org.apache.heron.healthmgr.common.PhysicalPlanProvider in project heron by twitter.
the class BackPressureSensorTest method providesBackPressureMetricForBolts.
@Test
public void providesBackPressureMetricForBolts() throws IOException {
PhysicalPlanProvider topologyProvider = mock(PhysicalPlanProvider.class);
when(topologyProvider.getBoltNames()).thenReturn(Arrays.asList(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 = METRIC_BACK_PRESSURE + boltId;
// the back pressure sensor will return average bp per second, so multiply by duration
registerStMgrInstanceMetricResponse(metricsProvider, metric, boltId.length() * DEFAULT_METRIC_DURATION.getSeconds());
}
HealthManagerMetrics publishingMetrics = mock(HealthManagerMetrics.class);
BackPressureSensor backPressureSensor = new BackPressureSensor(packingPlanProvider, topologyProvider, null, metricsProvider, publishingMetrics);
ExecutionContext context = mock(ExecutionContext.class);
when(context.checkpoint()).thenReturn(Instant.now());
backPressureSensor.initialize(context);
Collection<Measurement> componentMetrics = backPressureSensor.fetch();
assertEquals(3, componentMetrics.size());
MeasurementsTable table = MeasurementsTable.of(componentMetrics);
assertEquals(1, table.component("bolt-1").size());
assertEquals(boltIds[0].length(), table.component("bolt-1").instance(boltIds[0]).type(METRIC_BACK_PRESSURE.text()).sum(), 0.01);
assertEquals(2, table.component("bolt-2").size());
assertEquals(boltIds[1].length(), table.component("bolt-2").instance(boltIds[1]).type(METRIC_BACK_PRESSURE.text()).sum(), 0.01);
assertEquals(boltIds[2].length(), table.component("bolt-2").instance(boltIds[2]).type(METRIC_BACK_PRESSURE.text()).sum(), 0.01);
}
use of org.apache.heron.healthmgr.common.PhysicalPlanProvider in project heron by twitter.
the class ExecuteCountSensorTest method providesBoltExecutionCountMetrics.
@Test
public void providesBoltExecutionCountMetrics() {
Instant now = Instant.now();
String metric = METRIC_EXE_COUNT.text();
PhysicalPlanProvider topologyProvider = mock(PhysicalPlanProvider.class);
when(topologyProvider.getBoltNames()).thenReturn(Arrays.asList(new String[] { "bolt-1", "bolt-2" }));
MetricsProvider metricsProvider = mock(MetricsProvider.class);
Collection<Measurement> result = new ArrayList<>();
result.add(new Measurement("bolt-1", "container_1_bolt-1_1", metric, now, 123));
result.add(new Measurement("bolt-1", "container_1_bolt-1_2", metric, now, 345));
result.add(new Measurement("bolt-2", "container_1_bolt-2_3", metric, now, 321));
result.add(new Measurement("bolt-2", "container_1_bolt-2_4", metric, now, 543));
Collection<String> comps = Arrays.asList("bolt-1", "bolt-2");
when(metricsProvider.getMeasurements(any(Instant.class), eq(DEFAULT_METRIC_DURATION), eq(Collections.singletonList(metric)), eq(comps))).thenReturn(result);
ExecuteCountSensor executeCountSensor = new ExecuteCountSensor(topologyProvider, null, metricsProvider);
PoliciesExecutor.ExecutionContext context = mock(PoliciesExecutor.ExecutionContext.class);
when(context.checkpoint()).thenReturn(now);
executeCountSensor.initialize(context);
Collection<Measurement> componentMetrics = executeCountSensor.fetch();
assertEquals(4, componentMetrics.size());
MeasurementsTable table = MeasurementsTable.of(componentMetrics);
assertEquals(123, table.component("bolt-1").instance("container_1_bolt-1_1").type(metric).sum(), 0.01);
assertEquals(345, table.component("bolt-1").instance("container_1_bolt-1_2").type(metric).sum(), 0.01);
assertEquals(321, table.component("bolt-2").instance("container_1_bolt-2_3").type(metric).sum(), 0.01);
assertEquals(543, table.component("bolt-2").instance("container_1_bolt-2_4").type(metric).sum(), 0.01);
}
use of org.apache.heron.healthmgr.common.PhysicalPlanProvider in project heron by twitter.
the class ScaleUpResolverTest method testBuildPackingPlan.
@Test
public void testBuildPackingPlan() {
TopologyAPI.Topology topology = createTestTopology();
PhysicalPlanProvider topologyProvider = createPhysicalPlanProvider(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);
}
Aggregations