Search in sources :

Example 1 with RoundRobinPacking

use of com.twitter.heron.packing.roundrobin.RoundRobinPacking in project heron by twitter.

the class RuntimeManagerMainTest method testManageTopologyDryRun.

@PrepareForTest({ ReflectionUtils.class, Runtime.class })
@Test(expected = UpdateDryRunResponse.class)
public void testManageTopologyDryRun() throws Exception {
    config = mock(Config.class);
    // prepare packing class
    ResourceCompliantRRPacking repacking = new ResourceCompliantRRPacking();
    when(config.getStringValue(Key.REPACKING_CLASS)).thenReturn(IRepacking.class.getName());
    when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(IStateManager.class.getName());
    when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    when(config.getStringValue(RuntimeManagerRunner.NEW_COMPONENT_PARALLELISM_KEY)).thenReturn("testSpout:4,testBolt:5");
    // mock dry-run mode
    when(config.getBooleanValue(Key.DRY_RUN)).thenReturn(true);
    when(config.getDoubleValue(Key.INSTANCE_CPU)).thenReturn(1.0);
    when(config.getByteAmountValue(Key.INSTANCE_RAM)).thenReturn(ByteAmount.fromGigabytes(1));
    when(config.getByteAmountValue(Key.INSTANCE_DISK)).thenReturn(ByteAmount.fromGigabytes(1));
    RuntimeManagerMain runtimeManagerMain = spy(new RuntimeManagerMain(config, Command.UPDATE));
    // Mock validate runtime
    PowerMockito.mockStatic(ReflectionUtils.class);
    PowerMockito.doReturn(mock(IStateManager.class)).when(ReflectionUtils.class, "newInstance", eq(IStateManager.class.getName()));
    PowerMockito.doReturn(repacking).when(ReflectionUtils.class, "newInstance", eq(IRepacking.class.getName()));
    doNothing().when(runtimeManagerMain).validateRuntimeManage(any(SchedulerStateManagerAdaptor.class), eq(TOPOLOGY_NAME));
    // Successfully get ISchedulerClient
    ISchedulerClient client = mock(ISchedulerClient.class);
    doReturn(client).when(runtimeManagerMain).getSchedulerClient(any(Config.class));
    // Mock updateTopologyHandler of runner
    PowerMockito.mockStatic(Runtime.class);
    SchedulerStateManagerAdaptor manager = mock(SchedulerStateManagerAdaptor.class);
    PowerMockito.when(Runtime.schedulerStateManagerAdaptor(any(Config.class))).thenReturn(manager);
    RoundRobinPacking packing = new RoundRobinPacking();
    PackingPlans.PackingPlan currentPlan = PackingTestUtils.testProtoPackingPlan(TOPOLOGY_NAME, packing);
    // the actual topology does not matter
    doReturn(TopologyAPI.Topology.getDefaultInstance()).when(manager).getTopology(eq(TOPOLOGY_NAME));
    doReturn(currentPlan).when(manager).getPackingPlan(eq(TOPOLOGY_NAME));
    try {
        runtimeManagerMain.manageTopology();
    } finally {
        // verify scheduler client is never used
        verifyZeroInteractions(client);
    }
}
Also used : ResourceCompliantRRPacking(com.twitter.heron.packing.roundrobin.ResourceCompliantRRPacking) IStateManager(com.twitter.heron.spi.statemgr.IStateManager) PackingPlans(com.twitter.heron.proto.system.PackingPlans) RoundRobinPacking(com.twitter.heron.packing.roundrobin.RoundRobinPacking) IRepacking(com.twitter.heron.spi.packing.IRepacking) Config(com.twitter.heron.spi.common.Config) ISchedulerClient(com.twitter.heron.scheduler.client.ISchedulerClient) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with RoundRobinPacking

use of com.twitter.heron.packing.roundrobin.RoundRobinPacking in project heron by twitter.

the class RuntimeManagerRunnerTest method doUpdateTopologyHandlerTest.

private void doUpdateTopologyHandlerTest(String newParallelism, boolean expectedResult) {
    ISchedulerClient client = mock(ISchedulerClient.class);
    SchedulerStateManagerAdaptor manager = mock(SchedulerStateManagerAdaptor.class);
    RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.UPDATE, client);
    PowerMockito.mockStatic(Runtime.class);
    PowerMockito.when(Runtime.schedulerStateManagerAdaptor(runtime)).thenReturn(manager);
    RoundRobinPacking packing = new RoundRobinPacking();
    PackingPlans.PackingPlan currentPlan = PackingTestUtils.testProtoPackingPlan(TOPOLOGY_NAME, packing);
    PackingPlans.PackingPlan proposedPlan = PackingTestUtils.testProtoPackingPlan(TOPOLOGY_NAME, packing);
    Map<String, Integer> changeRequests = runner.parseNewParallelismParam(newParallelism);
    when(manager.getPackingPlan(eq(TOPOLOGY_NAME))).thenReturn(currentPlan);
    doReturn(proposedPlan).when(runner).buildNewPackingPlan(eq(currentPlan), eq(changeRequests), any(TopologyAPI.Topology.class));
    Scheduler.UpdateTopologyRequest updateTopologyRequest = Scheduler.UpdateTopologyRequest.newBuilder().setCurrentPackingPlan(currentPlan).setProposedPackingPlan(proposedPlan).build();
    when(client.updateTopology(updateTopologyRequest)).thenReturn(true);
    try {
        runner.updateTopologyHandler(TOPOLOGY_NAME, newParallelism);
    } finally {
        int expectedClientUpdateCalls = expectedResult ? 1 : 0;
        verify(client, times(expectedClientUpdateCalls)).updateTopology(updateTopologyRequest);
    }
}
Also used : RoundRobinPacking(com.twitter.heron.packing.roundrobin.RoundRobinPacking) Scheduler(com.twitter.heron.proto.scheduler.Scheduler) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) PackingPlans(com.twitter.heron.proto.system.PackingPlans) ISchedulerClient(com.twitter.heron.scheduler.client.ISchedulerClient)

Example 3 with RoundRobinPacking

use of com.twitter.heron.packing.roundrobin.RoundRobinPacking in project heron by twitter.

the class HeronMasterDriverTest method onNextAllocatedEvaluatorStartsWorker.

@Test
public void onNextAllocatedEvaluatorStartsWorker() throws Exception {
    PackingPlan packingPlan = PackingTestUtils.testPackingPlan("test", new RoundRobinPacking());
    spyDriver.scheduleHeronWorkers(packingPlan);
    assertTrue(spyDriver.lookupByContainerPlan(1).isPresent());
    PackingPlan.ContainerPlan containerPlan = spyDriver.lookupByContainerPlan(1).get();
    AllocatedEvaluator mockEvaluator = createMockEvaluator("test", getCpu(containerPlan), getRam(containerPlan));
    assertFalse(spyDriver.lookupByEvaluatorId("test").isPresent());
    spyDriver.new ContainerAllocationHandler().onNext(mockEvaluator);
    assertTrue(spyDriver.lookupByEvaluatorId("test").isPresent());
    assertEquals(Integer.valueOf(1), spyDriver.lookupByEvaluatorId("test").get());
    verify(mockEvaluator, times(1)).submitContext(any(Configuration.class));
}
Also used : RoundRobinPacking(com.twitter.heron.packing.roundrobin.RoundRobinPacking) Configuration(org.apache.reef.tang.Configuration) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) AllocatedEvaluator(org.apache.reef.driver.evaluator.AllocatedEvaluator) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with RoundRobinPacking

use of com.twitter.heron.packing.roundrobin.RoundRobinPacking in project heron by twitter.

the class SubmitterMainTest method setUp.

@Before
public void setUp() throws Exception {
    // Mock objects to be verified
    IPacking packing = mock(IPacking.class);
    statemgr = mock(IStateManager.class);
    launcher = mock(ILauncher.class);
    uploader = mock(IUploader.class);
    // Mock ReflectionUtils stuff
    PowerMockito.spy(ReflectionUtils.class);
    PowerMockito.doReturn(statemgr).when(ReflectionUtils.class, "newInstance", STATE_MANAGER_CLASS);
    PowerMockito.doReturn(launcher).when(ReflectionUtils.class, "newInstance", LAUNCHER_CLASS);
    PowerMockito.doReturn(packing).when(ReflectionUtils.class, "newInstance", PACKING_CLASS);
    PowerMockito.doReturn(uploader).when(ReflectionUtils.class, "newInstance", UPLOADER_CLASS);
    config = mock(Config.class);
    when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(STATE_MANAGER_CLASS);
    when(config.getStringValue(Key.LAUNCHER_CLASS)).thenReturn(LAUNCHER_CLASS);
    when(config.getStringValue(Key.PACKING_CLASS)).thenReturn(PACKING_CLASS);
    when(config.getStringValue(Key.UPLOADER_CLASS)).thenReturn(UPLOADER_CLASS);
    when(packing.pack()).thenReturn(PackingTestUtils.testPackingPlan(TOPOLOGY_NAME, new RoundRobinPacking()));
    topology = TopologyAPI.Topology.getDefaultInstance();
}
Also used : IStateManager(com.twitter.heron.spi.statemgr.IStateManager) IUploader(com.twitter.heron.spi.uploader.IUploader) IPacking(com.twitter.heron.spi.packing.IPacking) ILauncher(com.twitter.heron.spi.scheduler.ILauncher) RoundRobinPacking(com.twitter.heron.packing.roundrobin.RoundRobinPacking) Config(com.twitter.heron.spi.common.Config) Before(org.junit.Before)

Example 5 with RoundRobinPacking

use of com.twitter.heron.packing.roundrobin.RoundRobinPacking in project heron by twitter.

the class SchedulerMainTest method updateNumContainersIfNeeded.

@Test
public void updateNumContainersIfNeeded() {
    int configuredNumContainers = 4;
    int configuredNumStreamManagers = configuredNumContainers - 1;
    int packingPlanSize = 1;
    SubmitterMain submitterMain = new SubmitterMain(null, null);
    PackingPlan packingPlan = PackingTestUtils.testPackingPlan(TOPOLOGY_NAME, new RoundRobinPacking());
    assertEquals(packingPlanSize, packingPlan.getContainers().size());
    com.twitter.heron.api.Config apiConfig = new com.twitter.heron.api.Config();
    apiConfig.setNumStmgrs(configuredNumStreamManagers);
    TopologyAPI.Topology initialTopology = TopologyTests.createTopology(TOPOLOGY_NAME, apiConfig, new HashMap<String, Integer>(), new HashMap<String, Integer>());
    Config initialConfig = Config.newBuilder().put(Key.NUM_CONTAINERS, configuredNumContainers).put(Key.PACKING_CLASS, RoundRobinPacking.class.getName()).put(Key.TOPOLOGY_DEFINITION, initialTopology).build();
    // assert preconditions
    assertEquals(Integer.toString(configuredNumStreamManagers), apiConfig.get(com.twitter.heron.api.Config.TOPOLOGY_STMGRS));
    assertEquals(configuredNumStreamManagers, TopologyUtils.getNumContainers(initialTopology));
    assertContainerCount(configuredNumStreamManagers, initialConfig);
    Config newConfig = submitterMain.updateNumContainersIfNeeded(initialConfig, initialTopology, packingPlan);
    assertContainerCount(packingPlanSize, newConfig);
}
Also used : RoundRobinPacking(com.twitter.heron.packing.roundrobin.RoundRobinPacking) Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Mockito.anyString(org.mockito.Mockito.anyString) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

RoundRobinPacking (com.twitter.heron.packing.roundrobin.RoundRobinPacking)8 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 PackingPlans (com.twitter.heron.proto.system.PackingPlans)3 Config (com.twitter.heron.spi.common.Config)3 ISchedulerClient (com.twitter.heron.scheduler.client.ISchedulerClient)2 IStateManager (com.twitter.heron.spi.statemgr.IStateManager)2 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)2 HashSet (java.util.HashSet)2 EvaluatorRequest (org.apache.reef.driver.evaluator.EvaluatorRequest)2 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)1 ResourceCompliantRRPacking (com.twitter.heron.packing.roundrobin.ResourceCompliantRRPacking)1 Scheduler (com.twitter.heron.proto.scheduler.Scheduler)1 IPacking (com.twitter.heron.spi.packing.IPacking)1 IRepacking (com.twitter.heron.spi.packing.IRepacking)1 ILauncher (com.twitter.heron.spi.scheduler.ILauncher)1 IUploader (com.twitter.heron.spi.uploader.IUploader)1 AllocatedEvaluator (org.apache.reef.driver.evaluator.AllocatedEvaluator)1 Configuration (org.apache.reef.tang.Configuration)1