use of com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext in project heron by twitter.
the class ScaleUpResolverTest method testScaleUpFactorComputation.
@Test
public void testScaleUpFactorComputation() {
Instant now = Instant.now();
Collection<Measurement> result = new ArrayList<>();
ExecutionContext context = Mockito.mock(ExecutionContext.class);
when(context.checkpoint()).thenReturn(now);
when(context.previousCheckpoint()).thenReturn(now);
ScaleUpResolver resolver = new ScaleUpResolver(null, null, null, eventManager, null);
resolver.initialize(context);
result.add(new Measurement("bolt", "i1", METRIC_BACK_PRESSURE.text(), now, 500));
result.add(new Measurement("bolt", "i2", METRIC_BACK_PRESSURE.text(), now, 0));
when(context.measurements()).thenReturn(MeasurementsTable.of(result));
int factor = resolver.computeScaleUpFactor("bolt");
assertEquals(4, factor);
result.clear();
result.add(new Measurement("bolt", "i1", METRIC_BACK_PRESSURE.text(), now, 750));
result.add(new Measurement("bolt", "i2", METRIC_BACK_PRESSURE.text(), now, 0));
when(context.measurements()).thenReturn(MeasurementsTable.of(result));
factor = resolver.computeScaleUpFactor("bolt");
assertEquals(8, factor);
result.clear();
result.add(new Measurement("bolt", "i1", METRIC_BACK_PRESSURE.text(), now, 400));
result.add(new Measurement("bolt", "i2", METRIC_BACK_PRESSURE.text(), now, 100));
result.add(new Measurement("bolt", "i3", METRIC_BACK_PRESSURE.text(), now, 0));
when(context.measurements()).thenReturn(MeasurementsTable.of(result));
factor = resolver.computeScaleUpFactor("bolt");
assertEquals(6, factor);
}
use of com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext 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 com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext 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