Skip to content

Commit c1c72d9

Browse files
author
Bhavay Pahuja
committed
Optmize ITestS3AReadRestoredGlacierObjects to reduce setup time and other minor changes
1 parent c152dc2 commit c1c72d9

File tree

3 files changed

+72
-65
lines changed

3 files changed

+72
-65
lines changed

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/api/S3ObjectStorageClassFilter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import software.amazon.awssdk.services.s3.model.S3Object;
2626

2727
import org.apache.hadoop.fs.s3a.S3AFileSystem;
28-
import org.apache.hadoop.thirdparty.com.google.common.collect.Sets;
28+
import org.apache.hadoop.util.Sets;
2929

3030

3131
/**
@@ -86,6 +86,10 @@ private static boolean isCompletedRestoredObject(S3Object object) {
8686
return true;
8787
}
8888

89+
/**
90+
* Returns the filter function set as part of the enum definition
91+
* @return the filter function set as part of the enum definition
92+
*/
8993
public Function<S3Object, Boolean> getFilter() {
9094
return filter;
9195
}

hadoop-tools/hadoop-aws/src/site/markdown/tools/hadoop-aws/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ The switch to turn S3A auditing on or off.
932932

933933
[Amazon S3 Glacier (S3 Glacier)](https://docs.aws.amazon.com/amazonglacier/latest/dev/introduction.html) is a secure and durable service for low-cost data archiving and
934934
long-term backup.
935-
With S3 Glacier, you can store your data cost effectively for months, years, or even decades.
935+
With S3 Glacier, it is possible to store data more cost-effectively for months, years, or even decades.
936936
This support introduces a new config, which decides the objects returned from listStatus.
937937
Note : This is not available on all AWS S3 store types, or on third party stores.
938938

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

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Arrays;
2323
import java.util.Collection;
2424

25+
import org.apache.hadoop.fs.s3a.S3AFileSystem;
2526
import org.assertj.core.api.Assertions;
2627
import org.junit.Assume;
2728
import org.junit.Test;
@@ -64,34 +65,32 @@ enum Type { GLACIER_AND_DEEP_ARCHIVE, GLACIER }
6465
@Parameterized.Parameters(name = "storage-class-{1}")
6566
public static Collection<Object[]> data(){
6667
return Arrays.asList(new Object[][] {
67-
{Type.GLACIER_AND_DEEP_ARCHIVE, STORAGE_CLASS_GLACIER},
68-
{Type.GLACIER_AND_DEEP_ARCHIVE, STORAGE_CLASS_DEEP_ARCHIVE},
69-
{Type.GLACIER, STORAGE_CLASS_GLACIER}
68+
{STORAGE_CLASS_GLACIER}, {STORAGE_CLASS_DEEP_ARCHIVE},
7069
});
7170
}
7271

73-
private final int maxRetries = 100;
74-
private final int retryDelayMs = 5000;
75-
76-
private final Type type;
72+
private static final int MAX_RETRIES = 100;
73+
private static final int RETRY_DELAY_MS = 5000;
7774
private final String glacierClass;
7875

79-
public ITestS3AReadRestoredGlacierObjects(Type type, String glacierClass) {
80-
this.type = type;
76+
public ITestS3AReadRestoredGlacierObjects(String glacierClass) {
8177
this.glacierClass = glacierClass;
8278
}
8379

8480
private FileSystem createFiles(String s3ObjectStorageClassFilter) throws Throwable {
85-
Configuration conf = this.createConfiguration();
81+
FileSystem fs = createFileSystem(s3ObjectStorageClassFilter);
82+
Path path = new Path(methodPath(), "glaciated");
83+
ContractTestUtils.touch(fs, path);
84+
return fs;
85+
}
86+
87+
private FileSystem createFileSystem(String s3ObjectStorageClassFilter) throws Throwable {
88+
Configuration conf = createConfiguration();
8689
conf.set(READ_RESTORED_GLACIER_OBJECTS, s3ObjectStorageClassFilter);
8790
// Create Glacier objects:Storage Class:DEEP_ARCHIVE/GLACIER
8891
conf.set(STORAGE_CLASS, glacierClass);
89-
S3AContract contract = (S3AContract) createContract(conf);
90-
contract.init();
91-
92-
FileSystem fs = contract.getTestFileSystem();
93-
Path path = new Path(methodPath(), "glaciated");
94-
ContractTestUtils.touch(fs, path);
92+
FileSystem fs = new S3AFileSystem();
93+
fs.initialize(getFileSystem().getUri(), conf);
9594
return fs;
9695
}
9796

@@ -105,62 +104,65 @@ protected Configuration createConfiguration() {
105104
}
106105

107106
@Test
108-
public void testConfigWithInvalidValue() throws Throwable {
109-
Assume.assumeTrue(type == Type.GLACIER_AND_DEEP_ARCHIVE);
110-
String invalidValue = "ABCDE";
111-
try (FileSystem fs = createFiles(invalidValue)) {
112-
Assertions.assertThat(
113-
fs.listStatus(methodPath()))
114-
.describedAs("FileStatus List of %s", methodPath()).isNotEmpty();
115-
}
116-
}
107+
public void testAllGlacierAndDeepArchiveCases() throws Throwable {
117108

118-
@Test
119-
public void testIgnoreGlacierObject() throws Throwable {
120-
Assume.assumeTrue(type == Type.GLACIER_AND_DEEP_ARCHIVE);
121109
try (FileSystem fs = createFiles(S3ObjectStorageClassFilter.SKIP_ALL_GLACIER.name())) {
122-
Assertions.assertThat(
123-
fs.listStatus(methodPath()))
124-
.describedAs("FileStatus List of %s", methodPath()).isEmpty();
125-
}
126-
}
127-
128-
@Test
129-
public void testIgnoreRestoringGlacierObject() throws Throwable {
130-
Assume.assumeTrue(type == Type.GLACIER_AND_DEEP_ARCHIVE);
131-
try (FileSystem fs = createFiles(S3ObjectStorageClassFilter.READ_RESTORED_GLACIER_OBJECTS.name())) {
132-
Assertions.assertThat(
133-
fs.listStatus(
134-
methodPath()))
135-
.describedAs("FileStatus List of %s", methodPath()).isEmpty();
136-
}
137-
}
138110

139-
@Test
140-
public void testRestoredGlacierObject() throws Throwable {
141-
// Skipping this test for Deep Archive as expedited retrieval is not supported
142-
Assume.assumeTrue(type == Type.GLACIER);
143-
try (FileSystem fs = createFiles(S3ObjectStorageClassFilter.READ_RESTORED_GLACIER_OBJECTS.name())) {
144-
restoreGlacierObject(getFilePrefixForListObjects(), 2);
111+
// testIgnoreGlacierObject
112+
describe("Running testIgnoreGlacierObject");
145113
Assertions.assertThat(
146-
fs.listStatus(
147-
methodPath()))
148-
.describedAs("FileStatus List of %s", methodPath()).isNotEmpty();
149-
}
150-
}
114+
fs.listStatus(methodPath()))
115+
.describedAs("FileStatus List of %s", methodPath())
116+
.isEmpty();
117+
118+
// testReadAllObjects
119+
describe("Running testReadAllObjects");
120+
try (FileSystem fsTest = createFileSystem(S3ObjectStorageClassFilter.READ_ALL.name())) {
121+
Assertions.assertThat(
122+
fsTest.listStatus(methodPath()))
123+
.describedAs("FileStatus List of %s", methodPath())
124+
.isNotEmpty();
125+
}
126+
127+
// testIgnoreRestoringGlacierObject
128+
describe("Running testIgnoreRestoringGlacierObject");
129+
try (FileSystem fsTest = createFileSystem(S3ObjectStorageClassFilter.READ_RESTORED_GLACIER_OBJECTS.name())) {
130+
Assertions.assertThat(
131+
fsTest.listStatus(methodPath()))
132+
.describedAs("FileStatus List of %s", methodPath())
133+
.isEmpty();
134+
}
135+
136+
// testConfigWithInvalidValue
137+
describe("Running testConfigWithInvalidValue");
138+
String invalidValue = "ABCDE";
139+
try (FileSystem fsTest = createFiles(invalidValue)) {
140+
Assertions.assertThat(
141+
fsTest.listStatus(methodPath()))
142+
.describedAs("FileStatus List of %s", methodPath())
143+
.isNotEmpty();
144+
}
145+
146+
147+
// testRestoredGlacierObject - run only for Glacier Storage Class
148+
if ( glacierClass == STORAGE_CLASS_GLACIER ) {
149+
describe("Running testRestoredGlacierObject");
150+
try (FileSystem fsTest = createFileSystem(S3ObjectStorageClassFilter.READ_RESTORED_GLACIER_OBJECTS.name())) {
151+
restoreGlacierObject(getFilePrefixForListObjects(), 2);
152+
Assertions.assertThat(
153+
fsTest.listStatus(methodPath()))
154+
.describedAs("FileStatus List of %s", methodPath())
155+
.isNotEmpty();
156+
}
157+
158+
}
151159

152-
@Test
153-
public void testReadAllObjects() throws Throwable {
154-
Assume.assumeTrue(type == Type.GLACIER_AND_DEEP_ARCHIVE);
155-
try (FileSystem fs = createFiles(S3ObjectStorageClassFilter.READ_ALL.name())) {
156-
Assertions.assertThat(
157-
fs.listStatus(methodPath()))
158-
.describedAs("FileStatus List of %s", methodPath()).isNotEmpty();
159160
}
160161
}
161162

162163

163164
private void restoreGlacierObject(String glacierObjectKey, int expirationDays) throws Exception {
165+
describe("Initiate restore of the Glacier object");
164166
try (AuditSpan auditSpan = getSpanSource().createSpan(OBJECT_LIST_REQUEST, "", "").activate()) {
165167

166168
S3Client s3Client = getFileSystem().getS3AInternals().getAmazonS3Client("test");
@@ -175,7 +177,8 @@ private void restoreGlacierObject(String glacierObjectKey, int expirationDays) t
175177
S3ListRequest s3ListRequest = getFileSystem().createListObjectsRequest(
176178
getFilePrefixForListObjects(), "/");
177179

178-
LambdaTestUtils.await(maxRetries * retryDelayMs, retryDelayMs,
180+
describe("Wait till restore of the object is complete");
181+
LambdaTestUtils.await(MAX_RETRIES * RETRY_DELAY_MS, RETRY_DELAY_MS,
179182
() -> !getS3GlacierObject(s3Client, s3ListRequest).restoreStatus().isRestoreInProgress());
180183
}
181184
}

0 commit comments

Comments
 (0)