Search in sources :

Example 6 with S3FileSystem

use of org.apache.hop.vfs.s3.s3.vfs.S3FileSystem in project beam by apache.

the class S3FileSystemTest method testGetScheme.

@Test
public void testGetScheme() {
    S3FileSystem s3FileSystem = new S3FileSystem(s3Config("s3"));
    assertEquals("s3", s3FileSystem.getScheme());
    s3FileSystem = new S3FileSystem(s3Config("other"));
    assertEquals("other", s3FileSystem.getScheme());
}
Also used : S3TestUtils.buildMockedS3FileSystem(org.apache.beam.sdk.io.aws2.s3.S3TestUtils.buildMockedS3FileSystem) Test(org.junit.Test)

Example 7 with S3FileSystem

use of org.apache.hop.vfs.s3.s3.vfs.S3FileSystem in project beam by apache.

the class S3FileSystemTest method matchNonGlobNullContentEncodingWithOptions.

@Test
public void matchNonGlobNullContentEncodingWithOptions() {
    S3FileSystem s3FileSystem = buildMockedS3FileSystem(s3Options());
    S3ResourceId path = S3ResourceId.fromUri("s3://testbucket/testdirectory/filethatexists");
    long lastModifiedMillis = 1540000000000L;
    HeadObjectResponse headObjectResponse = HeadObjectResponse.builder().contentLength(100L).lastModified(Instant.ofEpochMilli(lastModifiedMillis)).contentEncoding(null).build();
    when(s3FileSystem.getS3Client().headObject(argThat(new GetHeadObjectRequestMatcher(HeadObjectRequest.builder().bucket(path.getBucket()).key(path.getKey()).build())))).thenReturn(headObjectResponse);
    MatchResult result = s3FileSystem.matchNonGlobPath(path);
    assertThat(result, MatchResultMatcher.create(ImmutableList.of(MatchResult.Metadata.builder().setSizeBytes(100).setLastModifiedMillis(lastModifiedMillis).setResourceId(path).setIsReadSeekEfficient(true).build())));
}
Also used : HeadObjectResponse(software.amazon.awssdk.services.s3.model.HeadObjectResponse) MatchResult(org.apache.beam.sdk.io.fs.MatchResult) S3TestUtils.buildMockedS3FileSystem(org.apache.beam.sdk.io.aws2.s3.S3TestUtils.buildMockedS3FileSystem) Test(org.junit.Test)

Example 8 with S3FileSystem

use of org.apache.hop.vfs.s3.s3.vfs.S3FileSystem in project beam by apache.

the class S3FileSystemTest method matchNonGlobForbidden.

@Test
public void matchNonGlobForbidden() {
    S3FileSystem s3FileSystem = buildMockedS3FileSystem(s3Config("s3"));
    SdkServiceException exception = S3Exception.builder().message("mock exception").statusCode(403).build();
    S3ResourceId path = S3ResourceId.fromUri("s3://testbucket/testdirectory/keyname");
    when(s3FileSystem.getS3Client().headObject(argThat(new GetHeadObjectRequestMatcher(HeadObjectRequest.builder().bucket(path.getBucket()).key(path.getKey()).build())))).thenThrow(exception);
    assertThat(s3FileSystem.matchNonGlobPath(path), MatchResultMatcher.create(MatchResult.Status.ERROR, new IOException(exception)));
}
Also used : SdkServiceException(software.amazon.awssdk.core.exception.SdkServiceException) IOException(java.io.IOException) S3TestUtils.buildMockedS3FileSystem(org.apache.beam.sdk.io.aws2.s3.S3TestUtils.buildMockedS3FileSystem) Test(org.junit.Test)

Example 9 with S3FileSystem

use of org.apache.hop.vfs.s3.s3.vfs.S3FileSystem in project beam by apache.

the class S3FileSystemTest method deleteThousandsOfObjectsInMultipleBucketsWithS3Options.

@Test
public void deleteThousandsOfObjectsInMultipleBucketsWithS3Options() throws IOException {
    S3FileSystem s3FileSystem = buildMockedS3FileSystem(s3Options());
    List<String> buckets = ImmutableList.of("bucket1", "bucket2");
    List<String> keys = new ArrayList<>();
    for (int i = 0; i < 2500; i++) {
        keys.add(String.format("key-%d", i));
    }
    List<S3ResourceId> paths = new ArrayList<>();
    for (String bucket : buckets) {
        for (String key : keys) {
            paths.add(S3ResourceId.fromComponents("s3", bucket, key));
        }
    }
    s3FileSystem.delete(paths);
    // Should require 6 calls to delete 2500 objects in each of 2 buckets.
    verify(s3FileSystem.getS3Client(), times(6)).deleteObjects(any(DeleteObjectsRequest.class));
}
Also used : ArrayList(java.util.ArrayList) S3TestUtils.buildMockedS3FileSystem(org.apache.beam.sdk.io.aws2.s3.S3TestUtils.buildMockedS3FileSystem) DeleteObjectsRequest(software.amazon.awssdk.services.s3.model.DeleteObjectsRequest) Test(org.junit.Test)

Example 10 with S3FileSystem

use of org.apache.hop.vfs.s3.s3.vfs.S3FileSystem in project beam by apache.

the class S3FileSystemTest method matchNonGlobNotReadSeekEfficient.

@Test
public void matchNonGlobNotReadSeekEfficient() {
    S3FileSystem s3FileSystem = buildMockedS3FileSystem(s3Config("s3"));
    S3ResourceId path = S3ResourceId.fromUri("s3://testbucket/testdirectory/filethatexists");
    long lastModifiedMillis = 1540000000000L;
    HeadObjectResponse headObjectResponse = HeadObjectResponse.builder().contentLength(100L).lastModified(Instant.ofEpochMilli(lastModifiedMillis)).contentEncoding("gzip").build();
    when(s3FileSystem.getS3Client().headObject(argThat(new GetHeadObjectRequestMatcher(HeadObjectRequest.builder().bucket(path.getBucket()).key(path.getKey()).build())))).thenReturn(headObjectResponse);
    MatchResult result = s3FileSystem.matchNonGlobPath(path);
    assertThat(result, MatchResultMatcher.create(ImmutableList.of(MatchResult.Metadata.builder().setSizeBytes(100).setLastModifiedMillis(lastModifiedMillis).setResourceId(path).setIsReadSeekEfficient(false).build())));
}
Also used : HeadObjectResponse(software.amazon.awssdk.services.s3.model.HeadObjectResponse) MatchResult(org.apache.beam.sdk.io.fs.MatchResult) S3TestUtils.buildMockedS3FileSystem(org.apache.beam.sdk.io.aws2.s3.S3TestUtils.buildMockedS3FileSystem) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)25 S3TestUtils.buildMockedS3FileSystem (org.apache.beam.sdk.io.aws2.s3.S3TestUtils.buildMockedS3FileSystem)20 HeadObjectResponse (software.amazon.awssdk.services.s3.model.HeadObjectResponse)9 MatchResult (org.apache.beam.sdk.io.fs.MatchResult)8 S3FileSystem (org.apache.hop.vfs.s3.s3.vfs.S3FileSystem)8 SdkServiceException (software.amazon.awssdk.core.exception.SdkServiceException)5 StorageUnitConverter (org.apache.hop.core.util.StorageUnitConverter)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 S3FileName (org.apache.hop.vfs.s3.s3.vfs.S3FileName)3 HeadObjectRequest (software.amazon.awssdk.services.s3.model.HeadObjectRequest)3 ListObjectsV2Response (software.amazon.awssdk.services.s3.model.ListObjectsV2Response)3 S3Object (software.amazon.awssdk.services.s3.model.S3Object)3 URL (java.net.URL)2 S3HopProperty (org.apache.hop.vfs.s3.s3common.S3HopProperty)2 Before (org.junit.Before)2 DeleteObjectsRequest (software.amazon.awssdk.services.s3.model.DeleteObjectsRequest)2 ListObjectsV2Request (software.amazon.awssdk.services.s3.model.ListObjectsV2Request)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1