Skip to content
Snippets Groups Projects
Commit 76c4bf59 authored by Michael Armbrust's avatar Michael Armbrust
Browse files

[SQL] Use TestSQLContext in Java tests

Sometimes tests were failing due to the creation of multiple `SparkContext`s in a single JVM.

Author: Michael Armbrust <michael@databricks.com>

Closes #4441 from marmbrus/javaTests and squashes the following commits:

657b1e0 [Michael Armbrust] [SQL] Use TestSQLContext in Java tests
parent 61073f83
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ package org.apache.spark.sql.api.java; ...@@ -19,6 +19,7 @@ package org.apache.spark.sql.api.java;
import java.io.Serializable; import java.io.Serializable;
import org.apache.spark.sql.test.TestSQLContext$;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -37,14 +38,12 @@ public class JavaAPISuite implements Serializable { ...@@ -37,14 +38,12 @@ public class JavaAPISuite implements Serializable {
@Before @Before
public void setUp() { public void setUp() {
sc = new JavaSparkContext("local", "JavaAPISuite"); sqlContext = TestSQLContext$.MODULE$;
sqlContext = new SQLContext(sc); sc = new JavaSparkContext(sqlContext.sparkContext());
} }
@After @After
public void tearDown() { public void tearDown() {
sc.stop();
sc = null;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
......
...@@ -22,6 +22,7 @@ import java.util.ArrayList; ...@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.spark.sql.test.TestSQLContext$;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
...@@ -42,13 +43,12 @@ public class JavaApplySchemaSuite implements Serializable { ...@@ -42,13 +43,12 @@ public class JavaApplySchemaSuite implements Serializable {
@Before @Before
public void setUp() { public void setUp() {
javaCtx = new JavaSparkContext("local", "JavaApplySchemaSuite"); javaSqlCtx = TestSQLContext$.MODULE$;
javaSqlCtx = new SQLContext(javaCtx); javaCtx = new JavaSparkContext(javaSqlCtx.sparkContext());
} }
@After @After
public void tearDown() { public void tearDown() {
javaCtx.stop();
javaCtx = null; javaCtx = null;
javaSqlCtx = null; javaSqlCtx = null;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment