Skip to content

Commit

Permalink
[SPARK-47089][BUILD][TESTS] Migrate mockito 4 to mockito 5
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
The pr aims to migrate `mockito 4` to `mockito 5`.

### Why are the changes needed?
This is the prerequisite behavior for upgrading `scalatest mockito` to version `3.2.18`.
`Scalatest mockito 3.2.18` no longer supports `mockito 4`.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
Pass GA.

### Was this patch authored or co-authored using generative AI tooling?
No.

Closes apache#45158 from panbingkun/SPARK-47089.

Authored-by: panbingkun <panbingkun@baidu.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
  • Loading branch information
panbingkun authored and dongjoon-hyun committed Feb 19, 2024
1 parent 5841260 commit 07e2281
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 43 deletions.
5 changes: 0 additions & 5 deletions mllib-local/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-tags_${scala.binary.version}</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions mllib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming_${scala.binary.version}</artifactId>
Expand Down
16 changes: 5 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
</dependency>
<dependency>
<groupId>org.scalatestplus</groupId>
<artifactId>mockito-4-11_${scala.binary.version}</artifactId>
<artifactId>mockito-5-8_${scala.binary.version}</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -1156,7 +1156,7 @@
</dependency>
<dependency>
<groupId>org.scalatestplus</groupId>
<artifactId>mockito-4-11_${scala.binary.version}</artifactId>
<artifactId>mockito-5-8_${scala.binary.version}</artifactId>
<version>3.2.17.0</version>
<scope>test</scope>
</dependency>
Expand All @@ -1175,25 +1175,19 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>4.11.0</version>
<version>5.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.14.5</version>
<version>1.14.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>1.14.5</version>
<version>1.14.10</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
11 changes: 10 additions & 1 deletion resource-managers/kubernetes/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,16 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jmock</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class ClientSuite extends SparkFunSuite with BeforeAndAfter {

private var kconf: KubernetesDriverConf = _
private var createdPodArgumentCaptor: ArgumentCaptor[Pod] = _
private var createdResourcesArgumentCaptor: ArgumentCaptor[HasMetadata] = _
private var createdResourcesArgumentCaptor: ArgumentCaptor[Array[HasMetadata]] = _

before {
MockitoAnnotations.openMocks(this).close()
Expand All @@ -179,7 +179,7 @@ class ClientSuite extends SparkFunSuite with BeforeAndAfter {
when(podsWithNamespace.withName(POD_NAME)).thenReturn(namedPods)

createdPodArgumentCaptor = ArgumentCaptor.forClass(classOf[Pod])
createdResourcesArgumentCaptor = ArgumentCaptor.forClass(classOf[HasMetadata])
createdResourcesArgumentCaptor = ArgumentCaptor.forClass(classOf[Array[HasMetadata]])
when(podsWithNamespace.resource(fullExpectedPod())).thenReturn(namedPods)
when(resourceList.forceConflicts()).thenReturn(resourceList)
when(namedPods.serverSideApply()).thenReturn(podWithOwnerReference())
Expand All @@ -189,7 +189,7 @@ class ClientSuite extends SparkFunSuite with BeforeAndAfter {
when(loggingPodStatusWatcher.watchOrStop(sId)).thenReturn(true)
doReturn(resourceList)
.when(kubernetesClient)
.resourceList(createdResourcesArgumentCaptor.capture())
.resourceList(createdResourcesArgumentCaptor.capture(): _*)
}

test("The client should configure the pod using the builder.") {
Expand All @@ -210,7 +210,7 @@ class ClientSuite extends SparkFunSuite with BeforeAndAfter {
kubernetesClient,
loggingPodStatusWatcher)
submissionClient.run()
val otherCreatedResources = createdResourcesArgumentCaptor.getAllValues
val otherCreatedResources = createdResourcesArgumentCaptor.getAllValues.asScala.flatten
assert(otherCreatedResources.size === 2)
val secrets = otherCreatedResources.toArray.filter(_.isInstanceOf[Secret]).toSeq
assert(secrets === ADDITIONAL_RESOURCES_WITH_OWNER_REFERENCES)
Expand Down Expand Up @@ -246,7 +246,7 @@ class ClientSuite extends SparkFunSuite with BeforeAndAfter {
kubernetesClient,
loggingPodStatusWatcher)
submissionClient.run()
val otherCreatedResources = createdResourcesArgumentCaptor.getAllValues
val otherCreatedResources = createdResourcesArgumentCaptor.getAllValues.asScala.flatten

// 2 for pre-resource creation/update, 1 for resource creation, 1 for config map
assert(otherCreatedResources.size === 4)
Expand Down Expand Up @@ -326,7 +326,7 @@ class ClientSuite extends SparkFunSuite with BeforeAndAfter {
kubernetesClient,
loggingPodStatusWatcher)
submissionClient.run()
val otherCreatedResources = createdResourcesArgumentCaptor.getAllValues
val otherCreatedResources = createdResourcesArgumentCaptor.getAllValues.asScala.flatten

val configMaps = otherCreatedResources.toArray
.filter(_.isInstanceOf[ConfigMap]).map(_.asInstanceOf[ConfigMap])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ class ExecutorPodsAllocatorSuite extends SparkFunSuite with BeforeAndAfter {
when(podsWithNamespace.withName(driverPodName)).thenReturn(driverPodOperations)
when(podsWithNamespace.resource(any())).thenReturn(podResource)
when(podsWithNamespace.withLabel(anyString(), anyString())).thenReturn(labeledPods)
when(podsWithNamespace.withLabelIn(anyString(), any())).thenReturn(labeledPods)
when(podsWithNamespace.withLabelIn(
anyString(), any(classOf[Array[String]]): _*)).thenReturn(labeledPods)
when(podsWithNamespace.withField(anyString(), anyString())).thenReturn(labeledPods)
when(labeledPods.withLabel(anyString(), anyString())).thenReturn(labeledPods)
when(labeledPods.withLabelIn(anyString(), any())).thenReturn(labeledPods)
when(labeledPods.withLabelIn(
anyString(), any(classOf[Array[String]]): _*)).thenReturn(labeledPods)
when(labeledPods.withField(anyString(), anyString())).thenReturn(labeledPods)
when(driverPodOperations.get).thenReturn(driverPod)
when(driverPodOperations.waitUntilReady(any(), any())).thenReturn(driverPod)
Expand Down Expand Up @@ -212,7 +214,7 @@ class ExecutorPodsAllocatorSuite extends SparkFunSuite with BeforeAndAfter {
.withLabel(SPARK_ROLE_LABEL, SPARK_POD_EXECUTOR_ROLE))
.thenReturn(podOperations)
when(podOperations
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any()))
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any(classOf[Array[String]]): _*))
.thenReturn(podOperations)

val startTime = Instant.now.toEpochMilli
Expand Down Expand Up @@ -362,7 +364,7 @@ class ExecutorPodsAllocatorSuite extends SparkFunSuite with BeforeAndAfter {
.withLabel(SPARK_ROLE_LABEL, SPARK_POD_EXECUTOR_ROLE))
.thenReturn(labeledPods)
when(labeledPods
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any()))
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any(classOf[Array[String]]): _*))
.thenReturn(labeledPods)

val startTime = Instant.now.toEpochMilli
Expand Down Expand Up @@ -432,7 +434,7 @@ class ExecutorPodsAllocatorSuite extends SparkFunSuite with BeforeAndAfter {
.withLabel(SPARK_ROLE_LABEL, SPARK_POD_EXECUTOR_ROLE))
.thenReturn(labeledPods)
when(labeledPods
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any()))
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any(classOf[Array[String]]): _*))
.thenReturn(labeledPods)

val startTime = Instant.now.toEpochMilli
Expand Down Expand Up @@ -477,7 +479,7 @@ class ExecutorPodsAllocatorSuite extends SparkFunSuite with BeforeAndAfter {
.withLabel(SPARK_ROLE_LABEL, SPARK_POD_EXECUTOR_ROLE))
.thenReturn(labeledPods)
when(labeledPods
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any()))
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any(classOf[Array[String]]): _*))
.thenReturn(labeledPods)

val startTime = Instant.now.toEpochMilli
Expand Down Expand Up @@ -560,7 +562,7 @@ class ExecutorPodsAllocatorSuite extends SparkFunSuite with BeforeAndAfter {
.withLabel(SPARK_ROLE_LABEL, SPARK_POD_EXECUTOR_ROLE))
.thenReturn(labeledPods)
when(labeledPods
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any()))
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any(classOf[Array[String]]): _*))
.thenReturn(labeledPods)

val startTime = Instant.now.toEpochMilli
Expand Down Expand Up @@ -642,7 +644,7 @@ class ExecutorPodsAllocatorSuite extends SparkFunSuite with BeforeAndAfter {
.withLabel(SPARK_ROLE_LABEL, SPARK_POD_EXECUTOR_ROLE))
.thenReturn(labeledPods)
when(labeledPods
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any()))
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any(classOf[Array[String]]): _*))
.thenReturn(labeledPods)

val startTime = Instant.now.toEpochMilli
Expand Down Expand Up @@ -794,7 +796,7 @@ class ExecutorPodsAllocatorSuite extends SparkFunSuite with BeforeAndAfter {
.withLabel(SPARK_ROLE_LABEL, SPARK_POD_EXECUTOR_ROLE))
.thenReturn(labeledPods)
when(labeledPods
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any()))
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any(classOf[Array[String]]): _*))
.thenReturn(labeledPods)

val startTime = Instant.now.toEpochMilli
Expand Down Expand Up @@ -890,7 +892,7 @@ class ExecutorPodsAllocatorSuite extends SparkFunSuite with BeforeAndAfter {
.withLabel(SPARK_ROLE_LABEL, SPARK_POD_EXECUTOR_ROLE))
.thenReturn(labeledPods)
when(labeledPods
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any()))
.withLabelIn(meq(SPARK_EXECUTOR_ID_LABEL), any(classOf[Array[String]]): _*))
.thenReturn(labeledPods)

val startTime = Instant.now.toEpochMilli
Expand Down
5 changes: 0 additions & 5 deletions sql/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
Expand Down

0 comments on commit 07e2281

Please sign in to comment.