Search in sources :

Example 1 with IExpectationSetters

use of org.easymock.IExpectationSetters in project druid by druid-io.

the class OssTestUtils method mockClientDeleteObjects.

public static void mockClientDeleteObjects(OSS client, List<DeleteObjectsRequest> deleteRequestsExpected, Map<DeleteObjectsRequest, Exception> requestToException) {
    Map<DeleteObjectsRequest, IExpectationSetters<DeleteObjectsResult>> requestToResultExpectationSetter = new HashMap<>();
    for (Map.Entry<DeleteObjectsRequest, Exception> requestsAndErrors : requestToException.entrySet()) {
        DeleteObjectsRequest request = requestsAndErrors.getKey();
        Exception exception = requestsAndErrors.getValue();
        IExpectationSetters<DeleteObjectsResult> resultExpectationSetter = requestToResultExpectationSetter.get(request);
        if (resultExpectationSetter == null) {
            client.deleteObjects(OssTestUtils.deleteObjectsRequestArgumentMatcher(request));
            resultExpectationSetter = EasyMock.<DeleteObjectsResult>expectLastCall().andThrow(exception);
            requestToResultExpectationSetter.put(request, resultExpectationSetter);
        } else {
            resultExpectationSetter.andThrow(exception);
        }
    }
    for (DeleteObjectsRequest request : deleteRequestsExpected) {
        IExpectationSetters<DeleteObjectsResult> resultExpectationSetter = requestToResultExpectationSetter.get(request);
        if (resultExpectationSetter == null) {
            client.deleteObjects(OssTestUtils.deleteObjectsRequestArgumentMatcher(request));
            resultExpectationSetter = EasyMock.expectLastCall();
            requestToResultExpectationSetter.put(request, resultExpectationSetter);
        }
        resultExpectationSetter.andReturn(new DeleteObjectsResult());
    }
}
Also used : IExpectationSetters(org.easymock.IExpectationSetters) HashMap(java.util.HashMap) DeleteObjectsResult(com.aliyun.oss.model.DeleteObjectsResult) HashMap(java.util.HashMap) Map(java.util.Map) DeleteObjectsRequest(com.aliyun.oss.model.DeleteObjectsRequest)

Example 2 with IExpectationSetters

use of org.easymock.IExpectationSetters in project druid by druid-io.

the class AzureTestUtils method expectDeleteObjects.

public static void expectDeleteObjects(AzureStorage storage, List<CloudBlobHolder> deleteRequestsExpected, Map<CloudBlobHolder, Exception> deleteRequestToException) throws Exception {
    Map<CloudBlobHolder, IExpectationSetters<CloudBlobHolder>> requestToResultExpectationSetter = new HashMap<>();
    for (Map.Entry<CloudBlobHolder, Exception> requestsAndErrors : deleteRequestToException.entrySet()) {
        CloudBlobHolder deleteObject = requestsAndErrors.getKey();
        Exception exception = requestsAndErrors.getValue();
        IExpectationSetters<CloudBlobHolder> resultExpectationSetter = requestToResultExpectationSetter.get(deleteObject);
        if (resultExpectationSetter == null) {
            storage.emptyCloudBlobDirectory(deleteObject.getContainerName(), deleteObject.getName());
            resultExpectationSetter = EasyMock.<CloudBlobHolder>expectLastCall().andThrow(exception);
            requestToResultExpectationSetter.put(deleteObject, resultExpectationSetter);
        } else {
            resultExpectationSetter.andThrow(exception);
        }
    }
    for (CloudBlobHolder deleteObject : deleteRequestsExpected) {
        IExpectationSetters<CloudBlobHolder> resultExpectationSetter = requestToResultExpectationSetter.get(deleteObject);
        if (resultExpectationSetter == null) {
            storage.emptyCloudBlobDirectory(deleteObject.getContainerName(), deleteObject.getName());
            resultExpectationSetter = EasyMock.expectLastCall();
            requestToResultExpectationSetter.put(deleteObject, resultExpectationSetter);
        }
        resultExpectationSetter.andReturn(null);
    }
}
Also used : IExpectationSetters(org.easymock.IExpectationSetters) HashMap(java.util.HashMap) CloudBlobHolder(org.apache.druid.storage.azure.blob.CloudBlobHolder) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException)

Example 3 with IExpectationSetters

use of org.easymock.IExpectationSetters in project druid by druid-io.

the class GoogleTestUtils method expectDeleteObjects.

public static void expectDeleteObjects(GoogleStorage storage, List<StorageObject> deleteObjectExpected, Map<StorageObject, Exception> deleteObjectToException) throws IOException {
    Map<StorageObject, IExpectationSetters<StorageObject>> requestToResultExpectationSetter = new HashMap<>();
    for (Map.Entry<StorageObject, Exception> deleteObjectAndException : deleteObjectToException.entrySet()) {
        StorageObject deleteObject = deleteObjectAndException.getKey();
        Exception exception = deleteObjectAndException.getValue();
        IExpectationSetters<StorageObject> resultExpectationSetter = requestToResultExpectationSetter.get(deleteObject);
        if (resultExpectationSetter == null) {
            storage.delete(deleteObject.getBucket(), deleteObject.getName());
            resultExpectationSetter = EasyMock.<StorageObject>expectLastCall().andThrow(exception);
            requestToResultExpectationSetter.put(deleteObject, resultExpectationSetter);
        } else {
            resultExpectationSetter.andThrow(exception);
        }
    }
    for (StorageObject deleteObject : deleteObjectExpected) {
        IExpectationSetters<StorageObject> resultExpectationSetter = requestToResultExpectationSetter.get(deleteObject);
        if (resultExpectationSetter == null) {
            storage.delete(deleteObject.getBucket(), deleteObject.getName());
            resultExpectationSetter = EasyMock.expectLastCall();
            requestToResultExpectationSetter.put(deleteObject, resultExpectationSetter);
        }
        resultExpectationSetter.andVoid();
    }
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) IExpectationSetters(org.easymock.IExpectationSetters) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException)

Example 4 with IExpectationSetters

use of org.easymock.IExpectationSetters in project druid by druid-io.

the class S3TestUtils method mockS3ClientDeleteObjects.

public static void mockS3ClientDeleteObjects(ServerSideEncryptingAmazonS3 s3Client, List<DeleteObjectsRequest> deleteRequestsExpected, Map<DeleteObjectsRequest, Exception> requestToException) {
    Map<DeleteObjectsRequest, IExpectationSetters<DeleteObjectsRequest>> requestToResultExpectationSetter = new HashMap<>();
    for (Map.Entry<DeleteObjectsRequest, Exception> requestsAndErrors : requestToException.entrySet()) {
        DeleteObjectsRequest request = requestsAndErrors.getKey();
        Exception exception = requestsAndErrors.getValue();
        IExpectationSetters<DeleteObjectsRequest> resultExpectationSetter = requestToResultExpectationSetter.get(request);
        if (resultExpectationSetter == null) {
            s3Client.deleteObjects(S3TestUtils.deleteObjectsRequestArgumentMatcher(request));
            resultExpectationSetter = EasyMock.<DeleteObjectsRequest>expectLastCall().andThrow(exception);
            requestToResultExpectationSetter.put(request, resultExpectationSetter);
        } else {
            resultExpectationSetter.andThrow(exception);
        }
    }
    for (DeleteObjectsRequest request : deleteRequestsExpected) {
        IExpectationSetters<DeleteObjectsRequest> resultExpectationSetter = requestToResultExpectationSetter.get(request);
        if (resultExpectationSetter == null) {
            s3Client.deleteObjects(S3TestUtils.deleteObjectsRequestArgumentMatcher(request));
            resultExpectationSetter = EasyMock.expectLastCall();
            requestToResultExpectationSetter.put(request, resultExpectationSetter);
        }
        resultExpectationSetter.andVoid();
    }
}
Also used : IExpectationSetters(org.easymock.IExpectationSetters) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) DeleteObjectsRequest(com.amazonaws.services.s3.model.DeleteObjectsRequest)

Aggregations

HashMap (java.util.HashMap)4 Map (java.util.Map)4 IExpectationSetters (org.easymock.IExpectationSetters)4 IOException (java.io.IOException)2 DeleteObjectsRequest (com.aliyun.oss.model.DeleteObjectsRequest)1 DeleteObjectsResult (com.aliyun.oss.model.DeleteObjectsResult)1 DeleteObjectsRequest (com.amazonaws.services.s3.model.DeleteObjectsRequest)1 StorageObject (com.google.api.services.storage.model.StorageObject)1 CloudBlobHolder (org.apache.druid.storage.azure.blob.CloudBlobHolder)1