use of org.apache.heron.healthmgr.common.PackingPlanProvider 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.PackingPlanProvider 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.PackingPlanProvider in project heron by twitter.
the class ScaleUpResolverTest method testResolve.
@Test
public void testResolve() {
TopologyAPI.Topology topology = createTestTopology();
Config config = createConfig(topology);
PackingPlan currentPlan = createPacking(topology, config);
PackingPlanProvider packingPlanProvider = mock(PackingPlanProvider.class);
when(packingPlanProvider.get()).thenReturn(currentPlan);
ISchedulerClient scheduler = mock(ISchedulerClient.class);
when(scheduler.updateTopology(any(UpdateTopologyRequest.class))).thenReturn(true);
Instant now = Instant.now();
Collections.singletonList(new Measurement("bolt", "i1", METRIC_BACK_PRESSURE.text(), now, 123));
List<String> assignments = Collections.singletonList("bolt");
Diagnosis diagnoses = new Diagnosis(DIAGNOSIS_UNDER_PROVISIONING.text(), now, assignments, null);
List<Diagnosis> diagnosis = Collections.singletonList(diagnoses);
ExecutionContext context = mock(ExecutionContext.class);
when(context.checkpoint()).thenReturn(now);
ScaleUpResolver resolver = new ScaleUpResolver(null, packingPlanProvider, scheduler, eventManager, null);
resolver.initialize(context);
ScaleUpResolver spyResolver = spy(resolver);
doReturn(2).when(spyResolver).computeScaleUpFactor("bolt");
doReturn(currentPlan).when(spyResolver).buildNewPackingPlan(any(HashMap.class), eq(currentPlan));
Collection<Action> result = spyResolver.resolve(diagnosis);
verify(scheduler, times(1)).updateTopology(any(UpdateTopologyRequest.class));
assertEquals(1, result.size());
}
Aggregations