This is an automated email from the ASF dual-hosted git repository.
srowen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 39fc7ee [SPARK-38611][TESTS] Replace `intercept` with `assertThrows`
in `CatalogLoadingSuite`
39fc7ee is described below
commit 39fc7eec470122d2afc7886a63646111914ffd94
Author: yangjie01 <[email protected]>
AuthorDate: Wed Mar 23 18:01:31 2022 -0500
[SPARK-38611][TESTS] Replace `intercept` with `assertThrows` in
`CatalogLoadingSuite`
### What changes were proposed in this pull request?
The `intercept` method implemented in `CatalogLoadingSuite` has same
semantics with `Assert.assertThrows`, so this pr replaces the handwritten
implementation with the standard Junit4 Api.
### Why are the changes needed?
Use standard Junit4 Api.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Pass GA
Closes #35919 from LuciferYang/SPARK-38611.
Authored-by: yangjie01 <[email protected]>
Signed-off-by: Sean Owen <[email protected]>
---
.../sql/connector/catalog/CatalogLoadingSuite.java | 35 ++++++----------------
1 file changed, 9 insertions(+), 26 deletions(-)
diff --git
a/sql/catalyst/src/test/java/org/apache/spark/sql/connector/catalog/CatalogLoadingSuite.java
b/sql/catalyst/src/test/java/org/apache/spark/sql/connector/catalog/CatalogLoadingSuite.java
index 37f6051..369e2fc 100644
---
a/sql/catalyst/src/test/java/org/apache/spark/sql/connector/catalog/CatalogLoadingSuite.java
+++
b/sql/catalyst/src/test/java/org/apache/spark/sql/connector/catalog/CatalogLoadingSuite.java
@@ -23,8 +23,6 @@ import org.apache.spark.sql.util.CaseInsensitiveStringMap;
import org.junit.Assert;
import org.junit.Test;
-import java.util.concurrent.Callable;
-
public class CatalogLoadingSuite {
@Test
public void testLoad() throws SparkException {
@@ -66,7 +64,7 @@ public class CatalogLoadingSuite {
public void testLoadWithoutConfig() {
SQLConf conf = new SQLConf();
- SparkException exc = intercept(CatalogNotFoundException.class,
+ SparkException exc = Assert.assertThrows(CatalogNotFoundException.class,
() -> Catalogs.load("missing", conf));
Assert.assertTrue("Should complain that implementation is not configured",
@@ -81,7 +79,8 @@ public class CatalogLoadingSuite {
SQLConf conf = new SQLConf();
conf.setConfString("spark.sql.catalog.missing",
"com.example.NoSuchCatalogPlugin");
- SparkException exc = intercept(SparkException.class, () ->
Catalogs.load("missing", conf));
+ SparkException exc =
+ Assert.assertThrows(SparkException.class, () -> Catalogs.load("missing",
conf));
Assert.assertTrue("Should complain that the class is not found",
exc.getMessage().contains("Cannot find catalog plugin class"));
@@ -97,7 +96,8 @@ public class CatalogLoadingSuite {
String invalidClassName = InvalidCatalogPlugin.class.getCanonicalName();
conf.setConfString("spark.sql.catalog.invalid", invalidClassName);
- SparkException exc = intercept(SparkException.class, () ->
Catalogs.load("invalid", conf));
+ SparkException exc =
+ Assert.assertThrows(SparkException.class, () -> Catalogs.load("invalid",
conf));
Assert.assertTrue("Should complain that class does not implement
CatalogPlugin",
exc.getMessage().contains("does not implement CatalogPlugin"));
@@ -113,7 +113,8 @@ public class CatalogLoadingSuite {
String invalidClassName =
ConstructorFailureCatalogPlugin.class.getCanonicalName();
conf.setConfString("spark.sql.catalog.invalid", invalidClassName);
- SparkException exc = intercept(SparkException.class, () ->
Catalogs.load("invalid", conf));
+ SparkException exc =
+ Assert.assertThrows(SparkException.class, () -> Catalogs.load("invalid",
conf));
Assert.assertTrue("Should identify the constructor error",
exc.getMessage().contains("Failed during instantiating constructor for
catalog"));
@@ -127,7 +128,8 @@ public class CatalogLoadingSuite {
String invalidClassName =
AccessErrorCatalogPlugin.class.getCanonicalName();
conf.setConfString("spark.sql.catalog.invalid", invalidClassName);
- SparkException exc = intercept(SparkException.class, () ->
Catalogs.load("invalid", conf));
+ SparkException exc =
+ Assert.assertThrows(SparkException.class, () -> Catalogs.load("invalid",
conf));
Assert.assertTrue("Should complain that no public constructor is provided",
exc.getMessage().contains("Failed to call public no-arg constructor
for catalog"));
@@ -136,25 +138,6 @@ public class CatalogLoadingSuite {
Assert.assertTrue("Should identify the class",
exc.getMessage().contains(invalidClassName));
}
-
- @SuppressWarnings("unchecked")
- public static <E extends Exception> E intercept(Class<E> expected,
Callable<?> callable) {
- try {
- callable.call();
- Assert.fail("No exception was thrown, expected: " +
- expected.getName());
- } catch (Exception actual) {
- try {
- Assert.assertEquals(expected, actual.getClass());
- return (E) actual;
- } catch (AssertionError e) {
- e.addSuppressed(actual);
- throw e;
- }
- }
- // Compiler doesn't catch that Assert.fail will always throw an exception.
- throw new UnsupportedOperationException("[BUG] Should not reach this
statement");
- }
}
class TestCatalogPlugin implements CatalogPlugin {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]