Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Upgrade Mockito to v3 (#1450)
Browse files Browse the repository at this point in the history
* Bump mockito version to 3.1.0

 + Remove deprecated mockito-all dependency from grpc-server

* Migrate usages of deprecated Mockito imports

* Explicitly match null args; fix name mismatch in testStartWorkflow

* Update usage of non-null matchers in TaskCoordinator tests

* Sleep and assert ack is called before verifying noops

* Throw explicit RuntimeException and use long matchers when needed in TestWorkflowExecutor

* Loosen non-null matchers in failing core test stubs

* Use explicit null matcher in jersey skip task test

* Update lockfiles

* De-dupe System.currentTimeMillis() calls to fix flaky TaskTest failure
  • Loading branch information
ParkerM authored and apanicker-nflx committed Dec 24, 2019
1 parent 3ae62cf commit 0fac732
Show file tree
Hide file tree
Showing 56 changed files with 330 additions and 346 deletions.
16 changes: 8 additions & 8 deletions cassandra-persistence/dependencies.lock
Expand Up @@ -821,8 +821,8 @@
"locked": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"firstLevelTransitive": [
Expand Down Expand Up @@ -968,8 +968,8 @@
"locked": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"firstLevelTransitive": [
Expand Down Expand Up @@ -1115,8 +1115,8 @@
"locked": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"firstLevelTransitive": [
Expand Down Expand Up @@ -1262,8 +1262,8 @@
"locked": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"firstLevelTransitive": [
Expand Down
16 changes: 8 additions & 8 deletions client/dependencies.lock
Expand Up @@ -611,8 +611,8 @@
"locked": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"firstLevelTransitive": [
Expand Down Expand Up @@ -722,8 +722,8 @@
"locked": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"firstLevelTransitive": [
Expand Down Expand Up @@ -833,8 +833,8 @@
"locked": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"firstLevelTransitive": [
Expand Down Expand Up @@ -944,8 +944,8 @@
"locked": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"firstLevelTransitive": [
Expand Down
Expand Up @@ -6,8 +6,8 @@
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -59,4 +59,4 @@ public void testWorkflowDeleteNameMissing() {
expectedException.expectMessage("Workflow name cannot be blank");
metadataClient.unregisterWorkflowDef(null, 1);
}
}
}
Expand Up @@ -29,11 +29,13 @@
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
Expand Down Expand Up @@ -95,8 +97,8 @@ public void testTaskException() {
.withTaskClient(client)
.withWorkerNamePrefix("test-worker-")
.build();
when(client.batchPollTasksInDomain(anyString(), anyString(), anyString(), anyInt(), anyInt())).thenReturn(ImmutableList.of(new Task()));
when(client.ack(anyString(), anyString())).thenReturn(true);
when(client.batchPollTasksInDomain(anyString(), isNull(), anyString(), anyInt(), anyInt())).thenReturn(ImmutableList.of(new Task()));
when(client.ack(any(), any())).thenReturn(true);
CountDownLatch latch = new CountDownLatch(1);
doAnswer(invocation -> {
assertEquals("test-worker-0", Thread.currentThread().getName());
Expand Down Expand Up @@ -132,10 +134,12 @@ public void testNoOpWhenAckFailed() {
.build();
Task testTask = new Task();
testTask.setStatus(Task.Status.IN_PROGRESS);
when(client.batchPollTasksInDomain(anyString(), anyString(), anyString(), anyInt(), anyInt())).thenReturn(ImmutableList.of(testTask));
when(client.ack(anyString(), anyString())).thenReturn(false);
when(client.batchPollTasksInDomain(any(), any(), any(), anyInt(), anyInt())).thenReturn(ImmutableList.of(testTask));
when(client.ack(any(), any())).thenReturn(false);

coordinator.init();
Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS);
verify(client, atLeastOnce()).ack(any(), any());

// then worker.execute must not be called and task must be updated with IN_PROGRESS status
verify(worker, never()).execute(any());
Expand All @@ -162,10 +166,12 @@ public void testNoOpWhenAckThrowsException() {
.build();
Task testTask = new Task();
testTask.setStatus(Task.Status.IN_PROGRESS);
when(client.batchPollTasksInDomain(anyString(), anyString(), anyString(), anyInt(), anyInt())).thenReturn(ImmutableList.of(testTask));
when(client.ack(anyString(), anyString())).thenThrow(new RuntimeException("Ack failed"));
when(client.batchPollTasksInDomain(any(), any(), any(), anyInt(), anyInt())).thenReturn(ImmutableList.of(testTask));
when(client.ack(any(), any())).thenThrow(new RuntimeException("Ack failed"));

coordinator.init();
Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS);
verify(client).ack(any(), any());

// then worker.execute must not be called and task must be updated with IN_PROGRESS status
verify(worker, never()).execute(any());
Expand Down Expand Up @@ -198,8 +204,8 @@ public void testReturnTaskWhenRejectedExecutionExceptionThrown() {
.withTaskClient(client)
.withWorkerNamePrefix("test-worker-")
.build();
when(client.batchPollTasksInDomain(anyString(), anyString(), anyString(), anyInt(), anyInt())).thenReturn(ImmutableList.of(testTask, testTask, testTask));
when(client.ack(anyString(), anyString())).thenReturn(true);
when(client.batchPollTasksInDomain(anyString(), isNull(), isNull(), anyInt(), anyInt())).thenReturn(ImmutableList.of(testTask, testTask, testTask));
when(client.ack(any(), any())).thenReturn(true);
CountDownLatch latch = new CountDownLatch(3);
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
Expand Down Expand Up @@ -248,10 +254,10 @@ public void testLargePayloadCanFailUpdateWithRetry() {
.withWorkerNamePrefix("test-worker-")
.build();

when(taskClient.batchPollTasksInDomain(anyString(), anyString(), anyString(), anyInt(), anyInt())).thenReturn(ImmutableList.of(testTask));
when(taskClient.ack(anyString(), anyString())).thenReturn(true);
when(taskClient.batchPollTasksInDomain(anyString(), isNull(), isNull(), anyInt(), anyInt())).thenReturn(ImmutableList.of(testTask));
when(taskClient.ack(any(), any())).thenReturn(true);

doThrow(ConductorClientException.class).when(taskClient).evaluateAndUploadLargePayload(any(TaskResult.class), anyString());
doThrow(ConductorClientException.class).when(taskClient).evaluateAndUploadLargePayload(any(TaskResult.class), any());

CountDownLatch latch = new CountDownLatch(1);

Expand Down
16 changes: 8 additions & 8 deletions common/dependencies.lock
Expand Up @@ -285,8 +285,8 @@
"requested": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"locked": "1.7.25",
Expand Down Expand Up @@ -339,8 +339,8 @@
"requested": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"locked": "1.7.25",
Expand Down Expand Up @@ -393,8 +393,8 @@
"requested": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"locked": "1.7.25",
Expand Down Expand Up @@ -447,8 +447,8 @@
"requested": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"locked": "1.7.25",
Expand Down
Expand Up @@ -78,13 +78,15 @@ public void testTaskDefinitionIfAvailable() {
@Test
public void testTaskQueueWaitTime() {
Task task = new Task();
task.setScheduledTime(System.currentTimeMillis() - 30_000); // 30 seconds ago
task.setStartTime(System.currentTimeMillis() - 25_000);

long currentTimeMillis = System.currentTimeMillis();
task.setScheduledTime(currentTimeMillis - 30_000); // 30 seconds ago
task.setStartTime(currentTimeMillis - 25_000);

long queueWaitTime = task.getQueueWaitTime();
assertEquals(5000L, queueWaitTime);

task.setUpdateTime(System.currentTimeMillis() - 20_000);
task.setUpdateTime(currentTimeMillis - 20_000);
task.setCallbackAfterSeconds(10);
queueWaitTime = task.getQueueWaitTime();
assertTrue(queueWaitTime > 0);
Expand Down
34 changes: 17 additions & 17 deletions contribs/dependencies.lock
Expand Up @@ -7,7 +7,7 @@
"locked": "1.11.86"
},
"com.amazonaws:aws-java-sdk-sqs": {
"locked": "1.11.687",
"locked": "1.11.693",
"requested": "latest.release"
},
"com.fasterxml.jackson.core:jackson-core": {
Expand Down Expand Up @@ -167,7 +167,7 @@
"locked": "1.11.86"
},
"com.amazonaws:aws-java-sdk-sqs": {
"locked": "1.11.687",
"locked": "1.11.693",
"requested": "latest.release"
},
"com.fasterxml.jackson.core:jackson-core": {
Expand Down Expand Up @@ -337,7 +337,7 @@
"locked": "1.11.86"
},
"com.amazonaws:aws-java-sdk-sqs": {
"locked": "1.11.687",
"locked": "1.11.693",
"requested": "latest.release"
},
"com.fasterxml.jackson.core:jackson-core": {
Expand Down Expand Up @@ -507,7 +507,7 @@
"locked": "1.11.86"
},
"com.amazonaws:aws-java-sdk-sqs": {
"locked": "1.11.687",
"locked": "1.11.693",
"requested": "latest.release"
},
"com.fasterxml.jackson.core:jackson-core": {
Expand Down Expand Up @@ -667,7 +667,7 @@
"locked": "1.11.86"
},
"com.amazonaws:aws-java-sdk-sqs": {
"locked": "1.11.687",
"locked": "1.11.693",
"requested": "latest.release"
},
"com.fasterxml.jackson.core:jackson-core": {
Expand Down Expand Up @@ -827,7 +827,7 @@
"locked": "1.11.86"
},
"com.amazonaws:aws-java-sdk-sqs": {
"locked": "1.11.687",
"locked": "1.11.693",
"requested": "latest.release"
},
"com.fasterxml.jackson.core:jackson-core": {
Expand Down Expand Up @@ -985,8 +985,8 @@
"locked": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"firstLevelTransitive": [
Expand All @@ -1003,7 +1003,7 @@
"locked": "1.11.86"
},
"com.amazonaws:aws-java-sdk-sqs": {
"locked": "1.11.687",
"locked": "1.11.693",
"requested": "latest.release"
},
"com.fasterxml.jackson.core:jackson-core": {
Expand Down Expand Up @@ -1161,8 +1161,8 @@
"locked": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"firstLevelTransitive": [
Expand All @@ -1179,7 +1179,7 @@
"locked": "1.11.86"
},
"com.amazonaws:aws-java-sdk-sqs": {
"locked": "1.11.687",
"locked": "1.11.693",
"requested": "latest.release"
},
"com.fasterxml.jackson.core:jackson-core": {
Expand Down Expand Up @@ -1337,8 +1337,8 @@
"locked": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"firstLevelTransitive": [
Expand All @@ -1355,7 +1355,7 @@
"locked": "1.11.86"
},
"com.amazonaws:aws-java-sdk-sqs": {
"locked": "1.11.687",
"locked": "1.11.693",
"requested": "latest.release"
},
"com.fasterxml.jackson.core:jackson-core": {
Expand Down Expand Up @@ -1513,8 +1513,8 @@
"locked": "6.0.13.Final"
},
"org.mockito:mockito-core": {
"locked": "1.10.19",
"requested": "1.10.19"
"locked": "3.1.0",
"requested": "3.1.0"
},
"org.slf4j:slf4j-api": {
"firstLevelTransitive": [
Expand Down

0 comments on commit 0fac732

Please sign in to comment.