Search in sources :

Example 26 with DataStorageException

use of com.epam.pipeline.entity.datastorage.DataStorageException in project cloud-pipeline by epam.

the class S3HelperTest method testMoveFileShouldThrowIfFileSizeExceedsTheLimit.

@Test
public void testMoveFileShouldThrowIfFileSizeExceedsTheLimit() {
    final ObjectListing singleFileListing = new ObjectListing();
    singleFileListing.setCommonPrefixes(Collections.singletonList(OLD_PATH));
    when(amazonS3.listObjects(any(ListObjectsRequest.class))).thenReturn(singleFileListing);
    final ObjectMetadata fileMetadata = new ObjectMetadata();
    fileMetadata.setContentLength(EXCEEDED_OBJECT_SIZE);
    when(amazonS3.getObjectMetadata(any())).thenReturn(fileMetadata);
    assertThrows(e -> e instanceof DataStorageException && e.getMessage().contains(SIZE_EXCEEDS_EXCEPTION_MESSAGE), () -> helper.moveFile(BUCKET, OLD_PATH, NEW_PATH));
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Test(org.junit.Test)

Example 27 with DataStorageException

use of com.epam.pipeline.entity.datastorage.DataStorageException in project cloud-pipeline by epam.

the class S3HelperTest method testMoveFolderShouldThrowIfAtLeastOneOfItsFilesSizeExceedTheLimit.

@Test
public void testMoveFolderShouldThrowIfAtLeastOneOfItsFilesSizeExceedTheLimit() {
    final ObjectListing sourceListing = new ObjectListing();
    sourceListing.setCommonPrefixes(Collections.singletonList(OLD_PATH));
    final ObjectListing destinationListing = new ObjectListing();
    destinationListing.setCommonPrefixes(Collections.emptyList());
    final ObjectListing bucketListing = spy(new ObjectListing());
    final S3ObjectSummary fileSummary = new S3ObjectSummary();
    fileSummary.setKey(OLD_PATH + "/someBigFile");
    fileSummary.setSize(EXCEEDED_OBJECT_SIZE);
    when(bucketListing.getObjectSummaries()).thenReturn(Collections.singletonList(fileSummary));
    when(amazonS3.listObjects(any(ListObjectsRequest.class))).thenReturn(sourceListing, destinationListing, bucketListing);
    assertThrows(e -> e instanceof DataStorageException && e.getMessage().contains(SIZE_EXCEEDS_EXCEPTION_MESSAGE), () -> helper.moveFolder(BUCKET, OLD_PATH, NEW_PATH));
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) Test(org.junit.Test)

Example 28 with DataStorageException

use of com.epam.pipeline.entity.datastorage.DataStorageException in project cloud-pipeline by epam.

the class S3HelperTest method testRestoreFileVersionShouldThrowIfFileSizeExceedsTheLimit.

@Test
public void testRestoreFileVersionShouldThrowIfFileSizeExceedsTheLimit() {
    final ObjectMetadata fileMetadata = new ObjectMetadata();
    fileMetadata.setContentLength(EXCEEDED_OBJECT_SIZE);
    when(amazonS3.getObjectMetadata(any())).thenReturn(fileMetadata);
    assertThrows(e -> e instanceof DataStorageException && e.getMessage().contains(SIZE_EXCEEDS_EXCEPTION_MESSAGE), () -> helper.restoreFileVersion(BUCKET, OLD_PATH, VERSION));
}
Also used : DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Test(org.junit.Test)

Aggregations

DataStorageException (com.epam.pipeline.entity.datastorage.DataStorageException)28 IOException (java.io.IOException)14 DataStorageFile (com.epam.pipeline.entity.datastorage.DataStorageFile)12 File (java.io.File)11 AmazonS3 (com.amazonaws.services.s3.AmazonS3)8 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)5 DataStorageItemContent (com.epam.pipeline.entity.datastorage.DataStorageItemContent)5 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)4 ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)4 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)4 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)4 DataStorageFolder (com.epam.pipeline.entity.datastorage.DataStorageFolder)4 DataStorageStreamingContent (com.epam.pipeline.entity.datastorage.DataStorageStreamingContent)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 SdkClientException (com.amazonaws.SdkClientException)3 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)3 InputStream (java.io.InputStream)3 Date (java.util.Date)3 List (java.util.List)3 Test (org.junit.Test)3