Skip to content

Commit 599d628

Browse files
author
Stu Arnett
committed
* AbstractS3ClientTest: moved testIam property into abstract class and renamed to isIamUser - added check for IAM user when checking for object lock in cleanUpBucket()
* S3JerseyClientV4Test: fixed renamed child methods to simply override super methods directly * WriteTruncationTest: refactored to extend AbstractS3ClientTest and run concurrently (several methods take >1 minute to execute)
1 parent 6d3e22f commit 599d628

File tree

5 files changed

+74
-146
lines changed

5 files changed

+74
-146
lines changed

src/test/java/com/emc/object/s3/AbstractS3ClientTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@
4040
import com.emc.rest.smart.ecs.Vdc;
4141
import com.emc.util.TestConfig;
4242
import org.junit.After;
43+
import org.junit.Before;
4344
import org.slf4j.Logger;
4445
import org.slf4j.LoggerFactory;
4546

47+
import java.io.IOException;
4648
import java.net.URI;
4749
import java.util.Arrays;
4850
import java.util.Properties;
@@ -55,6 +57,7 @@ public abstract class AbstractS3ClientTest extends AbstractClientTest {
5557
* may be null
5658
*/
5759
protected String ecsVersion;
60+
protected boolean isIamUser = false;
5861
protected CanonicalUser bucketOwner;
5962

6063
protected abstract S3Client createS3Client() throws Exception;
@@ -68,6 +71,12 @@ protected final void initClient() throws Exception {
6871
}
6972
}
7073

74+
@Before
75+
public void checkIamUser() throws IOException {
76+
Properties props = TestConfig.getProperties();
77+
this.isIamUser = Boolean.parseBoolean(props.getProperty(TestProperties.S3_IAM_USER));
78+
}
79+
7180
@After
7281
public void dumpLBStats() {
7382
if (client != null) {
@@ -90,7 +99,7 @@ protected void createBucket(String bucketName) throws Exception {
9099
@Override
91100
protected void cleanUpBucket(String bucketName) {
92101
if (client != null && client.bucketExists(bucketName)) {
93-
boolean objectLockEnabled = client.getObjectLockConfiguration(bucketName) != null;
102+
boolean objectLockEnabled = isIamUser && client.getObjectLockConfiguration(bucketName) != null;
94103
if (client.getBucketVersioning(bucketName).getStatus() != null) {
95104
for (AbstractVersion version : client.listVersions(new ListVersionsRequest(bucketName).withEncodingType(EncodingType.url)).getVersions()) {
96105
DeleteObjectRequest deleteRequest = new DeleteObjectRequest(bucketName, version.getKey()).withVersionId(version.getVersionId());

src/test/java/com/emc/object/s3/S3JerseyClientTest.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,6 @@
6464

6565
public class S3JerseyClientTest extends AbstractS3ClientTest {
6666
private static final Logger log = LoggerFactory.getLogger(S3JerseyClientTest.class);
67-
protected boolean testIAM = false;
68-
69-
@Before
70-
public void checkIamUser() {
71-
try {
72-
Properties props = TestConfig.getProperties();
73-
testIAM = Boolean.parseBoolean(props.getProperty(TestProperties.S3_IAM_USER));
74-
} catch (Exception ignored) {
75-
}
76-
}
7767

7868
@Override
7969
protected String getTestBucketPrefix() {
@@ -180,7 +170,7 @@ public void testCreateBucketRequest() throws Exception {
180170

181171
@Test
182172
public void testCreateFilesystemBucket() {
183-
Assume.assumeFalse("FS buckets are not supported with IAM user.", testIAM);
173+
Assume.assumeFalse("FS buckets are not supported with IAM user.", isIamUser);
184174

185175
String bucketName = getTestBucket() + "-y";
186176

@@ -210,7 +200,7 @@ public void testCreateEncryptedBucket() {
210200
@Test
211201
public void testEnableObjectLockOnExistingBucket() {
212202
Assume.assumeTrue("ECS version must be at least 3.6.2", ecsVersion != null && ecsVersion.compareTo("3.6.2") >= 0);
213-
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", testIAM);
203+
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", isIamUser);
214204

215205
String bucketName = getTestBucket();
216206
ObjectLockConfiguration objectLockConfig = client.getObjectLockConfiguration(bucketName);
@@ -223,7 +213,7 @@ public void testEnableObjectLockOnExistingBucket() {
223213
@Test
224214
public void testCreateObjectLockBucket() {
225215
Assume.assumeTrue("ECS version must be at least 3.6.2", ecsVersion != null && ecsVersion.compareTo("3.6.2") >= 0);
226-
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", testIAM);
216+
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", isIamUser);
227217

228218
String bucketName = "s3-client-test-createObjectLockBucket";
229219
client.createBucket(new CreateBucketRequest(bucketName).withObjectLockEnabled(true));
@@ -235,7 +225,7 @@ public void testCreateObjectLockBucket() {
235225
@Test
236226
public void testSetObjectLockConfiguration() {
237227
Assume.assumeTrue("ECS version must be at least 3.6.2", ecsVersion != null && ecsVersion.compareTo("3.6.2") >= 0);
238-
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", testIAM);
228+
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", isIamUser);
239229

240230
String bucketName = getTestBucket();
241231
ObjectLockConfiguration objectLockConfig = new ObjectLockConfiguration().withObjectLockEnabled(ObjectLockConfiguration.ObjectLockEnabled.Enabled);
@@ -262,7 +252,7 @@ public void testSetObjectLockConfiguration() {
262252
@Test
263253
public void testDeleteObjectWithLegalHoldNotAllowed() throws Exception {
264254
Assume.assumeTrue("ECS version must be at least 3.6.2", ecsVersion != null && ecsVersion.compareTo("3.6.2") >= 0);
265-
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", testIAM);
255+
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", isIamUser);
266256

267257
String bucketName = getTestBucket();
268258
String key = "testObject_DeleteWithLegalHold";
@@ -289,7 +279,7 @@ public void testDeleteObjectWithLegalHoldNotAllowed() throws Exception {
289279
@Test
290280
public void testPutObjectLegalHold() throws Exception {
291281
Assume.assumeTrue("ECS version must be at least 3.6.2", ecsVersion != null && ecsVersion.compareTo("3.6.2") >= 0);
292-
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", testIAM);
282+
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", isIamUser);
293283

294284
String bucketName = getTestBucket();
295285
String key = "testObject_PutObjectLegalHold";
@@ -316,7 +306,7 @@ public void testPutObjectLegalHold() throws Exception {
316306
@Test
317307
public void testPutObjectRetention() throws Exception {
318308
Assume.assumeTrue("ECS version must be at least 3.6.2", ecsVersion != null && ecsVersion.compareTo("3.6.2") >= 0);
319-
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", testIAM);
309+
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", isIamUser);
320310

321311
String bucketName = getTestBucket();
322312
String key = "testObject_PutObjectRetention";
@@ -358,7 +348,7 @@ public void testPutObjectRetention() throws Exception {
358348
@Test
359349
public void testDeleteObjectWithBypassGovernance() throws Exception {
360350
Assume.assumeTrue("ECS version must be at least 3.6.2", ecsVersion != null && ecsVersion.compareTo("3.6.2") >= 0);
361-
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", testIAM);
351+
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", isIamUser);
362352

363353
String bucketName = getTestBucket();
364354
String key = "testDeleteObjectWithBypassGovernance";
@@ -398,7 +388,7 @@ public void testDeleteObjectWithBypassGovernance() throws Exception {
398388
@Test
399389
public void testCopyObjectWithLegalHoldON() throws Exception {
400390
Assume.assumeTrue("ECS version must be at least 3.6.2", ecsVersion != null && ecsVersion.compareTo("3.6.2") >= 0);
401-
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", testIAM);
391+
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", isIamUser);
402392

403393
String bucketName = getTestBucket();
404394
String key1 = "source-object";
@@ -426,7 +416,7 @@ public void testCopyObjectWithLegalHoldON() throws Exception {
426416
@Test
427417
public void testSingleMultipartUploadWithRetention() throws Exception {
428418
Assume.assumeTrue("ECS version must be at least 3.6.2", ecsVersion != null && ecsVersion.compareTo("3.6.2") >= 0);
429-
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", testIAM);
419+
Assume.assumeTrue("Skip Object Lock related tests for non IAM user.", isIamUser);
430420

431421
String bucketName = getTestBucket();
432422
String key = "testMpuSimple";

src/test/java/com/emc/object/s3/S3JerseyClientV4Test.java

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,8 @@ public S3Client createS3Client() throws Exception {
2727
return new S3JerseyClient(createS3Config().withUseV2Signer(false));
2828
}
2929

30-
@Ignore
31-
@Test
30+
@Override
3231
public void testPreSignedUrl() throws Exception {
33-
}
34-
35-
@Test
36-
public void testPreSignedUrlV4() throws Exception {
3732
S3Config s3Config = new S3Config(new URI("https://s3.amazonaws.com")).withUseVHost(true)
3833
.withIdentity("AKIAIOSFODNN7EXAMPLE").withSecretKey("wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
3934
.withUseV2Signer(false);
@@ -47,13 +42,8 @@ public void testPreSignedUrlV4() throws Exception {
4742
url.toString().contains("&X-Amz-SignedHeaders");
4843
}
4944

50-
@Ignore
51-
@Test
45+
@Override
5246
public void testPreSignedPutUrl() throws Exception {
53-
}
54-
55-
@Test
56-
public void testPreSignedPutUrlV4() throws Exception {
5747
S3Config s3Config = new S3Config(new URI("https://s3.amazonaws.com")).withUseVHost(true)
5848
.withIdentity("AKIAIOSFODNN7EXAMPLE").withSecretKey("wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
5949
.withUseV2Signer(false);
@@ -89,13 +79,8 @@ public void testPreSignedPutUrlV4() throws Exception {
8979
Assert.assertEquals("bar", metadata.getUserMetadata("foo"));
9080
}
9181

92-
@Ignore
93-
@Test
82+
@Override
9483
public void testPreSignedPutNoContentType() throws Exception {
95-
}
96-
97-
@Test
98-
public void testPreSignedPutNoContentTypeV4() throws Exception {
9984
S3Config s3Config = new S3Config(new URI("https://s3.amazonaws.com")).withUseVHost(true)
10085
.withIdentity("AKIAIOSFODNN7EXAMPLE").withSecretKey("wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
10186
.withUseV2Signer(false);
@@ -133,13 +118,8 @@ public void testPreSignedPutNoContentTypeV4() throws Exception {
133118
Assert.assertEquals("bar", metadata.getUserMetadata("foo"));
134119
}
135120

136-
@Ignore
137-
@Test
121+
@Override
138122
public void testPreSignedUrlWithChinese() throws Exception {
139-
}
140-
141-
@Test
142-
public void testPreSignedUrlWithChineseV4() throws Exception {
143123
S3Config s3Config = new S3Config(new URI("https://s3.amazonaws.com")).withUseVHost(true)
144124
.withIdentity("stu").withSecretKey("/QcPo5pEvQh7EOHKs2XjzCARrt7HokZhlpdGKbHs")
145125
.withUseV2Signer(false);
@@ -152,8 +132,8 @@ public void testPreSignedUrlWithChineseV4() throws Exception {
152132
url.toString().contains("&X-Amz-SignedHeaders=");
153133
}
154134

155-
@Test
156-
public void testPreSignedUrlWithHeadersV4() throws Exception {
135+
@Override
136+
public void testPreSignedUrlHeaderOverrides() throws Exception {
157137
S3Config s3Config = new S3Config(new URI("https://s3.amazonaws.com")).withUseVHost(true)
158138
.withIdentity("AKIAIOSFODNN7EXAMPLE").withSecretKey("wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
159139
.withUseV2Signer(false);
@@ -171,9 +151,4 @@ public void testPreSignedUrlWithHeadersV4() throws Exception {
171151
url.toString().contains("&X-Amz-Expires=") & url.toString().contains("&X-Amz-Signature=") &
172152
url.toString().contains("&X-Amz-SignedHeaders=content-md5%3Bcontent-type");
173153
}
174-
175-
@Ignore
176-
@Test
177-
public void testPreSignedUrlHeaderOverrides() throws Exception {
178-
}
179154
}

src/test/java/com/emc/object/s3/WriteTruncationTest.java

Lines changed: 39 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,65 @@
11
package com.emc.object.s3;
22

3-
import com.emc.object.ObjectConfig;
4-
import com.emc.object.s3.bean.ListObjectsResult;
5-
import com.emc.object.s3.bean.S3Object;
63
import com.emc.object.s3.jersey.S3JerseyClient;
74
import com.emc.object.s3.request.CreateBucketRequest;
85
import com.emc.object.s3.request.PutObjectRequest;
96
import com.emc.object.util.FaultInjectionStream;
7+
import com.emc.util.ConcurrentJunitRunner;
108
import com.sun.jersey.api.client.ClientHandlerException;
119
import com.sun.jersey.client.urlconnection.URLConnectionClientHandler;
1210
import org.apache.commons.codec.digest.DigestUtils;
13-
import org.junit.*;
14-
import org.slf4j.Logger;
15-
import org.slf4j.LoggerFactory;
11+
import org.junit.After;
12+
import org.junit.Assert;
13+
import org.junit.Ignore;
14+
import org.junit.Test;
15+
import org.junit.runner.RunWith;
1616

1717
import javax.xml.bind.DatatypeConverter;
1818
import java.io.ByteArrayInputStream;
1919
import java.io.IOException;
2020
import java.io.InputStream;
21-
import java.net.URI;
2221
import java.util.Random;
2322

24-
public class WriteTruncationTest {
25-
public static final Logger log = LoggerFactory.getLogger(WriteTruncationTest.class);
26-
27-
static final String BUCKET_NAME = "ecs-object-client-write-truncation-test";
23+
@RunWith(ConcurrentJunitRunner.class)
24+
public class WriteTruncationTest extends AbstractS3ClientTest {
2825
static final int OBJECT_RETENTION_PERIOD = 15; // 15 seconds
2926
static final int MOCK_OBJ_SIZE = 5 * 1024 * 1024; // 5MB
3027

31-
S3Client s3Client;
32-
S3Client s3JvmClient;
28+
S3Client jvmClient;
3329
final Random random = new Random();
3430

35-
@Before
36-
public void setup() throws Exception {
37-
S3Config s3Config = AbstractS3ClientTest.s3ConfigFromProperties();
38-
s3Config.setRetryEnabled(false);
31+
@Override
32+
protected S3Client createS3Client() throws Exception {
33+
S3Config s3Config = createS3Config().withRetryEnabled(false);
34+
this.jvmClient = new S3JerseyClient(s3Config, new URLConnectionClientHandler());
35+
return new S3JerseyClient(createS3Config().withRetryEnabled(false));
36+
}
3937

40-
String proxy = s3Config.getPropAsString(ObjectConfig.PROPERTY_PROXY_URI);
41-
if (proxy != null) {
42-
URI proxyUri = new URI(proxy);
43-
System.setProperty("http.proxyHost", proxyUri.getHost());
44-
System.setProperty("http.proxyPort", "" + proxyUri.getPort());
45-
}
38+
@Override
39+
protected String getTestBucketPrefix() {
40+
return "s3-write-truncation-test";
41+
}
4642

47-
s3Client = new S3JerseyClient(s3Config);
48-
s3JvmClient = new S3JerseyClient(s3Config, new URLConnectionClientHandler());
43+
@Override
44+
protected void createBucket(String bucketName) {
45+
// create bucket with retention period and D@RE enabled
46+
client.createBucket(new CreateBucketRequest(getTestBucket())
47+
.withRetentionPeriod(OBJECT_RETENTION_PERIOD)
48+
.withEncryptionEnabled(true));
49+
}
4950

51+
@Override
52+
protected void cleanUpBucket(String bucketName) {
5053
try {
51-
// create bucket with retention period and D@RE enabled
52-
s3Client.createBucket(new CreateBucketRequest(BUCKET_NAME)
53-
.withRetentionPeriod(OBJECT_RETENTION_PERIOD)
54-
.withEncryptionEnabled(true));
55-
} catch (S3Exception e) {
56-
if (!e.getErrorCode().equals("BucketAlreadyExists")) throw e;
54+
Thread.sleep(OBJECT_RETENTION_PERIOD * 1000); // wait for retention to expire
55+
} catch (InterruptedException ignored) {
5756
}
57+
super.cleanUpBucket(bucketName);
58+
}
59+
60+
@After
61+
public void shutdownJvmClient() {
62+
if (jvmClient != null) jvmClient.destroy();
5863
}
5964

6065
@Test
@@ -126,7 +131,7 @@ void testTruncatedWrite(boolean useApacheClient,
126131
ExceptionType exceptionType,
127132
int delayBeforeException,
128133
boolean sendContentMd5) {
129-
S3Client s3Client = useApacheClient ? this.s3Client : this.s3JvmClient;
134+
S3Client s3Client = useApacheClient ? this.client : this.jvmClient;
130135

131136
String key = String.format("read-%s%s-%s%stest",
132137
delayBeforeException > 0 ? "delayed-" : "",
@@ -153,7 +158,7 @@ void testTruncatedWrite(boolean useApacheClient,
153158
badStream.setSecondDelayBeforeThrowing(delayBeforeException);
154159

155160
try {
156-
s3Client.putObject(new PutObjectRequest(BUCKET_NAME, key, badStream).withObjectMetadata(metadata));
161+
s3Client.putObject(new PutObjectRequest(getTestBucket(), key, badStream).withObjectMetadata(metadata));
157162
Assert.fail("exception in input stream did not throw an exception");
158163
} catch (ClientHandlerException e) {
159164
if (exceptionType == ExceptionType.RuntimeException) {
@@ -170,35 +175,7 @@ void testTruncatedWrite(boolean useApacheClient,
170175
} catch (InterruptedException ignored) {
171176
}
172177

173-
Assert.assertEquals(0, s3Client.listObjects(BUCKET_NAME).getObjects().size());
174-
}
175-
176-
@After
177-
public void teardown() {
178-
if (s3Client == null) return;
179-
180-
try {
181-
Thread.sleep(OBJECT_RETENTION_PERIOD * 1000); // wait for retention to expire
182-
} catch (InterruptedException ignored) {
183-
}
184-
185-
try {
186-
ListObjectsResult listing = null;
187-
do {
188-
if (listing == null) listing = s3Client.listObjects(BUCKET_NAME);
189-
else listing = s3Client.listMoreObjects(listing);
190-
191-
for (final S3Object summary : listing.getObjects()) {
192-
s3Client.deleteObject(BUCKET_NAME, summary.getKey());
193-
}
194-
} while (listing.isTruncated());
195-
196-
s3Client.deleteBucket(BUCKET_NAME);
197-
} catch (RuntimeException e) {
198-
log.error("could not delete bucket " + BUCKET_NAME, e);
199-
} finally {
200-
s3Client.destroy();
201-
}
178+
Assert.assertEquals(0, s3Client.listObjects(getTestBucket()).getObjects().size());
202179
}
203180

204181
enum ExceptionType {

0 commit comments

Comments
 (0)