Skip to content

Commit eae4d8e

Browse files
author
Marcelo Vanzin
committed
Fix new unit tests on Windows.
1 parent e570fb5 commit eae4d8e

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

launcher/src/test/java/org/apache/spark/launcher/SparkLauncherSuite.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333

3434
/**
3535
* These tests require the Spark assembly to be built before they can be run.
36-
*
37-
* TODO: these tests do not work on Win32.
3836
*/
3937
public class SparkLauncherSuite {
4038

@@ -85,7 +83,8 @@ private void testCmdBuilder(boolean isDriver) throws Exception {
8583
.setConf(SparkLauncher.DRIVER_EXTRA_LIBRARY_PATH, "/native")
8684
.setConf("spark.foo", "foo");
8785

88-
List<String> cmd = launcher.buildShellCommand();
86+
Map<String, String> env = new HashMap<String, String>();
87+
List<String> cmd = launcher.buildLauncherCommand(env);
8988

9089
// Checks below are different for driver and non-driver mode.
9190

@@ -110,18 +109,11 @@ private void testCmdBuilder(boolean isDriver) throws Exception {
110109
assertFalse("Driver classpath should not be in command.", contains("/driver", cp));
111110
}
112111

113-
String[] libPath = null;
114-
String envName = launcher.getLibPathEnvName() + "=";
115-
for (String arg : cmd) {
116-
if (arg.startsWith(envName)) {
117-
libPath = arg.substring(envName.length()).split(Pattern.quote(File.pathSeparator));
118-
break;
119-
}
120-
}
112+
String libPath = env.get(launcher.getLibPathEnvName());
121113
if (isDriver) {
122114
assertNotNull("Native library path should be set.", libPath);
123115
assertTrue("Native library path should contain provided entry.",
124-
contains("/native", libPath));
116+
contains("/native", libPath.split(Pattern.quote(File.pathSeparator))));
125117
} else {
126118
assertNull("Native library should not be set.", libPath);
127119
}

launcher/src/test/java/org/apache/spark/launcher/SparkSubmitCliLauncherSuite.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
package org.apache.spark.launcher;
1919

2020
import java.util.Arrays;
21+
import java.util.HashMap;
2122
import java.util.List;
23+
import java.util.Map;
2224

2325
import org.junit.Test;
2426
import static org.junit.Assert.*;
@@ -65,11 +67,12 @@ public void testPySparkLauncher() throws Exception {
6567
"--master=foo",
6668
"--deploy-mode=bar");
6769

70+
Map<String, String> env = new HashMap<String, String>();
6871
List<String> cmd = new SparkSubmitCliLauncher(sparkSubmitArgs)
6972
.setSparkHome(System.getProperty("spark.test.home"))
70-
.buildShellCommand();
73+
.buildLauncherCommand(env);
7174
assertEquals("python", cmd.get(cmd.size() - 1));
72-
assertTrue(cmd.contains("PYSPARK_SUBMIT_ARGS=\"--master\" \"foo\" \"--deploy-mode\" \"bar\""));
75+
assertEquals("\"--master\" \"foo\" \"--deploy-mode\" \"bar\"", env.get("PYSPARK_SUBMIT_ARGS"));
7376
}
7477

7578
@Test
@@ -80,9 +83,11 @@ public void testPySparkFallback() throws Exception {
8083
"script.py",
8184
"arg1");
8285

86+
Map<String, String> env = new HashMap<String, String>();
8387
List<String> cmd = new SparkSubmitCliLauncher(sparkSubmitArgs)
8488
.setSparkHome(System.getProperty("spark.test.home"))
85-
.buildShellCommand();
89+
.buildLauncherCommand(env);
90+
8691
assertEquals("foo", findArgValue(cmd, "--master"));
8792
assertEquals("bar", findArgValue(cmd, "--deploy-mode"));
8893
assertEquals("script.py", cmd.get(cmd.size() - 2));

0 commit comments

Comments
 (0)