11/*
2- * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+ * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1515
1616package com .amazonaws .services .s3 ;
1717
18+ import android .util .Log ;
19+
20+ import static junit .framework .Assert .assertTrue ;
1821import static org .junit .Assert .assertEquals ;
1922import static org .junit .Assert .fail ;
2023
2730import com .amazonaws .services .s3 .model .VersionListing ;
2831import com .amazonaws .testutils .util .RandomInputStream ;
2932
30- import org .junit .After ;
33+ import org .junit .AfterClass ;
34+ import org .junit .BeforeClass ;
3135import org .junit .Test ;
3236
3337/**
3438 * Integration test for S3 storage class related operations.
3539 */
3640public class StorageClassIntegrationTest extends S3IntegrationTestBase {
3741
38- private String bucketName = "java-storage-class-integ-test-" + System .currentTimeMillis ();
42+ private static final String BUCKET_NAME = "java-storage-class-integ-test-" + System .currentTimeMillis ();
43+
44+ private static final String TAG = StorageClassIntegrationTest .class .getSimpleName ();
45+
46+ @ BeforeClass
47+ public static void setUp () {
48+ try {
49+ S3IntegrationTestBase .setUp ();
50+ s3 .createBucket (BUCKET_NAME );
51+ waitForBucketCreation (BUCKET_NAME );
52+ } catch (Exception ex ) {
53+ Log .e (TAG , "Error in creating the bucket: " + BUCKET_NAME );
54+ assertTrue ("Error in creating the bucket: " + BUCKET_NAME , false );
55+ }
56+ }
3957
4058 /**
4159 * Releases all resources allocated by this test.
4260 */
43- @ After
44- public void tearDown () throws Exception {
45- deleteBucketAndAllVersionedContents (bucketName );
61+ @ AfterClass
62+ public static void tearDown () {
63+ try {
64+ deleteBucketAndAllVersionedContents (BUCKET_NAME );
65+ } catch (Exception ex ) {
66+ Log .e (TAG , "Error in deleting the bucket: " + BUCKET_NAME );
67+ }
4668 }
4769
4870 /**
4971 * Tests that we can change an object's storage class, upload objects in a
50- * specific storage class, and retrive an object's storage class, both for
51- * versioned and unversioned objects.
72+ * specific storage class, and retrieve an object's storage class, both for
73+ * versioned and non-versioned objects.
5274 */
5375 @ Test
5476 public void testStorageClasses () throws Exception {
55- s3 .createBucket (bucketName );
56-
5777 // Upload an object with standard storage
58- putObject (bucketName , "key" , StorageClass .Standard .toString ());
59- assertStorageClass (bucketName , "key" , StorageClass .Standard );
78+ putObject (BUCKET_NAME , "key" , StorageClass .Standard .toString ());
79+ assertStorageClass (BUCKET_NAME , "key" , StorageClass .Standard );
6080
6181 // Upload an object with reduced redundancy storage
62- putObject (bucketName , "key" , StorageClass .ReducedRedundancy .toString ());
63- assertStorageClass (bucketName , "key" , StorageClass .ReducedRedundancy );
82+ putObject (BUCKET_NAME , "key" , StorageClass .ReducedRedundancy .toString ());
83+ assertStorageClass (BUCKET_NAME , "key" , StorageClass .ReducedRedundancy );
6484
65- // Move to regular storage
66- s3 .changeObjectStorageClass (bucketName , "key" , StorageClass .Standard );
67- assertStorageClass (bucketName , "key" , StorageClass .Standard );
85+ // Move to Standard storage
86+ s3 .changeObjectStorageClass (BUCKET_NAME , "key" , StorageClass .Standard );
87+ assertStorageClass (BUCKET_NAME , "key" , StorageClass .Standard );
6888
6989 // Move back to reduced redundancy storage
70- s3 .changeObjectStorageClass (bucketName , "key" , StorageClass .ReducedRedundancy );
71- assertStorageClass (bucketName , "key" , StorageClass .ReducedRedundancy );
90+ s3 .changeObjectStorageClass (BUCKET_NAME , "key" , StorageClass .ReducedRedundancy );
91+ assertStorageClass (BUCKET_NAME , "key" , StorageClass .ReducedRedundancy );
7292
7393 // Turn on versioning
7494 s3 .setBucketVersioningConfiguration (new SetBucketVersioningConfigurationRequest (
75- bucketName ,
95+ BUCKET_NAME ,
7696 new BucketVersioningConfiguration (BucketVersioningConfiguration .ENABLED )));
7797
7898 // Upload a new version with standard storage
79- putObject (bucketName , "key" , StorageClass .Standard .toString ());
80- assertStorageClass (bucketName , "key" , StorageClass .Standard );
99+ putObject (BUCKET_NAME , "key" , StorageClass .Standard .toString ());
100+ assertStorageClass (BUCKET_NAME , "key" , StorageClass .Standard );
81101
82102 // Move to reduced redundancy storage
83- s3 .changeObjectStorageClass (bucketName , "key" , StorageClass .ReducedRedundancy );
84- assertStorageClass (bucketName , "key" , StorageClass .ReducedRedundancy );
103+ s3 .changeObjectStorageClass (BUCKET_NAME , "key" , StorageClass .ReducedRedundancy );
104+ assertStorageClass (BUCKET_NAME , "key" , StorageClass .ReducedRedundancy );
85105
86106 // And move back to standard storage
87- s3 .changeObjectStorageClass (bucketName , "key" , StorageClass .Standard );
88- assertStorageClass (bucketName , "key" , StorageClass .Standard );
107+ s3 .changeObjectStorageClass (BUCKET_NAME , "key" , StorageClass .Standard );
108+ assertStorageClass (BUCKET_NAME , "key" , StorageClass .Standard );
109+ }
110+
111+ /**
112+ * Tests that we can change an object's storage class, upload objects in a
113+ * specific storage class, and retrive an object's storage class.
114+ */
115+ @ Test
116+ public void testStorageClasseIntelligentTiering () throws Exception {
117+ // Upload an object with IntelligentTiering storage
118+ putObject (BUCKET_NAME , "key" , StorageClass .IntelligentTiering .toString ());
119+ assertStorageClass (BUCKET_NAME , "key" , StorageClass .IntelligentTiering );
120+
121+ // Upload an object with reduced redundancy storage
122+ putObject (BUCKET_NAME , "key" , StorageClass .ReducedRedundancy .toString ());
123+ assertStorageClass (BUCKET_NAME , "key" , StorageClass .ReducedRedundancy );
124+
125+ // Move to Standard storage
126+ s3 .changeObjectStorageClass (BUCKET_NAME , "key" , StorageClass .Standard );
127+ assertStorageClass (BUCKET_NAME , "key" , StorageClass .Standard );
128+
129+ // Move back to IntelligentTiering storage
130+ s3 .changeObjectStorageClass (BUCKET_NAME , "key" , StorageClass .IntelligentTiering );
131+ assertStorageClass (BUCKET_NAME , "key" , StorageClass .IntelligentTiering );
132+
133+ // Turn on versioning
134+ s3 .setBucketVersioningConfiguration (new SetBucketVersioningConfigurationRequest (
135+ BUCKET_NAME ,
136+ new BucketVersioningConfiguration (BucketVersioningConfiguration .ENABLED )));
137+
138+ // Upload a new version with IntelligentTiering storage
139+ putObject (BUCKET_NAME , "key" , StorageClass .IntelligentTiering .toString ());
140+ assertStorageClass (BUCKET_NAME , "key" , StorageClass .IntelligentTiering );
141+
142+ // Move to reduced redundancy storage
143+ s3 .changeObjectStorageClass (BUCKET_NAME , "key" , StorageClass .ReducedRedundancy );
144+ assertStorageClass (BUCKET_NAME , "key" , StorageClass .ReducedRedundancy );
145+
146+ // And move back to IntelligentTiering storage
147+ s3 .changeObjectStorageClass (BUCKET_NAME , "key" , StorageClass .IntelligentTiering );
148+ assertStorageClass (BUCKET_NAME , "key" , StorageClass .IntelligentTiering );
89149 }
90150
91151 /*
@@ -96,7 +156,9 @@ public void testStorageClasses() throws Exception {
96156 * Uploads some random test data to the object stored in the specified
97157 * bucket and key, and uses the specified storage class.
98158 */
99- private void putObject (String bucketName , String key , String storageClass ) {
159+ private void putObject (String bucketName ,
160+ String key ,
161+ String storageClass ) {
100162 ObjectMetadata metadata = new ObjectMetadata ();
101163 metadata .setContentLength (1230 );
102164 PutObjectRequest request = new PutObjectRequest (bucketName , key ,
@@ -109,7 +171,9 @@ private void putObject(String bucketName, String key, String storageClass) {
109171 * Asserts that the latest version for the specified object is stored in the
110172 * expected storage class, otherwise this method fails the current test.
111173 */
112- private void assertStorageClass (String bucketName , String key , StorageClass expectedStorageClass )
174+ private void assertStorageClass (String bucketName ,
175+ String key ,
176+ StorageClass expectedStorageClass )
113177 throws Exception {
114178 // Short pause for eventual consistency
115179 Thread .sleep (1000 * 3 );
0 commit comments