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();
}
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;
}
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));
}
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]);
}
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));
}
Aggregations