Search in sources :

Example 1 with REEFFileNames

use of org.apache.reef.runtime.common.files.REEFFileNames in project heron by twitter.

the class HeronExecutorTaskTest method setsEnvironmentForExecutor.

/**
   * Tests launcher execution by yarn task
   */
@Test
@PrepareForTest({ ShellUtils.class, HeronReefUtils.class, REEFFileNames.class })
public void setsEnvironmentForExecutor() throws Exception {
    PowerMockito.spy(HeronReefUtils.class);
    PowerMockito.doNothing().when(HeronReefUtils.class, "extractPackageInSandbox", Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    REEFFileNames mockFiles = PowerMockito.mock(REEFFileNames.class);
    File global = new File(".");
    PowerMockito.when(mockFiles.getGlobalFolder()).thenReturn(global);
    HeronExecutorTask spyTask = getSpyOnHeronExecutorTask(mockFiles);
    String[] testCmd = { "cmd" };
    Mockito.doReturn(testCmd).when(spyTask).getExecutorCommand();
    HashMap<String, String> env = spyTask.getEnvironment("testCWD");
    Assert.assertEquals(1, env.size());
    String pexRoot = env.get("PEX_ROOT");
    Assert.assertNotNull(pexRoot);
    Assert.assertEquals("testCWD", pexRoot);
    Mockito.when(spyTask.getEnvironment(Mockito.anyString())).thenReturn(env);
    Process mockProcess = Mockito.mock(Process.class);
    Mockito.doReturn(0).when(mockProcess).waitFor();
    PowerMockito.spy(ShellUtils.class);
    PowerMockito.doReturn(mockProcess).when(ShellUtils.class, "runASyncProcess", Mockito.eq(testCmd), Mockito.any(File.class), Mockito.eq(env), Mockito.any(String.class), Mockito.any(Boolean.class));
    spyTask.call(null);
    Mockito.verify(mockProcess).waitFor();
}
Also used : File(java.io.File) REEFFileNames(org.apache.reef.runtime.common.files.REEFFileNames) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with REEFFileNames

use of org.apache.reef.runtime.common.files.REEFFileNames in project heron by twitter.

the class HeronExecutorTaskTest method setsEnvironmentForExecutor.

/**
 * Tests launcher execution by yarn task
 */
@Test
@PrepareForTest({ ShellUtils.class, HeronReefUtils.class, REEFFileNames.class })
public void setsEnvironmentForExecutor() throws Exception {
    PowerMockito.spy(HeronReefUtils.class);
    PowerMockito.doNothing().when(HeronReefUtils.class, "extractPackageInSandbox", Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    REEFFileNames mockFiles = PowerMockito.mock(REEFFileNames.class);
    File global = new File(".");
    PowerMockito.when(mockFiles.getGlobalFolder()).thenReturn(global);
    HeronExecutorTask spyTask = getSpyOnHeronExecutorTask(mockFiles);
    String[] testCmd = { "cmd" };
    Mockito.doReturn(testCmd).when(spyTask).getExecutorCommand();
    HashMap<String, String> env = spyTask.getEnvironment("testCWD");
    Assert.assertEquals(1, env.size());
    String pexRoot = env.get("PEX_ROOT");
    Assert.assertNotNull(pexRoot);
    Assert.assertEquals("testCWD", pexRoot);
    Mockito.when(spyTask.getEnvironment(Mockito.anyString())).thenReturn(env);
    Process mockProcess = Mockito.mock(Process.class);
    Mockito.doReturn(0).when(mockProcess).waitFor();
    PowerMockito.spy(ShellUtils.class);
    PowerMockito.doReturn(mockProcess).when(ShellUtils.class, "runASyncProcess", Mockito.eq(testCmd), Mockito.any(File.class), Mockito.eq(env), Mockito.any(String.class), Mockito.any(Boolean.class));
    spyTask.call(null);
    Mockito.verify(mockProcess).waitFor();
}
Also used : File(java.io.File) REEFFileNames(org.apache.reef.runtime.common.files.REEFFileNames) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with REEFFileNames

use of org.apache.reef.runtime.common.files.REEFFileNames in project incubator-heron by apache.

the class HeronExecutorTaskTest method setsEnvironmentForExecutor.

/**
 * Tests launcher execution by yarn task
 */
@Test
@PrepareForTest({ ShellUtils.class, HeronReefUtils.class, REEFFileNames.class })
public void setsEnvironmentForExecutor() throws Exception {
    PowerMockito.spy(HeronReefUtils.class);
    PowerMockito.doNothing().when(HeronReefUtils.class, "extractPackageInSandbox", Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    REEFFileNames mockFiles = PowerMockito.mock(REEFFileNames.class);
    File global = new File(".");
    PowerMockito.when(mockFiles.getGlobalFolder()).thenReturn(global);
    HeronExecutorTask spyTask = getSpyOnHeronExecutorTask(mockFiles);
    String[] testCmd = { "cmd" };
    Mockito.doReturn(testCmd).when(spyTask).getExecutorCommand();
    HashMap<String, String> env = spyTask.getEnvironment("testCWD");
    Assert.assertEquals(1, env.size());
    String pexRoot = env.get("PEX_ROOT");
    Assert.assertNotNull(pexRoot);
    Assert.assertEquals("testCWD", pexRoot);
    Mockito.when(spyTask.getEnvironment(Mockito.anyString())).thenReturn(env);
    Process mockProcess = Mockito.mock(Process.class);
    Mockito.doReturn(0).when(mockProcess).waitFor();
    PowerMockito.spy(ShellUtils.class);
    PowerMockito.doReturn(mockProcess).when(ShellUtils.class, "runASyncProcess", Mockito.eq(testCmd), Mockito.any(File.class), Mockito.eq(env), Mockito.any(String.class), Mockito.any(Boolean.class));
    spyTask.call(null);
    Mockito.verify(mockProcess).waitFor();
}
Also used : File(java.io.File) REEFFileNames(org.apache.reef.runtime.common.files.REEFFileNames) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

File (java.io.File)3 REEFFileNames (org.apache.reef.runtime.common.files.REEFFileNames)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3