use of org.apache.heron.spi.packing.PackingPlan 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());
}
use of org.apache.heron.spi.packing.PackingPlan 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);
}
use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.
the class PackingPlanProviderTest method fetchesAndCachesPackingFromStateMgr.
@Test
public void fetchesAndCachesPackingFromStateMgr() {
PackingPlans.PackingPlan proto = PackingTestUtils.testProtoPackingPlan(topologyName, new RoundRobinPacking());
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
when(adaptor.getPackingPlan(topologyName)).thenReturn(proto);
PackingPlanProvider provider = new PackingPlanProvider(adaptor, eventManager, topologyName);
PackingPlan packing = provider.get();
Assert.assertEquals(1, packing.getContainers().size());
// once fetched it is cached
provider.get();
verify(adaptor, times(1)).getPackingPlan(topologyName);
}
use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.
the class PackingPlanProvider method getBoltInstanceNames.
public String[] getBoltInstanceNames(String... boltComponents) {
HashSet<String> boltComponentNames = new HashSet<>();
Collections.addAll(boltComponentNames, boltComponents);
PackingPlan packing = get();
ArrayList<String> boltInstanceNames = new ArrayList<>();
for (ContainerPlan containerPlan : packing.getContainers()) {
for (InstancePlan instancePlan : containerPlan.getInstances()) {
if (!boltComponentNames.contains(instancePlan.getComponentName())) {
continue;
}
String name = "container_" + containerPlan.getId() + "_" + instancePlan.getComponentName() + "_" + instancePlan.getTaskId();
boltInstanceNames.add(name);
}
}
return boltInstanceNames.toArray(new String[boltInstanceNames.size()]);
}
use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.
the class LocalSchedulerTest method testAddContainer.
@Test
public void testAddContainer() throws Exception {
Mockito.when(runtime.getLongValue(Key.NUM_CONTAINERS)).thenReturn(2L);
scheduler.initialize(config, runtime);
// verify plan is deployed and containers are created
Mockito.doNothing().when(scheduler).startExecutorMonitor(Mockito.anyInt(), Mockito.any(Process.class), Mockito.anySet());
Process mockProcessTM = Mockito.mock(Process.class);
Mockito.doReturn(mockProcessTM).when(scheduler).startExecutorProcess(0, null);
Process mockProcessWorker1 = Mockito.mock(Process.class);
Mockito.doReturn(mockProcessWorker1).when(scheduler).startExecutorProcess(1, PackingTestUtils.testContainerPlan(1).getInstances());
PackingPlan packingPlan = Mockito.mock(PackingPlan.class);
Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
containers.add(PackingTestUtils.testContainerPlan(1));
Mockito.when(packingPlan.getContainers()).thenReturn(containers);
Assert.assertTrue(scheduler.onSchedule(packingPlan));
Mockito.verify(scheduler, Mockito.times(2)).startExecutor(Mockito.anyInt(), Mockito.anySet());
// now verify add container adds new container
Process mockProcessWorker2 = Mockito.mock(Process.class);
Mockito.doReturn(mockProcessWorker2).when(scheduler).startExecutorProcess(3, PackingTestUtils.testContainerPlan(3).getInstances());
containers.clear();
containers.add(PackingTestUtils.testContainerPlan(3));
scheduler.addContainers(containers);
Mockito.verify(scheduler).startExecutor(3, PackingTestUtils.testContainerPlan(3).getInstances());
Process mockProcess = Mockito.mock(Process.class);
Mockito.doReturn(mockProcess).when(scheduler).startExecutorProcess(Mockito.anyInt(), Mockito.anySet());
containers.clear();
containers.add(PackingTestUtils.testContainerPlan(4));
containers.add(PackingTestUtils.testContainerPlan(5));
scheduler.addContainers(containers);
Mockito.verify(scheduler).startExecutor(4, PackingTestUtils.testContainerPlan(4).getInstances());
Mockito.verify(scheduler).startExecutor(5, PackingTestUtils.testContainerPlan(5).getInstances());
}
Aggregations