Search in sources :

Example 1 with ShellScriptBuilder

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.ShellScriptBuilder in project hadoop by apache.

the class TestContainerLaunch method testWindowsShellScriptBuilderLink.

@Test(timeout = 10000)
public void testWindowsShellScriptBuilderLink() throws IOException {
    // Test is only relevant on Windows
    assumeWindows();
    String linkCmd = "@" + Shell.getWinUtilsPath() + " symlink \"\" \"\"";
    // The tests are built on assuming 8191 max command line length
    assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGTH);
    ShellScriptBuilder builder = ShellScriptBuilder.create();
    // test link
    builder.link(new Path(org.apache.commons.lang.StringUtils.repeat("A", 1024)), new Path(org.apache.commons.lang.StringUtils.repeat("B", 1024)));
    builder.link(new Path(org.apache.commons.lang.StringUtils.repeat("E", (Shell.WINDOWS_MAX_SHELL_LENGTH - linkCmd.length()) / 2)), new Path(org.apache.commons.lang.StringUtils.repeat("F", (Shell.WINDOWS_MAX_SHELL_LENGTH - linkCmd.length()) / 2)));
    try {
        builder.link(new Path(org.apache.commons.lang.StringUtils.repeat("X", (Shell.WINDOWS_MAX_SHELL_LENGTH - linkCmd.length()) / 2 + 1)), new Path(org.apache.commons.lang.StringUtils.repeat("Y", (Shell.WINDOWS_MAX_SHELL_LENGTH - linkCmd.length()) / 2) + 1));
        fail("long link was expected to throw");
    } catch (IOException e) {
        assertThat(e.getMessage(), CoreMatchers.containsString(expectedMessage));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ShellScriptBuilder(org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.ShellScriptBuilder) IOException(java.io.IOException) BaseContainerManagerTest(org.apache.hadoop.yarn.server.nodemanager.containermanager.BaseContainerManagerTest) Test(org.junit.Test)

Example 2 with ShellScriptBuilder

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.ShellScriptBuilder in project hadoop by apache.

the class TestContainerLaunch method testWindowsShellScriptBuilderCommand.

@Test(timeout = 10000)
public void testWindowsShellScriptBuilderCommand() throws IOException {
    String callCmd = "@call ";
    // Test is only relevant on Windows
    assumeWindows();
    // The tests are built on assuming 8191 max command line length
    assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGTH);
    ShellScriptBuilder builder = ShellScriptBuilder.create();
    // Basic tests: less length, exact length, max+1 length 
    builder.command(Arrays.asList(org.apache.commons.lang.StringUtils.repeat("A", 1024)));
    builder.command(Arrays.asList(org.apache.commons.lang.StringUtils.repeat("E", Shell.WINDOWS_MAX_SHELL_LENGTH - callCmd.length())));
    try {
        builder.command(Arrays.asList(org.apache.commons.lang.StringUtils.repeat("X", Shell.WINDOWS_MAX_SHELL_LENGTH - callCmd.length() + 1)));
        fail("longCommand was expected to throw");
    } catch (IOException e) {
        assertThat(e.getMessage(), CoreMatchers.containsString(expectedMessage));
    }
    // Composite tests, from parts: less, exact and +
    builder.command(Arrays.asList(org.apache.commons.lang.StringUtils.repeat("A", 1024), org.apache.commons.lang.StringUtils.repeat("A", 1024), org.apache.commons.lang.StringUtils.repeat("A", 1024)));
    // buildr.command joins the command parts with an extra space
    builder.command(Arrays.asList(org.apache.commons.lang.StringUtils.repeat("E", 4095), org.apache.commons.lang.StringUtils.repeat("E", 2047), org.apache.commons.lang.StringUtils.repeat("E", 2047 - callCmd.length())));
    try {
        builder.command(Arrays.asList(org.apache.commons.lang.StringUtils.repeat("X", 4095), org.apache.commons.lang.StringUtils.repeat("X", 2047), org.apache.commons.lang.StringUtils.repeat("X", 2048 - callCmd.length())));
        fail("long commands was expected to throw");
    } catch (IOException e) {
        assertThat(e.getMessage(), CoreMatchers.containsString(expectedMessage));
    }
}
Also used : ShellScriptBuilder(org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.ShellScriptBuilder) IOException(java.io.IOException) BaseContainerManagerTest(org.apache.hadoop.yarn.server.nodemanager.containermanager.BaseContainerManagerTest) Test(org.junit.Test)

Example 3 with ShellScriptBuilder

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.ShellScriptBuilder in project hadoop by apache.

the class TestContainerLaunch method testShellScriptBuilderNonZeroExitCode.

/**
   * Test that script exists with non-zero exit code when command fails.
   * @throws IOException
   */
@Test(timeout = 10000)
public void testShellScriptBuilderNonZeroExitCode() throws IOException {
    ShellScriptBuilder builder = ShellScriptBuilder.create();
    builder.command(Arrays.asList(new String[] { "unknownCommand" }));
    File shellFile = Shell.appendScriptExtension(tmpDir, "testShellScriptBuilderError");
    PrintStream writer = new PrintStream(new FileOutputStream(shellFile));
    builder.write(writer);
    writer.close();
    try {
        FileUtil.setExecutable(shellFile, true);
        Shell.ShellCommandExecutor shexc = new Shell.ShellCommandExecutor(new String[] { shellFile.getAbsolutePath() }, tmpDir);
        try {
            shexc.execute();
            fail("builder shell command was expected to throw");
        } catch (IOException e) {
            // expected
            System.out.println("Received an expected exception: " + e.getMessage());
        }
    } finally {
        FileUtil.fullyDelete(shellFile);
    }
}
Also used : PrintStream(java.io.PrintStream) Shell(org.apache.hadoop.util.Shell) ShellScriptBuilder(org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.ShellScriptBuilder) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File) BaseContainerManagerTest(org.apache.hadoop.yarn.server.nodemanager.containermanager.BaseContainerManagerTest) Test(org.junit.Test)

Example 4 with ShellScriptBuilder

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.ShellScriptBuilder in project hadoop by apache.

the class TestContainerLaunch method testWindowsShellScriptBuilderEnv.

@Test(timeout = 10000)
public void testWindowsShellScriptBuilderEnv() throws IOException {
    // Test is only relevant on Windows
    assumeWindows();
    // The tests are built on assuming 8191 max command line length
    assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGTH);
    ShellScriptBuilder builder = ShellScriptBuilder.create();
    // test env
    builder.env("somekey", org.apache.commons.lang.StringUtils.repeat("A", 1024));
    builder.env("somekey", org.apache.commons.lang.StringUtils.repeat("A", Shell.WINDOWS_MAX_SHELL_LENGTH - ("@set somekey=").length()));
    try {
        builder.env("somekey", org.apache.commons.lang.StringUtils.repeat("A", Shell.WINDOWS_MAX_SHELL_LENGTH - ("@set somekey=").length()) + 1);
        fail("long env was expected to throw");
    } catch (IOException e) {
        assertThat(e.getMessage(), CoreMatchers.containsString(expectedMessage));
    }
}
Also used : ShellScriptBuilder(org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.ShellScriptBuilder) IOException(java.io.IOException) BaseContainerManagerTest(org.apache.hadoop.yarn.server.nodemanager.containermanager.BaseContainerManagerTest) Test(org.junit.Test)

Example 5 with ShellScriptBuilder

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.ShellScriptBuilder in project hadoop by apache.

the class TestContainerLaunch method testWindowsShellScriptBuilderMkdir.

@Test(timeout = 10000)
public void testWindowsShellScriptBuilderMkdir() throws IOException {
    String mkDirCmd = "@if not exist \"\" mkdir \"\"";
    // Test is only relevant on Windows
    assumeWindows();
    // The tests are built on assuming 8191 max command line length
    assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGTH);
    ShellScriptBuilder builder = ShellScriptBuilder.create();
    // test mkdir
    builder.mkdir(new Path(org.apache.commons.lang.StringUtils.repeat("A", 1024)));
    builder.mkdir(new Path(org.apache.commons.lang.StringUtils.repeat("E", (Shell.WINDOWS_MAX_SHELL_LENGTH - mkDirCmd.length()) / 2)));
    try {
        builder.mkdir(new Path(org.apache.commons.lang.StringUtils.repeat("X", (Shell.WINDOWS_MAX_SHELL_LENGTH - mkDirCmd.length()) / 2 + 1)));
        fail("long mkdir was expected to throw");
    } catch (IOException e) {
        assertThat(e.getMessage(), CoreMatchers.containsString(expectedMessage));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ShellScriptBuilder(org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.ShellScriptBuilder) IOException(java.io.IOException) BaseContainerManagerTest(org.apache.hadoop.yarn.server.nodemanager.containermanager.BaseContainerManagerTest) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)5 BaseContainerManagerTest (org.apache.hadoop.yarn.server.nodemanager.containermanager.BaseContainerManagerTest)5 ShellScriptBuilder (org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.ShellScriptBuilder)5 Test (org.junit.Test)5 Path (org.apache.hadoop.fs.Path)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 JarFile (java.util.jar.JarFile)1 Shell (org.apache.hadoop.util.Shell)1