@Test public void testGetPreviewPlan() { try { PackagedProgram prog = new PackagedProgram(new File(CliFrontendTestUtils.getTestJarPath())); final PrintStream out = System.out; final PrintStream err = System.err; try { System.setOut(new PrintStream(new NullOutputStream())); System.setErr(new PrintStream(new NullOutputStream())); Assert.assertNotNull(prog.getPreviewPlan()); } finally { System.setOut(out); System.setErr(err); } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); Assert.fail("Test is erroneous: " + e.getMessage()); } }
@Test(expected = CliArgsException.class) public void testInvalidParallelismOption() throws Exception { // test configure parallelism with non integer value String[] parameters = {"-v", "-p", "text", getTestJarPath()}; Configuration configuration = getConfiguration(); CliFrontend testFrontend = new CliFrontend( configuration, Collections.singletonList(getCli(configuration))); testFrontend.run(parameters); }
@Test(expected = CliArgsException.class) public void testParallelismWithOverflow() throws Exception { // test configure parallelism with overflow integer value String[] parameters = {"-v", "-p", "475871387138", getTestJarPath()}; Configuration configuration = new Configuration(); CliFrontend testFrontend = new CliFrontend( configuration, Collections.singletonList(getCli(configuration))); testFrontend.run(parameters); }
@Test public void testShowExecutionPlanWithParallelism() { replaceStdOut(); try { String[] parameters = {"-p", "17", CliFrontendTestUtils.getTestJarPath()}; Configuration configuration = getConfiguration(); CliFrontend testFrontend = new CliFrontend( configuration, Collections.singletonList(getCli(configuration))); testFrontend.info(parameters); assertTrue(buffer.toString().contains("\"parallelism\": \"17\"")); } catch (Exception e) { e.printStackTrace(); fail("Program caused an exception: " + e.getMessage()); } finally { restoreStdOut(); } }
@Test public void testShowExecutionPlan() throws Exception { replaceStdOut(); try { String[] parameters = new String[]{CliFrontendTestUtils.getTestJarPath(), "-f", "true"}; Configuration configuration = getConfiguration(); CliFrontend testFrontend = new CliFrontend( configuration, Collections.singletonList(getCli(configuration))); testFrontend.info(parameters); assertTrue(buffer.toString().contains("\"parallelism\": \"1\"")); } finally { restoreStdOut(); } }
@Test public void testValidVariantWithNoJarAndNoArgumentsOption() throws Exception { String[] arguments = { "--classpath", "file:///tmp/foo", "--classpath", "file:///tmp/bar", getTestJarPath(), "--debug", "true", "arg1", "arg2" }; URL[] classpath = new URL[] { new URL("file:///tmp/foo"), new URL("file:///tmp/bar") }; String[] reducedArguments = {"--debug", "true", "arg1", "arg2"}; RunOptions options = CliFrontendParser.parseRunCommand(arguments); assertEquals(getTestJarPath(), options.getJarFilePath()); assertArrayEquals(classpath, options.getClasspaths().toArray()); assertArrayEquals(reducedArguments, options.getProgramArgs()); PackagedProgram prog = frontend.buildProgram(options); Assert.assertArrayEquals(reducedArguments, prog.getArguments()); Assert.assertEquals(TEST_JAR_MAIN_CLASS, prog.getMainClassName()); }
@Test public void testVariantWithExplicitJarAndArgumentsOption() throws Exception { String[] arguments = { "--classpath", "file:///tmp/foo", "--classpath", "file:///tmp/bar", "-j", getTestJarPath(), "-a", "--debug", "true", "arg1", "arg2" }; URL[] classpath = new URL[] { new URL("file:///tmp/foo"), new URL("file:///tmp/bar") }; String[] reducedArguments = new String[] {"--debug", "true", "arg1", "arg2"}; RunOptions options = CliFrontendParser.parseRunCommand(arguments); assertEquals(getTestJarPath(), options.getJarFilePath()); assertArrayEquals(classpath, options.getClasspaths().toArray()); assertArrayEquals(reducedArguments, options.getProgramArgs()); PackagedProgram prog = frontend.buildProgram(options); Assert.assertArrayEquals(reducedArguments, prog.getArguments()); Assert.assertEquals(TEST_JAR_MAIN_CLASS, prog.getMainClassName()); }
@Test public void testVariantWithExplicitJarAndNoArgumentsOption() throws Exception { String[] arguments = { "--classpath", "file:///tmp/foo", "--classpath", "file:///tmp/bar", "-j", getTestJarPath(), "--debug", "true", "arg1", "arg2" }; URL[] classpath = new URL[] { new URL("file:///tmp/foo"), new URL("file:///tmp/bar") }; String[] reducedArguments = new String[] {"--debug", "true", "arg1", "arg2"}; RunOptions options = CliFrontendParser.parseRunCommand(arguments); assertEquals(getTestJarPath(), options.getJarFilePath()); assertArrayEquals(classpath, options.getClasspaths().toArray()); assertArrayEquals(reducedArguments, options.getProgramArgs()); PackagedProgram prog = frontend.buildProgram(options); Assert.assertArrayEquals(reducedArguments, prog.getArguments()); Assert.assertEquals(TEST_JAR_MAIN_CLASS, prog.getMainClassName()); }
String[] parameters = {"-v", getTestJarPath()}; verifyCliFrontend(getCli(configuration), parameters, 1, true, false); String[] parameters = {"-v", "-p", "42", getTestJarPath()}; verifyCliFrontend(getCli(configuration), parameters, 42, true, false); String[] parameters = {"-p", "2", "-q", getTestJarPath()}; verifyCliFrontend(getCli(configuration), parameters, 2, false, false); String[] parameters = {"-p", "2", "-d", getTestJarPath()}; verifyCliFrontend(getCli(configuration), parameters, 2, true, true); String[] parameters = {"-s", "expectedSavepointPath", getTestJarPath()}; RunOptions options = CliFrontendParser.parseRunCommand(parameters); SavepointRestoreSettings savepointSettings = options.getSavepointRestoreSettings(); String[] parameters = {"-s", "expectedSavepointPath", "-n", getTestJarPath()}; RunOptions options = CliFrontendParser.parseRunCommand(parameters); SavepointRestoreSettings savepointSettings = options.getSavepointRestoreSettings(); { getTestJarPath(), "-arg1", "value1", "justavalue", "--arg2", "value2"}; RunOptions options = CliFrontendParser.parseRunCommand(parameters); assertEquals("-arg1", options.getProgramArgs()[0]);
"--classpath", "file:///tmp/foo", "--classpath", "file:///tmp/bar", "-c", TEST_JAR_CLASSLOADERTEST_CLASS, getTestJarPath(), "true", "arg1", "arg2" }; URL[] classpath = new URL[] { new URL("file:///tmp/foo"), new URL("file:///tmp/bar") }; assertEquals(getTestJarPath(), options.getJarFilePath()); assertArrayEquals(classpath, options.getClasspaths().toArray()); assertEquals(TEST_JAR_CLASSLOADERTEST_CLASS, options.getEntryPointClassName());