Search in sources :

Example 41 with Config

use of org.apache.heron.spi.common.Config 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.RUNTIME_MANAGER_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()));
    doReturn(true).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);
    ResourceCompliantRRPacking packing = new ResourceCompliantRRPacking();
    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(org.apache.heron.packing.roundrobin.ResourceCompliantRRPacking) IStateManager(org.apache.heron.spi.statemgr.IStateManager) PackingPlans(org.apache.heron.proto.system.PackingPlans) IRepacking(org.apache.heron.spi.packing.IRepacking) Config(org.apache.heron.spi.common.Config) ISchedulerClient(org.apache.heron.scheduler.client.ISchedulerClient) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 42 with Config

use of org.apache.heron.spi.common.Config in project heron by twitter.

the class RuntimeManagerMainTest method testManageTopologyFailGetSchdulerClient.

@PrepareForTest(ReflectionUtils.class)
@Test(expected = SchedulerException.class)
public void testManageTopologyFailGetSchdulerClient() throws Exception {
    config = mock(Config.class);
    when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    RuntimeManagerMain runtimeManagerMain = spy(new RuntimeManagerMain(config, MOCK_COMMAND));
    // Valid state manager class
    Mockito.when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(IStateManager.class.getName());
    PowerMockito.mockStatic(ReflectionUtils.class);
    PowerMockito.doReturn(Mockito.mock(IStateManager.class)).when(ReflectionUtils.class, "newInstance", Mockito.eq(IStateManager.class.getName()));
    // Legal request
    doReturn(true).when(runtimeManagerMain).validateRuntimeManage(any(SchedulerStateManagerAdaptor.class), eq(TOPOLOGY_NAME));
    // Failed to get ISchedulerClient
    doThrow(new SchedulerException("")).when(runtimeManagerMain).getSchedulerClient(any(Config.class));
    runtimeManagerMain.manageTopology();
}
Also used : IStateManager(org.apache.heron.spi.statemgr.IStateManager) SchedulerException(org.apache.heron.spi.scheduler.SchedulerException) Config(org.apache.heron.spi.common.Config) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 43 with Config

use of org.apache.heron.spi.common.Config in project heron by twitter.

the class RuntimeManagerMainTest method testManageTopologyOk.

@PrepareForTest(ReflectionUtils.class)
@Test
public void testManageTopologyOk() throws Exception {
    config = mock(Config.class);
    when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    RuntimeManagerMain runtimeManagerMain = spy(new RuntimeManagerMain(config, MOCK_COMMAND));
    // Valid state manager class
    Mockito.when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(IStateManager.class.getName());
    PowerMockito.mockStatic(ReflectionUtils.class);
    PowerMockito.doReturn(Mockito.mock(IStateManager.class)).when(ReflectionUtils.class, "newInstance", Mockito.eq(IStateManager.class.getName()));
    // Legal request
    doReturn(true).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));
    // Happy path
    doNothing().when(runtimeManagerMain).callRuntimeManagerRunner(any(Config.class), eq(client), eq(false));
    runtimeManagerMain.manageTopology();
}
Also used : IStateManager(org.apache.heron.spi.statemgr.IStateManager) Config(org.apache.heron.spi.common.Config) ISchedulerClient(org.apache.heron.scheduler.client.ISchedulerClient) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 44 with Config

use of org.apache.heron.spi.common.Config 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(Config.newBuilder().put(Key.PACKING_CLASS, "org.apache.heron.packing.roundrobin.ResourceCompliantRRPacking").build(), null);
    PackingPlan packingPlan = PackingTestUtils.testPackingPlan(TOPOLOGY_NAME, new RoundRobinPacking());
    assertEquals(packingPlanSize, packingPlan.getContainers().size());
    org.apache.heron.api.Config apiConfig = new org.apache.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(org.apache.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(org.apache.heron.packing.roundrobin.RoundRobinPacking) Config(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Mockito.anyString(org.mockito.Mockito.anyString) TopologyAPI(org.apache.heron.api.generated.TopologyAPI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 45 with Config

use of org.apache.heron.spi.common.Config in project heron by twitter.

the class SchedulerMainTest method setUp.

/**
 * Basic setup before executing a test case
 */
@Before
public void setUp() throws Exception {
    Config config = mock(Config.class);
    when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(STATE_MANAGER_CLASS);
    when(config.getStringValue(Key.SCHEDULER_CLASS)).thenReturn(SCHEDULER_CLASS);
    int iSchedulerServerPort = 0;
    TopologyAPI.Topology topology = TopologyTests.createTopology(iTopologyName, new org.apache.heron.api.Config(), new HashMap<String, Integer>(), new HashMap<String, Integer>());
    // Mock objects to be verified
    stateManager = mock(IStateManager.class);
    scheduler = mock(IScheduler.class);
    final SettableFuture<PackingPlans.PackingPlan> future = getTestPacking();
    when(stateManager.getPackingPlan(null, iTopologyName)).thenReturn(future);
    // Mock ReflectionUtils stuff
    PowerMockito.spy(ReflectionUtils.class);
    PowerMockito.doReturn(stateManager).when(ReflectionUtils.class, "newInstance", STATE_MANAGER_CLASS);
    PowerMockito.doReturn(scheduler).when(ReflectionUtils.class, "newInstance", SCHEDULER_CLASS);
    // Mock objects to be verified
    schedulerMain = spy(new SchedulerMain(config, topology, iSchedulerServerPort, mock(Properties.class)));
    schedulerServer = mock(SchedulerServer.class);
    doReturn(schedulerServer).when(schedulerMain).getServer(any(Config.class), eq(scheduler), eq(iSchedulerServerPort));
    doReturn(true).when(scheduler).onSchedule(any(PackingPlan.class));
    // Mock SchedulerUtils stuff
    PowerMockito.spy(SchedulerUtils.class);
    PowerMockito.doReturn(true).when(SchedulerUtils.class, "setSchedulerLocation", any(Config.class), anyString(), eq(scheduler));
    // Avoid infinite waiting
    Shutdown shutdown = mock(Shutdown.class);
    doReturn(shutdown).when(schedulerMain).getShutdown();
}
Also used : IStateManager(org.apache.heron.spi.statemgr.IStateManager) Config(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Mockito.anyString(org.mockito.Mockito.anyString) Properties(java.util.Properties) TopologyAPI(org.apache.heron.api.generated.TopologyAPI) Shutdown(org.apache.heron.scheduler.utils.Shutdown) SchedulerServer(org.apache.heron.scheduler.server.SchedulerServer) IScheduler(org.apache.heron.spi.scheduler.IScheduler) Before(org.junit.Before)

Aggregations

Config (org.apache.heron.spi.common.Config)140 Test (org.junit.Test)75 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 PackingPlan (org.apache.heron.spi.packing.PackingPlan)22 HashMap (java.util.HashMap)18 SchedulerStateManagerAdaptor (org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)18 Pair (org.apache.heron.common.basics.Pair)16 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)15 IOException (java.io.IOException)11 LauncherUtils (org.apache.heron.scheduler.utils.LauncherUtils)11 Map (java.util.Map)10 V1Volume (io.kubernetes.client.openapi.models.V1Volume)9 URI (java.net.URI)9 IScheduler (org.apache.heron.spi.scheduler.IScheduler)9 IStateManager (org.apache.heron.spi.statemgr.IStateManager)9 Before (org.junit.Before)9 File (java.io.File)7 LinkedList (java.util.LinkedList)7 Resource (org.apache.heron.spi.packing.Resource)7 CommandLine (org.apache.commons.cli.CommandLine)6