Search in sources :

Example 1 with RandomTempFile

use of com.amazonaws.testutils.util.RandomTempFile in project aws-sdk-android by aws-amplify.

the class GetObjectIntegrationTest method setUp.

/**
 * Creates and initializes all the test resources needed for these tests.
 */
@BeforeClass
public static void setUp() throws Exception {
    S3IntegrationTestBase.setUp();
    if (!ANDROID_TESTING) {
        setUpCredentials();
    }
    final long fileSize = 100000L;
    tempData = tempDataBuffer((int) fileSize);
    s3.createBucket(BUCKET_NAME);
    s3.createBucket(REQUESTER_PAYS_BUCKET_NAME);
    ObjectMetadata metadata = null;
    if (!ANDROID_TESTING) {
        file = new RandomTempFile("get-object-integ-test", fileSize);
        s3.putObject(BUCKET_NAME, KEY, file);
        s3.putObject(REQUESTER_PAYS_BUCKET_NAME, KEY, file);
    } else {
        file = getRandomTempFile("foo", fileSize);
        final ByteArrayInputStream bais = new ByteArrayInputStream(tempData);
        metadata = new ObjectMetadata();
        metadata.setContentLength(fileSize);
        s3.putObject(new PutObjectRequest(BUCKET_NAME, KEY, bais, metadata));
        bais.close();
    }
    metadata = s3.getObjectMetadata(BUCKET_NAME, KEY);
    etag = metadata.getETag();
    final Date lastModified = metadata.getLastModified();
    earlierDate = new Date(lastModified.getTime() - 1000);
    laterDate = new Date(lastModified.getTime() + 1000);
    // Sleep for a few seconds to make sure the test doesn't run before
    // the future date
    Thread.sleep(1000 * 2);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RandomTempFile(com.amazonaws.testutils.util.RandomTempFile) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Date(java.util.Date) BeforeClass(org.junit.BeforeClass)

Example 2 with RandomTempFile

use of com.amazonaws.testutils.util.RandomTempFile in project aws-sdk-android by aws-amplify.

the class BucketLifecycleConfigurationIntegrationTest method setUp.

/**
 * Creates and initializes all the test resources needed for these tests.
 */
@BeforeClass
public static void setUp() throws Exception {
    S3IntegrationTestBase.setUp();
    if (!ANDROID_TESTING) {
        setUpCredentials();
    }
    tempData = tempDataBuffer(1000);
    s3.createBucket(BUCKET_NAME);
    S3IntegrationTestBase.waitForBucketCreation(BUCKET_NAME);
    ObjectMetadata metadata = null;
    if (!ANDROID_TESTING) {
        file = new RandomTempFile("get-object-integ-test", 1000L);
        s3.putObject(BUCKET_NAME, KEY, file);
    } else {
        file = S3IntegrationTestBase.getRandomTempFile("foo", 1000L);
        ByteArrayInputStream bais = new ByteArrayInputStream(tempData);
        metadata = new ObjectMetadata();
        metadata.setContentLength(1000);
        s3.putObject(new PutObjectRequest(BUCKET_NAME, KEY, bais, metadata));
        bais.close();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RandomTempFile(com.amazonaws.testutils.util.RandomTempFile) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) BeforeClass(org.junit.BeforeClass)

Example 3 with RandomTempFile

use of com.amazonaws.testutils.util.RandomTempFile in project aws-sdk-android by aws-amplify.

the class ServerSideEncryptionWithCustomerKeyIntegrationTest method setUp.

/**
 * Creates and initializes all the test resources needed for these tests.
 */
@BeforeClass
public static void setUp() throws Exception {
    S3IntegrationTestBase.setUp();
    s3.createBucket(BUCKET_NAME);
    file_singleUpload = new RandomTempFile("get-object-integ-test-single-upload", SINGLE_UPLOAD_OBJECT_SIZE);
    file_multipartUpload = new RandomTempFile("get-object-integ-test-multipart-upload", PART_NUMBER * PART_SIZE);
    secretKey = generateSecretKey();
    secretKey_b64 = Base64.encodeAsString(secretKey.getEncoded());
}
Also used : RandomTempFile(com.amazonaws.testutils.util.RandomTempFile) BeforeClass(org.junit.BeforeClass)

Example 4 with RandomTempFile

use of com.amazonaws.testutils.util.RandomTempFile in project aws-sdk-android by aws-amplify.

the class MultiThreadedDownloadIntegrationTest method testMultipleDownloads.

/**
 * Tests that we can successfully download objects from multiple threads
 * using the same Amazon S3 client, and that the objects are downloaded
 * correctly, matching the content that we uploaded, and with the metadata
 * that we expect.
 */
@Test
public void testMultipleDownloads() throws Exception {
    file = new RandomTempFile("download-stress-integ-test-file.txt", CONTENT_LENGTH);
    s3.createBucket(bucketName);
    s3.putObject(bucketName, key, file);
    List<Callable<Integer>> tasks = new ArrayList<Callable<Integer>>();
    for (int i = 0; i < TOTAL_REQUESTS; i++) {
        tasks.add(new TimedGetObjectCallable());
    }
    List<Future<Integer>> futures = threadPool.invokeAll(tasks);
    for (java.util.Iterator iterator = futures.iterator(); iterator.hasNext(); ) {
        Future<Integer> future = (Future<Integer>) iterator.next();
        int executionTime = future.get().intValue();
        assertTrue(executionTime > 0);
        assertTrue(executionTime < 1000 * 10);
    }
}
Also used : ArrayList(java.util.ArrayList) RandomTempFile(com.amazonaws.testutils.util.RandomTempFile) Future(java.util.concurrent.Future) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 5 with RandomTempFile

use of com.amazonaws.testutils.util.RandomTempFile in project aws-sdk-android by aws-amplify.

the class GetObjectIntegrationTest method testGetDirectoryObjectAsFile.

/**
 * Tests that we can download a directory-keyed object to a file.
 */
@Test
public void testGetDirectoryObjectAsFile() throws Exception {
    final File data = new RandomTempFile("get-object-integ-test-directory", 1000L);
    final String directoryKey = "a/b/c/d.dat";
    s3.putObject(BUCKET_NAME, directoryKey, data);
    final File tempFile = File.createTempFile("aws-java-sdk-integ-test", ".dat");
    final ObjectMetadata objectMetadata = s3.getObject(new GetObjectRequest(BUCKET_NAME, directoryKey), tempFile);
    assertNull(objectMetadata.getSSEAlgorithm());
    assertNotNull(objectMetadata.getLastModified());
    assertNotNull(objectMetadata.getContentType());
    assertTrue(tempFile.exists());
    assertFileEqualsStream(tempFile, new FileInputStream(data));
}
Also used : RandomTempFile(com.amazonaws.testutils.util.RandomTempFile) RandomTempFile(com.amazonaws.testutils.util.RandomTempFile) File(java.io.File) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

RandomTempFile (com.amazonaws.testutils.util.RandomTempFile)6 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)4 BeforeClass (org.junit.BeforeClass)4 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Test (org.junit.Test)2 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Callable (java.util.concurrent.Callable)1 Future (java.util.concurrent.Future)1