/** * Adds a no-value argument to the Spark invocation. If the argument is known, this method * validates whether the argument is indeed a no-value argument, and throws an exception * otherwise. * <p> * Use this method with caution. It is possible to create an invalid Spark command by passing * unknown arguments to this method, since those are allowed for forward compatibility. * * @since 1.5.0 * @param arg Argument to add. * @return This launcher. */ public SparkLauncher addSparkArg(String arg) { SparkSubmitOptionParser validator = new ArgumentValidator(false); validator.parse(Arrays.asList(arg)); builder.sparkArgs.add(arg); return this; }
/** * Adds a no-value argument to the Spark invocation. If the argument is known, this method * validates whether the argument is indeed a no-value argument, and throws an exception * otherwise. * <p> * Use this method with caution. It is possible to create an invalid Spark command by passing * unknown arguments to this method, since those are allowed for forward compatibility. * * @since 1.5.0 * @param arg Argument to add. * @return This launcher. */ public SparkLauncher addSparkArg(String arg) { SparkSubmitOptionParser validator = new ArgumentValidator(false); validator.parse(Arrays.asList(arg)); builder.sparkArgs.add(arg); return this; }
/** * Adds a no-value argument to the Spark invocation. If the argument is known, this method * validates whether the argument is indeed a no-value argument, and throws an exception * otherwise. * <p> * Use this method with caution. It is possible to create an invalid Spark command by passing * unknown arguments to this method, since those are allowed for forward compatibility. * * @since 1.5.0 * @param arg Argument to add. * @return This launcher. */ public T addSparkArg(String arg) { SparkSubmitOptionParser validator = new ArgumentValidator(false); validator.parse(Arrays.asList(arg)); builder.userArgs.add(arg); return self(); }
/** * Adds a no-value argument to the Spark invocation. If the argument is known, this method * validates whether the argument is indeed a no-value argument, and throws an exception * otherwise. * <p> * Use this method with caution. It is possible to create an invalid Spark command by passing * unknown arguments to this method, since those are allowed for forward compatibility. * * @since 1.5.0 * @param arg Argument to add. * @return This launcher. */ public T addSparkArg(String arg) { SparkSubmitOptionParser validator = new ArgumentValidator(false); validator.parse(Arrays.asList(arg)); builder.userArgs.add(arg); return self(); }
@Test(expected=IllegalArgumentException.class) public void testMissingArg() { parser.parse(Arrays.asList(parser.MASTER)); }
@Test(expected=IllegalArgumentException.class) public void testMissingArg() { parser.parse(Arrays.asList(parser.MASTER)); }
validator.parse(Arrays.asList(name, value)); builder.userArgs.add(name); builder.userArgs.add(value);
validator.parse(Arrays.asList(name, value)); builder.sparkArgs.add(name); builder.sparkArgs.add(value);
validator.parse(Arrays.asList(name, value)); builder.sparkArgs.add(name); builder.sparkArgs.add(value);
validator.parse(Arrays.asList(name, value)); builder.userArgs.add(name); builder.userArgs.add(value);
@Test public void testEqualSeparatedOption() { List<String> args = Arrays.asList(parser.MASTER + "=" + parser.MASTER); parser.parse(args); verify(parser).handle(eq(parser.MASTER), eq(parser.MASTER)); verify(parser).handleExtraArgs(eq(Collections.emptyList())); }
@Test public void testExtraOptions() { List<String> args = Arrays.asList(parser.MASTER, parser.MASTER, "foo", "bar"); parser.parse(args); verify(parser).handle(eq(parser.MASTER), eq(parser.MASTER)); verify(parser).handleUnknown(eq("foo")); verify(parser).handleExtraArgs(eq(Arrays.asList("bar"))); }
@Test public void testEqualSeparatedOption() { List<String> args = Arrays.asList(parser.MASTER + "=" + parser.MASTER); parser.parse(args); verify(parser).handle(eq(parser.MASTER), eq(parser.MASTER)); verify(parser).handleExtraArgs(eq(Collections.emptyList())); }
@Test public void testExtraOptions() { List<String> args = Arrays.asList(parser.MASTER, parser.MASTER, "foo", "bar"); parser.parse(args); verify(parser).handle(eq(parser.MASTER), eq(parser.MASTER)); verify(parser).handleUnknown(eq("foo")); verify(parser).handleExtraArgs(eq(Arrays.asList("bar"))); }
@Test public void testAllOptions() { int count = 0; for (String[] optNames : parser.opts) { for (String optName : optNames) { String value = optName + "-value"; parser.parse(Arrays.asList(optName, value)); count++; verify(parser).handle(eq(optNames[0]), eq(value)); verify(parser, times(count)).handle(anyString(), anyString()); verify(parser, times(count)).handleExtraArgs(eq(Collections.emptyList())); } } for (String[] switchNames : parser.switches) { int switchCount = 0; for (String name : switchNames) { parser.parse(Arrays.asList(name)); count++; switchCount++; verify(parser, times(switchCount)).handle(eq(switchNames[0]), same(null)); verify(parser, times(count)).handle(anyString(), any(String.class)); verify(parser, times(count)).handleExtraArgs(eq(Collections.emptyList())); } } }
@Test public void testAllOptions() { int count = 0; for (String[] optNames : parser.opts) { for (String optName : optNames) { String value = optName + "-value"; parser.parse(Arrays.asList(optName, value)); count++; verify(parser).handle(eq(optNames[0]), eq(value)); verify(parser, times(count)).handle(anyString(), anyString()); verify(parser, times(count)).handleExtraArgs(eq(Collections.emptyList())); } } for (String[] switchNames : parser.switches) { int switchCount = 0; for (String name : switchNames) { parser.parse(Arrays.asList(name)); count++; switchCount++; verify(parser, times(switchCount)).handle(eq(switchNames[0]), same(null)); verify(parser, times(count)).handle(anyString(), any(String.class)); verify(parser, times(count)).handleExtraArgs(eq(Collections.emptyList())); } } }
parser.parse(Arrays.asList(args)); assertNotNull("Launcher port not found.", port.get()); assertNotNull("Launcher secret not found.", secret.get());