This is an automated email from the ASF dual-hosted git repository.

stack pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new 6097e90  HADOOP-16600. StagingTestBase uses methods not available in 
Mockito 1.8.5 in branch-3.1
6097e90 is described below

commit 6097e909ec99f5d85fec7b0eb9642451e910982e
Author: Duo Zhang <[email protected]>
AuthorDate: Sat Sep 28 19:22:47 2019 +0800

    HADOOP-16600. StagingTestBase uses methods not available in Mockito 1.8.5 
in branch-3.1
    
    Signed-off-by: Steve Loughran <[email protected]>
    Signed-off-by: Ayush Saxena <[email protected]>
    Signed-off-by: stack <[email protected]>
---
 .../fs/s3a/commit/staging/StagingTestBase.java     | 30 +++++++++++++++++-----
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git 
a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/commit/staging/StagingTestBase.java
 
b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/commit/staging/StagingTestBase.java
index 38d5156..d81c747 100644
--- 
a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/commit/staging/StagingTestBase.java
+++ 
b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/commit/staging/StagingTestBase.java
@@ -49,6 +49,7 @@ import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.mockito.invocation.InvocationOnMock;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -515,6 +516,21 @@ public class StagingTestBase {
   }
 
   /**
+   * InvocationOnMock.getArgumentAt comes and goes with Mockito versions; this
+   * helper method is designed to be resilient to change.
+   * @param invocation invocation to query
+   * @param index argument index
+   * @param clazz class of return type
+   * @param <T> type of return
+   * @return the argument of the invocation, cast to the given type.
+   */
+  @SuppressWarnings("unchecked")
+  private static<T> T getArgumentAt(InvocationOnMock invocation, int index,
+      Class<T> clazz) {
+    return (T)invocation.getArguments()[index];
+  }
+
+  /**
    * Instantiate mock client with the results and errors requested.
    * @param results results to accrue
    * @param errors when (if any) to fail
@@ -539,7 +555,7 @@ public class StagingTestBase {
                   "Mock Fail on init " + results.requests.size());
             }
             String uploadId = UUID.randomUUID().toString();
-            InitiateMultipartUploadRequest req = invocation.getArgumentAt(
+            InitiateMultipartUploadRequest req = getArgumentAt(invocation,
                 0, InitiateMultipartUploadRequest.class);
             results.requests.put(uploadId, req);
             results.activeUploads.put(uploadId, req.getKey());
@@ -561,7 +577,7 @@ public class StagingTestBase {
               throw new AmazonClientException(
                   "Mock Fail on upload " + results.parts.size());
             }
-            UploadPartRequest req = invocation.getArgumentAt(
+            UploadPartRequest req = getArgumentAt(invocation,
                 0, UploadPartRequest.class);
             results.parts.add(req);
             String etag = UUID.randomUUID().toString();
@@ -588,7 +604,7 @@ public class StagingTestBase {
               throw new AmazonClientException(
                   "Mock Fail on commit " + results.commits.size());
             }
-            CompleteMultipartUploadRequest req = invocation.getArgumentAt(
+            CompleteMultipartUploadRequest req = getArgumentAt(invocation,
                 0, CompleteMultipartUploadRequest.class);
             results.commits.add(req);
             results.activeUploads.remove(req.getUploadId());
@@ -608,7 +624,7 @@ public class StagingTestBase {
           throw new AmazonClientException(
               "Mock Fail on abort " + results.aborts.size());
         }
-        AbortMultipartUploadRequest req = invocation.getArgumentAt(
+        AbortMultipartUploadRequest req = getArgumentAt(invocation,
             0, AbortMultipartUploadRequest.class);
         String id = req.getUploadId();
         String p = results.activeUploads.remove(id);
@@ -630,7 +646,7 @@ public class StagingTestBase {
     doAnswer(invocation -> {
       LOG.debug("deleteObject for {}", mockClient);
       synchronized (lock) {
-        results.deletes.add(invocation.getArgumentAt(
+        results.deletes.add(getArgumentAt(invocation,
             0, DeleteObjectRequest.class));
         return null;
       }
@@ -643,8 +659,8 @@ public class StagingTestBase {
       LOG.debug("deleteObject for {}", mockClient);
       synchronized (lock) {
         results.deletes.add(new DeleteObjectRequest(
-            invocation.getArgumentAt(0, String.class),
-            invocation.getArgumentAt(1, String.class)
+            getArgumentAt(invocation, 0, String.class),
+            getArgumentAt(invocation, 1, String.class)
         ));
         return null;
       }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to