Search in sources :

Example 31 with Config

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

the class LocalLauncherTest method testLaunch.

@Test
public void testLaunch() throws Exception {
    Config config = createRunnerConfig();
    Config runtime = Mockito.mock(Config.class);
    URI mockURI = new URI("h:a");
    Mockito.doReturn(mockURI).when(runtime).get(Key.TOPOLOGY_PACKAGE_URI);
    PackingPlan packingPlan = Mockito.mock(PackingPlan.class);
    PowerMockito.spy(LocalContext.class);
    PowerMockito.doReturn(WORKING_DIRECTORY).when(LocalContext.class, "workingDirectory", config);
    LocalLauncher localLauncher = Mockito.spy(new LocalLauncher());
    localLauncher.initialize(config, runtime);
    // Failed to setup working directory
    Mockito.doReturn(false).when(localLauncher).setupWorkingDirectoryAndExtractPackages();
    Assert.assertFalse(localLauncher.launch(packingPlan));
    // setup successfully
    Mockito.doReturn(true).when(localLauncher).setupWorkingDirectoryAndExtractPackages();
    String[] expectedSchedulerCommand = { "expected", "scheduler", "command" };
    Mockito.doReturn(expectedSchedulerCommand).when(localLauncher).getSchedulerCommand();
    // Failed to start the Scheduler Process
    Mockito.doReturn(null).when(localLauncher).startScheduler(Mockito.any(String[].class));
    Assert.assertFalse(localLauncher.launch(packingPlan));
    Mockito.verify(localLauncher).startScheduler(expectedSchedulerCommand);
    // Happy path
    Mockito.doReturn(Mockito.mock(Process.class)).when(localLauncher).startScheduler(Mockito.any(String[].class));
    Assert.assertTrue(localLauncher.launch(packingPlan));
    Mockito.verify(localLauncher, Mockito.times(2)).startScheduler(expectedSchedulerCommand);
    localLauncher.close();
}
Also used : Config(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) URI(java.net.URI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 32 with Config

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

the class LocalLauncherTest method createRunnerConfig.

private static Config createRunnerConfig() {
    Config config = Mockito.mock(Config.class);
    Mockito.when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    Mockito.when(config.getStringValue(Key.CLUSTER)).thenReturn(CLUSTER);
    Mockito.when(config.getStringValue(Key.ROLE)).thenReturn(ROLE);
    Mockito.when(config.getStringValue(Key.ENVIRON)).thenReturn(ENVIRON);
    return config;
}
Also used : Config(org.apache.heron.spi.common.Config)

Example 33 with Config

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

the class MarathonSchedulerTest method testGetJobLinks.

@Test
public void testGetJobLinks() throws Exception {
    final String SCHEDULER_URI = "http://marathon.scheduler.uri";
    final String JOB_LINK = SCHEDULER_URI + MarathonConstants.JOB_LINK + TOPOLOGY_NAME;
    Config mockConfig = Mockito.mock(Config.class);
    Mockito.when(mockConfig.getStringValue(MarathonContext.HERON_MARATHON_SCHEDULER_URI)).thenReturn(SCHEDULER_URI);
    Config mockRuntime = Mockito.mock(Config.class);
    Mockito.when(mockRuntime.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    scheduler.initialize(mockConfig, mockRuntime);
    List<String> links = scheduler.getJobLinks();
    Assert.assertEquals(1, links.size());
    System.out.println(links.get(0));
    System.out.println(JOB_LINK);
    Assert.assertTrue(links.get(0).equals(JOB_LINK));
}
Also used : Config(org.apache.heron.spi.common.Config) Test(org.junit.Test)

Example 34 with Config

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

the class MesosLauncherTest method testGetSchedulerCommand.

@Test
@SuppressWarnings("unchecked")
public void testGetSchedulerCommand() throws Exception {
    final String JAVA_HOME = "java_home";
    final String NATIVE_LIBRARY_PATH = "native_library_path";
    final URI mockURI = TypeUtils.getURI("file:///mock/uri");
    Config config = Mockito.mock(Config.class);
    Mockito.when(config.getStringValue(MesosContext.SCHEDULER_WORKING_DIRECTORY)).thenReturn("working-dir");
    Mockito.when(config.getStringValue(MesosContext.HERON_MESOS_NATIVE_LIBRARY_PATH)).thenReturn(NATIVE_LIBRARY_PATH);
    Mockito.when(config.getStringValue(Key.JAVA_HOME)).thenReturn(JAVA_HOME);
    Config runtime = Mockito.mock(Config.class);
    Mockito.when(runtime.get(Key.TOPOLOGY_PACKAGE_URI)).thenReturn(mockURI);
    MesosLauncher launcher = Mockito.spy(MesosLauncher.class);
    String[] mockCommand = new String[] { "mock", "scheduler", "command" };
    Mockito.doReturn(mockCommand).when(launcher).schedulerCommandArgs(Mockito.anyList());
    launcher.initialize(config, runtime);
    String[] command = launcher.getSchedulerCommand();
    // Assert the content of command
    Assert.assertEquals(String.format("%s/bin/java", JAVA_HOME), command[0]);
    Assert.assertEquals(String.format("-Djava.library.path=%s", NATIVE_LIBRARY_PATH), command[1]);
    Assert.assertEquals("-cp", command[2]);
    Assert.assertEquals(String.format("-Pheron.package.topology.uri=%s", mockURI.toString()), command[5]);
    Assert.assertEquals(mockCommand[0], command[6]);
    Assert.assertEquals(mockCommand[1], command[7]);
    Assert.assertEquals(mockCommand[2], command[8]);
}
Also used : Config(org.apache.heron.spi.common.Config) URI(java.net.URI) Test(org.junit.Test)

Example 35 with Config

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

the class MesosLauncherTest method testLaunch.

@Test
public void testLaunch() throws Exception {
    MesosLauncher launcher = Mockito.spy(MesosLauncher.class);
    PackingPlan packingPlan = Mockito.mock(PackingPlan.class);
    Config config = Mockito.mock(Config.class);
    Mockito.doReturn("working-dir").when(config).getStringValue(MesosContext.SCHEDULER_WORKING_DIRECTORY);
    Config runtime = Mockito.mock(Config.class);
    launcher.initialize(config, runtime);
    // Failed to setup working dir
    Mockito.doReturn(false).when(launcher).setupWorkingDirectory();
    Assert.assertFalse(launcher.launch(packingPlan));
    Mockito.doReturn(true).when(launcher).setupWorkingDirectory();
    String[] mockCommand = new String[] { "mock", "scheduler", "command" };
    Mockito.doReturn(mockCommand).when(launcher).getSchedulerCommand();
    // Failed to spwan the process
    Mockito.doReturn(null).when(launcher).startScheduler(mockCommand);
    Assert.assertFalse(launcher.launch(packingPlan));
    // Happy path
    Process p = Mockito.mock(Process.class);
    Mockito.doReturn(p).when(launcher).startScheduler(mockCommand);
    Assert.assertTrue(launcher.launch(packingPlan));
}
Also used : Config(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Test(org.junit.Test)

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