Skip to content

Commit fc182f7

Browse files
andygrovedongjoon-hyun
authored andcommitted
[SPARK-34682][SQL] Use PrivateMethodTester instead of reflection
### Why are the changes needed? SPARK-34682 was merged prematurely. This PR implements feedback from the review. I wasn't sure whether I should create a new JIRA or not. ### Does this PR introduce _any_ user-facing change? No. Just improves the test. ### How was this patch tested? Updated test. Closes #31798 from andygrove/SPARK-34682-follow-up. Authored-by: Andy Grove <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent fd48438 commit fc182f7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
package org.apache.spark.sql.execution.adaptive
1919

2020
import java.io.File
21-
import java.lang.reflect.InvocationTargetException
2221
import java.net.URI
2322

2423
import org.apache.log4j.Level
24+
import org.scalatest.PrivateMethodTester
2525

2626
import org.apache.spark.scheduler.{SparkListener, SparkListenerEvent, SparkListenerJobStart}
2727
import org.apache.spark.sql.{Dataset, QueryTest, Row, SparkSession, Strategy}
@@ -46,7 +46,8 @@ import org.apache.spark.util.Utils
4646
class AdaptiveQueryExecSuite
4747
extends QueryTest
4848
with SharedSparkSession
49-
with AdaptiveSparkPlanHelper {
49+
with AdaptiveSparkPlanHelper
50+
with PrivateMethodTester {
5051

5152
import testImplicits._
5253

@@ -881,12 +882,11 @@ class AdaptiveQueryExecSuite
881882
val reader = readers.head
882883
val c = reader.canonicalized.asInstanceOf[CustomShuffleReaderExec]
883884
// we can't just call execute() because that has separate checks for canonicalized plans
884-
val doExecute = c.getClass.getMethod("doExecute")
885-
doExecute.setAccessible(true)
886-
val ex = intercept[InvocationTargetException] {
887-
doExecute.invoke(c)
885+
val ex = intercept[IllegalStateException] {
886+
val doExecute = PrivateMethod[Unit](Symbol("doExecute"))
887+
c.invokePrivate(doExecute())
888888
}
889-
assert(ex.getCause.getMessage === "operating on canonicalized plan")
889+
assert(ex.getMessage === "operating on canonicalized plan")
890890
}
891891
}
892892

0 commit comments

Comments
 (0)