Search in sources :

Example 76 with Config

use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.

the class UpdateTopologyManagerTest method mockRuntime.

private static Config mockRuntime(SchedulerStateManagerAdaptor stateManager) {
    Config runtime = mock(Config.class);
    when(runtime.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    when(runtime.get(Key.SCHEDULER_STATE_MANAGER_ADAPTOR)).thenReturn(stateManager);
    return runtime;
}
Also used : Config(com.twitter.heron.spi.common.Config)

Example 77 with Config

use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.

the class SubmitDryRunRenderTest method test.

private void test(String filename, boolean rich) throws IOException {
    InputStream stream = SubmitDryRunRenderTest.class.getResourceAsStream(filename);
    if (stream == null) {
        throw new RuntimeException("Sample output file not found");
    }
    // Input might contain UTF-8 character, so we read stream with UTF-8 decoding
    String exampleTable = IOUtils.toString(stream, StandardCharsets.UTF_8);
    TopologyAPI.Topology topology = PowerMockito.mock(TopologyAPI.Topology.class);
    Config config = Config.newBuilder().put(Key.PACKING_CLASS, "com.twitter.heron.packing.roundrobin.RoundRobinPacking").build();
    String table = new SubmitTableDryRunRenderer(new SubmitDryRunResponse(topology, config, plan), rich).render();
    assertEquals(exampleTable, table);
}
Also used : InputStream(java.io.InputStream) Config(com.twitter.heron.spi.common.Config) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI)

Example 78 with Config

use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.

the class SchedulerServerTest method testSchedulerServer.

@Test
public void testSchedulerServer() throws Exception {
    int freePort = SysUtils.getFreePort();
    IScheduler scheduler = Mockito.mock(IScheduler.class);
    Config runtime = Mockito.mock(Config.class);
    SchedulerServer schedulerServer = Mockito.spy(new SchedulerServer(runtime, scheduler, freePort));
    Assert.assertEquals(NetworkUtils.getHostName(), schedulerServer.getHost());
    Assert.assertEquals(freePort, schedulerServer.getPort());
}
Also used : Config(com.twitter.heron.spi.common.Config) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) Test(org.junit.Test)

Example 79 with Config

use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.

the class RuntimeManagerMainTest method testManageTopologyFailCall.

@PrepareForTest(ReflectionUtils.class)
@Test(expected = TopologyRuntimeManagementException.class)
public void testManageTopologyFailCall() 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));
    // Failed to callRuntimeManagerRunner
    doThrow(new TopologyRuntimeManagementException("")).when(runtimeManagerMain).callRuntimeManagerRunner(any(Config.class), eq(client), eq(false));
    runtimeManagerMain.manageTopology();
}
Also used : IStateManager(com.twitter.heron.spi.statemgr.IStateManager) 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 80 with Config

use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.

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 com.twitter.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(com.twitter.heron.spi.statemgr.IStateManager) Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Mockito.anyString(org.mockito.Mockito.anyString) Properties(java.util.Properties) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) Shutdown(com.twitter.heron.scheduler.utils.Shutdown) SchedulerServer(com.twitter.heron.scheduler.server.SchedulerServer) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) Before(org.junit.Before)

Aggregations

Config (com.twitter.heron.spi.common.Config)211 Test (org.junit.Test)125 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)60 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)53 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)43 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)35 LauncherUtils (com.twitter.heron.scheduler.utils.LauncherUtils)19 IStateManager (com.twitter.heron.spi.statemgr.IStateManager)18 IScheduler (com.twitter.heron.spi.scheduler.IScheduler)17 HashMap (java.util.HashMap)16 Before (org.junit.Before)16 ILauncher (com.twitter.heron.spi.scheduler.ILauncher)14 IOException (java.io.IOException)13 Resource (com.twitter.heron.spi.packing.Resource)12 URI (java.net.URI)12 HashSet (java.util.HashSet)11 CommandLine (org.apache.commons.cli.CommandLine)10 ByteAmount (com.twitter.heron.common.basics.ByteAmount)9 ISchedulerClient (com.twitter.heron.scheduler.client.ISchedulerClient)9 File (java.io.File)9