Search in sources :

Example 11 with AmazonS3Exception

use of com.amazonaws.services.s3.model.AmazonS3Exception in project presto by prestodb.

the class TestPrestoS3FileSystem method testGetMetadataRetryCounter.

@SuppressWarnings({ "OverlyStrongTypeCast", "ConstantConditions" })
@Test
public void testGetMetadataRetryCounter() {
    int maxRetries = 2;
    try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) {
        MockAmazonS3 s3 = new MockAmazonS3();
        s3.setGetObjectMetadataHttpCode(SC_INTERNAL_SERVER_ERROR);
        Configuration configuration = new Configuration();
        configuration.set(S3_MAX_BACKOFF_TIME, "1ms");
        configuration.set(S3_MAX_RETRY_TIME, "5s");
        configuration.setInt(S3_MAX_CLIENT_RETRIES, maxRetries);
        fs.initialize(new URI("s3n://test-bucket/"), configuration);
        fs.setS3Client(s3);
        fs.getS3ObjectMetadata(new Path("s3n://test-bucket/test"));
    } catch (Throwable expected) {
        assertInstanceOf(expected, AmazonS3Exception.class);
        assertEquals(((AmazonS3Exception) expected).getStatusCode(), SC_INTERNAL_SERVER_ERROR);
        assertEquals(PrestoS3FileSystem.getFileSystemStats().getGetMetadataRetries().getTotalCount(), maxRetries);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) ClientConfiguration(com.amazonaws.ClientConfiguration) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 12 with AmazonS3Exception

use of com.amazonaws.services.s3.model.AmazonS3Exception in project nifi by apache.

the class AbstractS3IT method putTestFile.

protected void putTestFile(String key, File file) throws AmazonS3Exception {
    PutObjectRequest putRequest = new PutObjectRequest(BUCKET_NAME, key, file);
    client.putObject(putRequest);
}
Also used : PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 13 with AmazonS3Exception

use of com.amazonaws.services.s3.model.AmazonS3Exception in project nifi by apache.

the class AbstractS3IT method putTestFileEncrypted.

protected void putTestFileEncrypted(String key, File file) throws AmazonS3Exception, FileNotFoundException {
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
    PutObjectRequest putRequest = new PutObjectRequest(BUCKET_NAME, key, new FileInputStream(file), objectMetadata);
    client.putObject(putRequest);
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) FileInputStream(java.io.FileInputStream)

Example 14 with AmazonS3Exception

use of com.amazonaws.services.s3.model.AmazonS3Exception in project nifi by apache.

the class TestFetchS3Object method testGetObjectExceptionGoesToFailure.

@Test
public void testGetObjectExceptionGoesToFailure() throws IOException {
    runner.setProperty(FetchS3Object.REGION, "us-east-1");
    runner.setProperty(FetchS3Object.BUCKET, "request-bucket");
    final Map<String, String> attrs = new HashMap<>();
    attrs.put("filename", "request-key");
    runner.enqueue(new byte[0], attrs);
    Mockito.doThrow(new AmazonS3Exception("NoSuchBucket")).when(mockS3Client).getObject(Mockito.any());
    runner.run(1);
    runner.assertAllFlowFilesTransferred(FetchS3Object.REL_FAILURE, 1);
}
Also used : HashMap(java.util.HashMap) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) Test(org.junit.Test)

Example 15 with AmazonS3Exception

use of com.amazonaws.services.s3.model.AmazonS3Exception in project nifi by apache.

the class TestPutS3Object method testPutSinglePartException.

@Test
public void testPutSinglePartException() {
    runner.setProperty(PutS3Object.REGION, "ap-northeast-1");
    runner.setProperty(PutS3Object.BUCKET, "test-bucket");
    final Map<String, String> ffAttributes = new HashMap<>();
    ffAttributes.put("filename", "testfile.txt");
    runner.enqueue("Test Content", ffAttributes);
    MultipartUploadListing uploadListing = new MultipartUploadListing();
    Mockito.when(mockS3Client.listMultipartUploads(Mockito.any(ListMultipartUploadsRequest.class))).thenReturn(uploadListing);
    Mockito.when(mockS3Client.putObject(Mockito.any(PutObjectRequest.class))).thenThrow(new AmazonS3Exception("TestFail"));
    runner.assertValid();
    runner.run(1);
    runner.assertAllFlowFilesTransferred(PutS3Object.REL_FAILURE, 1);
}
Also used : HashMap(java.util.HashMap) MultipartUploadListing(com.amazonaws.services.s3.model.MultipartUploadListing) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) ListMultipartUploadsRequest(com.amazonaws.services.s3.model.ListMultipartUploadsRequest) Test(org.junit.Test)

Aggregations

AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)62 IOException (java.io.IOException)23 Test (org.junit.Test)13 FileNotFoundException (java.io.FileNotFoundException)10 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)9 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)9 AmazonServiceException (com.amazonaws.AmazonServiceException)8 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)7 GetObjectMetadataRequest (com.amazonaws.services.s3.model.GetObjectMetadataRequest)6 S3Object (com.amazonaws.services.s3.model.S3Object)6 S3TestUtils.buildMockedS3FileSystem (org.apache.beam.sdk.io.aws.s3.S3TestUtils.buildMockedS3FileSystem)6 AmazonClientException (com.amazonaws.AmazonClientException)5 InterruptedIOException (java.io.InterruptedIOException)5 ArrayList (java.util.ArrayList)5 Path (org.apache.hadoop.fs.Path)5 ClientConfiguration (com.amazonaws.ClientConfiguration)4 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)4 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)4 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)4 URI (java.net.URI)4