HADOOP-16600. StagingTestBase uses methods not available in Mockito 1.8.5 in branch-3.1
Signed-off-by: Steve Loughran <stevel@apache.org> Signed-off-by: Ayush Saxena <ayushsaxena@apache.org> Signed-off-by: stack <stack@apache.org>
This commit is contained in:
parent
14beaae65e
commit
6097e909ec
|
@ -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;
|
||||
|
||||
|
@ -514,6 +515,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
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue