Skip to content

Commit 68f6234

Browse files
committed
HADOOP-18508. Tune ITestS3AEncryptionSSEC
-always create base dir at the start of each test -use methodPath() -remove final relics of s3guard comments/qualifiers -remove parameterization on directory marker retention, the default of "keep" stresses the trickiest bit of the code as it leaves more markers around. Change-Id: Ib1fa2940116170bd5d00375ab51ed582f8cad1f6
1 parent d82fa09 commit 68f6234

File tree

1 file changed

+17
-69
lines changed

1 file changed

+17
-69
lines changed

hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AEncryptionSSEC.java

Lines changed: 17 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@
2020

2121
import java.io.IOException;
2222
import java.nio.file.AccessDeniedException;
23-
import java.util.Arrays;
24-
import java.util.Collection;
2523

2624
import org.assertj.core.api.Assertions;
2725
import org.junit.Test;
28-
import org.junit.runner.RunWith;
29-
import org.junit.runners.Parameterized;
3026

3127
import org.apache.hadoop.conf.Configuration;
3228
import org.apache.hadoop.fs.FileSystem;
@@ -37,15 +33,11 @@
3733

3834
import static org.apache.hadoop.fs.contract.ContractTestUtils.dataset;
3935
import static org.apache.hadoop.fs.contract.ContractTestUtils.touch;
40-
import static org.apache.hadoop.fs.s3a.Constants.DIRECTORY_MARKER_POLICY;
41-
import static org.apache.hadoop.fs.s3a.Constants.DIRECTORY_MARKER_POLICY_DELETE;
42-
import static org.apache.hadoop.fs.s3a.Constants.DIRECTORY_MARKER_POLICY_KEEP;
4336
import static org.apache.hadoop.fs.s3a.Constants.ETAG_CHECKSUM_ENABLED;
4437
import static org.apache.hadoop.fs.s3a.Constants.S3_ENCRYPTION_ALGORITHM;
4538
import static org.apache.hadoop.fs.s3a.Constants.S3_ENCRYPTION_KEY;
4639
import static org.apache.hadoop.fs.s3a.Constants.SERVER_SIDE_ENCRYPTION_ALGORITHM;
4740
import static org.apache.hadoop.fs.s3a.Constants.SERVER_SIDE_ENCRYPTION_KEY;
48-
import static org.apache.hadoop.fs.s3a.S3ATestUtils.createTestPath;
4941
import static org.apache.hadoop.fs.s3a.S3ATestUtils.getTestBucketName;
5042
import static org.apache.hadoop.fs.s3a.S3ATestUtils.maybeSkipRootTests;
5143
import static org.apache.hadoop.fs.s3a.S3ATestUtils.removeBaseAndBucketOverrides;
@@ -59,7 +51,6 @@
5951
* Equally "vexing" has been the optimizations of getFileStatus(), wherein
6052
* LIST comes before HEAD path + /
6153
*/
62-
@RunWith(Parameterized.class)
6354
public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
6455

6556
private static final String SERVICE_AMAZON_S3_STATUS_CODE_403
@@ -74,31 +65,11 @@ public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
7465
= "msdo3VvvZznp66Gth58a91Hxe/UpExMkwU9BHkIjfW8=";
7566
private static final int TEST_FILE_LEN = 2048;
7667

77-
/**
78-
* Parameterization.
79-
*/
80-
@Parameterized.Parameters(name = "{0}")
81-
public static Collection<Object[]> params() {
82-
return Arrays.asList(new Object[][]{
83-
{"keep-markers", true},
84-
{"delete-markers", false}
85-
});
86-
}
87-
88-
/**
89-
* Parameter: should directory markers be retained?
90-
*/
91-
private final boolean keepMarkers;
92-
9368
/**
9469
* Filesystem created with a different key.
9570
*/
9671
private S3AFileSystem fsKeyB;
9772

98-
public ITestS3AEncryptionSSEC(final String name,
99-
final boolean keepMarkers) {
100-
this.keepMarkers = keepMarkers;
101-
}
10273

10374
@SuppressWarnings("deprecation")
10475
@Override
@@ -107,16 +78,11 @@ protected Configuration createConfiguration() {
10778
String bucketName = getTestBucketName(conf);
10879
// directory marker options
10980
removeBaseAndBucketOverrides(bucketName, conf,
110-
DIRECTORY_MARKER_POLICY,
11181
ETAG_CHECKSUM_ENABLED,
11282
S3_ENCRYPTION_ALGORITHM,
11383
S3_ENCRYPTION_KEY,
11484
SERVER_SIDE_ENCRYPTION_ALGORITHM,
11585
SERVER_SIDE_ENCRYPTION_KEY);
116-
conf.set(DIRECTORY_MARKER_POLICY,
117-
keepMarkers
118-
? DIRECTORY_MARKER_POLICY_KEEP
119-
: DIRECTORY_MARKER_POLICY_DELETE);
12086
conf.set(S3_ENCRYPTION_ALGORITHM,
12187
getSSEAlgorithm().getMethod());
12288
conf.set(S3_ENCRYPTION_KEY, KEY_1);
@@ -156,7 +122,7 @@ public void testCreateFileAndReadWithDifferentEncryptionKey() throws
156122
() -> {
157123
int len = TEST_FILE_LEN;
158124
describe("Create an encrypted file of size " + len);
159-
Path src = path("testCreateFileAndReadWithDifferentEncryptionKey");
125+
Path src = methodPath();
160126
writeThenReadFile(src, len);
161127

162128
//extract the test FS
@@ -176,7 +142,7 @@ public void testCreateFileAndReadWithDifferentEncryptionKey() throws
176142
*/
177143
@Test
178144
public void testCreateSubdirWithDifferentKey() throws Exception {
179-
Path base = path("testCreateSubdirWithDifferentKey");
145+
Path base = methodPath();
180146
Path nestedDirectory = new Path(base, "nestedDir");
181147
fsKeyB = createNewFileSystemWithSSECKey(
182148
KEY_2);
@@ -215,9 +181,10 @@ public void testCreateFileThenMoveWithDifferentSSECKey() throws Exception {
215181
*/
216182
@Test
217183
public void testRenameFile() throws Exception {
218-
Path src = path("original-path.txt");
184+
final Path base = methodPath();
185+
Path src = new Path(base, "original-path.txt");
219186
writeThenReadFile(src, TEST_FILE_LEN);
220-
Path newPath = path("different-path.txt");
187+
Path newPath = new Path(base, "different-path.txt");
221188
getFileSystem().rename(src, newPath);
222189
byte[] data = dataset(TEST_FILE_LEN, 'a', 'z');
223190
ContractTestUtils.verifyFileContents(getFileSystem(), newPath, data);
@@ -230,11 +197,11 @@ public void testRenameFile() throws Exception {
230197
@Test
231198
public void testListEncryptedDir() throws Exception {
232199

233-
Path pathABC = path("testListEncryptedDir/a/b/c/");
200+
Path pathABC = new Path(methodPath(), "a/b/c/");
234201
Path pathAB = pathABC.getParent();
235202
Path pathA = pathAB.getParent();
236203

237-
Path nestedDirectory = createTestPath(pathABC);
204+
Path nestedDirectory = pathABC;
238205
assertTrue(getFileSystem().mkdirs(nestedDirectory));
239206

240207
fsKeyB = createNewFileSystemWithSSECKey(KEY_4);
@@ -263,7 +230,7 @@ public void testListEncryptedDir() throws Exception {
263230
@Test
264231
public void testListStatusEncryptedDir() throws Exception {
265232

266-
Path pathABC = path("testListStatusEncryptedDir/a/b/c/");
233+
Path pathABC = new Path(methodPath(), "a/b/c/");
267234
Path pathAB = pathABC.getParent();
268235
Path pathA = pathAB.getParent();
269236
assertTrue(getFileSystem().mkdirs(pathABC));
@@ -298,7 +265,7 @@ public void testListStatusEncryptedDir() throws Exception {
298265
*/
299266
@Test
300267
public void testListStatusEncryptedFile() throws Exception {
301-
Path pathABC = path("testListStatusEncryptedFile/a/b/c/");
268+
Path pathABC = new Path(methodPath(), "a/b/c/");
302269
assertTrue("mkdirs failed", getFileSystem().mkdirs(pathABC));
303270

304271
Path fileToStat = new Path(pathABC, "fileToStat.txt");
@@ -307,23 +274,9 @@ public void testListStatusEncryptedFile() throws Exception {
307274
fsKeyB = createNewFileSystemWithSSECKey(KEY_4);
308275

309276
//Until this point, no exception is thrown about access
310-
if (statusProbesCheckS3(fsKeyB, fileToStat)) {
311-
intercept(AccessDeniedException.class,
312-
SERVICE_AMAZON_S3_STATUS_CODE_403,
313-
() -> fsKeyB.listStatus(fileToStat));
314-
} else {
315-
fsKeyB.listStatus(fileToStat);
316-
}
317-
}
318-
319-
/**
320-
* Do file status probes check S3?
321-
* @param fs filesystem
322-
* @param path file path
323-
* @return true if check for a path being a file will issue a HEAD request.
324-
*/
325-
private boolean statusProbesCheckS3(S3AFileSystem fs, Path path) {
326-
return true;
277+
intercept(AccessDeniedException.class,
278+
SERVICE_AMAZON_S3_STATUS_CODE_403,
279+
() -> fsKeyB.listStatus(fileToStat));
327280
}
328281

329282
/**
@@ -334,22 +287,17 @@ private boolean statusProbesCheckS3(S3AFileSystem fs, Path path) {
334287
*/
335288
@Test
336289
public void testDeleteEncryptedObjectWithDifferentKey() throws Exception {
337-
//requireUnguardedFilesystem();
338-
Path pathABC = path("testDeleteEncryptedObjectWithDifferentKey/a/b/c/");
339290

291+
Path pathABC = new Path(methodPath(), "a/b/c/");
340292
Path pathAB = pathABC.getParent();
341293
Path pathA = pathAB.getParent();
342294
assertTrue(getFileSystem().mkdirs(pathABC));
343295
Path fileToDelete = new Path(pathABC, "filetobedeleted.txt");
344296
writeThenReadFile(fileToDelete, TEST_FILE_LEN);
345297
fsKeyB = createNewFileSystemWithSSECKey(KEY_4);
346-
if (statusProbesCheckS3(fsKeyB, fileToDelete)) {
347-
intercept(AccessDeniedException.class,
348-
SERVICE_AMAZON_S3_STATUS_CODE_403,
349-
() -> fsKeyB.delete(fileToDelete, false));
350-
} else {
351-
fsKeyB.delete(fileToDelete, false);
352-
}
298+
intercept(AccessDeniedException.class,
299+
SERVICE_AMAZON_S3_STATUS_CODE_403,
300+
() -> fsKeyB.delete(fileToDelete, false));
353301
//This is possible
354302
fsKeyB.delete(pathABC, true);
355303
fsKeyB.delete(pathAB, true);
@@ -362,7 +310,7 @@ public void testDeleteEncryptedObjectWithDifferentKey() throws Exception {
362310
*/
363311
@Test
364312
public void testChecksumRequiresReadAccess() throws Throwable {
365-
Path path = path("tagged-file");
313+
Path path = methodPath();
366314
S3AFileSystem fs = getFileSystem();
367315
touch(fs, path);
368316
Assertions.assertThat(fs.getFileChecksum(path))

0 commit comments

Comments
 (0)