Skip to content

Commit b2d347f

Browse files
committed
HADOOP-19610. S3A: ITests to run under JUnit5: many more tests
A lot more. Nothing which brings up a YARN cluster works; not worrying about that now.
1 parent 2444ec7 commit b2d347f

File tree

7 files changed

+170
-237
lines changed

7 files changed

+170
-237
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import java.util.concurrent.atomic.AtomicInteger;
2929

3030
import org.junit.jupiter.api.AfterEach;
31-
import org.junit.jupiter.params.ParameterizedTest;
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.params.ParameterizedClass;
3234
import org.junit.jupiter.params.provider.MethodSource;
3335
import software.amazon.awssdk.auth.signer.Aws4Signer;
3436
import software.amazon.awssdk.auth.signer.AwsS3V4Signer;
@@ -65,6 +67,8 @@
6567
* Because the v2 sdk has had some problems with bulk delete
6668
* and custom signing, this suite is parameterized.
6769
*/
70+
@ParameterizedClass(name="bulk-delete={0}")
71+
@MethodSource("params")
6872
public class ITestCustomSigner extends AbstractS3ATestBase {
6973

7074
private static final Logger LOG = LoggerFactory
@@ -83,7 +87,7 @@ public static Collection<Object[]> params() {
8387
});
8488
}
8589

86-
private boolean bulkDelete;
90+
private final boolean bulkDelete;
8791

8892
private final UserGroupInformation ugi1 = UserGroupInformation.createRemoteUser("user1");
8993

@@ -93,14 +97,14 @@ public static Collection<Object[]> params() {
9397

9498
private String endpoint;
9599

96-
public void initITestCustomSigner(
100+
public ITestCustomSigner(
97101
final String ignored,
98-
final boolean pBulkDelete) throws Exception {
99-
this.bulkDelete = pBulkDelete;
100-
setup();
102+
final boolean bulkDelete) {
103+
this.bulkDelete = bulkDelete;
101104
}
102105

103106
@Override
107+
@BeforeEach
104108
public void setup() throws Exception {
105109
super.setup();
106110
final S3AFileSystem fs = getFileSystem();
@@ -127,11 +131,10 @@ public void teardown() throws Exception {
127131
FileSystem.closeAllForUGI(ugi2);
128132
}
129133

130-
@MethodSource("params")
131-
@ParameterizedTest(name = "{0}")
132-
public void testCustomSignerAndInitializer(final String ignored,
133-
final boolean pBulkDelete) throws Exception {
134-
initITestCustomSigner(ignored, pBulkDelete);
134+
@Test
135+
public void testCustomSignerAndInitializer()
136+
throws IOException, InterruptedException {
137+
135138
final Path basePath = path(getMethodName());
136139
FileSystem fs1 = runStoreOperationsAndVerify(ugi1,
137140
new Path(basePath, "customsignerpath1"), "id1");

hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/auth/delegation/ITestDelegatedMRJob.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import org.junit.jupiter.api.AfterAll;
2424
import org.junit.jupiter.api.AfterEach;
2525
import org.junit.jupiter.api.BeforeAll;
26-
import org.junit.jupiter.params.ParameterizedTest;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
28+
import org.junit.jupiter.params.ParameterizedClass;
2729
import org.junit.jupiter.params.provider.MethodSource;
2830
import org.slf4j.Logger;
2931
import org.slf4j.LoggerFactory;
@@ -86,6 +88,8 @@
8688
* This is needed to verify that job resources have their tokens extracted
8789
* too.
8890
*/
91+
@ParameterizedClass(name="token={0}")
92+
@MethodSource("params")
8993
public class ITestDelegatedMRJob extends AbstractDelegationIT {
9094

9195
private static final Logger LOG =
@@ -97,11 +101,11 @@ public class ITestDelegatedMRJob extends AbstractDelegationIT {
97101
@SuppressWarnings("StaticNonFinalField")
98102
private static MiniKerberizedHadoopCluster cluster;
99103

100-
private String name;
104+
private final String name;
101105

102-
private String tokenBinding;
106+
private final String tokenBinding;
103107

104-
private Text tokenKind;
108+
private final Text tokenKind;
105109

106110
/**
107111
* Created in test setup.
@@ -134,12 +138,10 @@ public static Collection<Object[]> params() {
134138
});
135139
}
136140

137-
public void initITestDelegatedMRJob(String pName, String pTokenBinding, Text pTokenKind)
138-
throws Exception {
139-
this.name = pName;
140-
this.tokenBinding = pTokenBinding;
141-
this.tokenKind = pTokenKind;
142-
setup();
141+
public ITestDelegatedMRJob(String name, String tokenBinding, Text tokenKind) {
142+
this.name = name;
143+
this.tokenBinding = tokenBinding;
144+
this.tokenKind = tokenKind;
143145
}
144146

145147
/***
@@ -191,6 +193,7 @@ protected YarnConfiguration getConfiguration() {
191193
}
192194

193195
@Override
196+
@BeforeEach
194197
public void setup() throws Exception {
195198
cluster.loginPrincipal();
196199
super.setup();
@@ -242,23 +245,17 @@ protected int getTestTimeoutMillis() {
242245
return getTestTimeoutSeconds() * 1000;
243246
}
244247

245-
@MethodSource("params")
246-
@ParameterizedTest
247-
public void testCommonCrawlLookup(String pName, String pTokenBinding,
248-
Text pTokenKind) throws Throwable {
249-
initITestDelegatedMRJob(pName, pTokenBinding, pTokenKind);
248+
@Test
249+
public void testCommonCrawlLookup() throws Throwable {
250250
FileSystem resourceFS = extraJobResourcePath.getFileSystem(
251251
getConfiguration());
252252
FileStatus status = resourceFS.getFileStatus(extraJobResourcePath);
253253
LOG.info("Extra job resource is {}", status);
254254
assertTrue(status.isEncrypted(), "Not encrypted: " + status);
255255
}
256256

257-
@MethodSource("params")
258-
@ParameterizedTest
259-
public void testJobSubmissionCollectsTokens(String pName, String pTokenBinding,
260-
Text pTokenKind) throws Exception {
261-
initITestDelegatedMRJob(pName, pTokenBinding, pTokenKind);
257+
@Test
258+
public void testJobSubmissionCollectsTokens() throws Exception {
262259
describe("Mock Job test");
263260
JobConf conf = new JobConf(getConfiguration());
264261
if (isUsingDefaultExternalDataFile(conf)) {

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

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

25-
import org.junit.jupiter.params.ParameterizedTest;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.params.ParameterizedClass;
2628
import org.junit.jupiter.params.provider.MethodSource;
2729
import org.slf4j.Logger;
2830
import org.slf4j.LoggerFactory;
@@ -53,9 +55,13 @@
5355
/**
5456
* Tests for the committer factory creation/override process.
5557
*/
58+
@ParameterizedClass(name="committer={3}")
59+
@MethodSource("params")
5660
public final class ITestS3ACommitterFactory extends AbstractCommitITest {
61+
5762
private static final Logger LOG = LoggerFactory.getLogger(
5863
ITestS3ACommitterFactory.class);
64+
5965
/**
6066
* Name for invalid committer: {@value}.
6167
*/
@@ -114,18 +120,18 @@ public static Collection<Object[]> params() {
114120
/**
115121
* Name of committer to set in filesystem config. If "" do not set one.
116122
*/
117-
private String fsCommitterName;
123+
private final String fsCommitterName;
118124

119125
/**
120126
* Name of committer to set in job config.
121127
*/
122-
private String jobCommitterName;
128+
private final String jobCommitterName;
123129

124130
/**
125131
* Expected committer class.
126132
* If null: an exception is expected
127133
*/
128-
private Class<? extends AbstractS3ACommitter> committerClass;
134+
private final Class<? extends AbstractS3ACommitter> committerClass;
129135

130136
/**
131137
* Description from parameters, simply for thread names to be more informative.
@@ -134,21 +140,20 @@ public static Collection<Object[]> params() {
134140

135141
/**
136142
* Create a parameterized instance.
137-
* @param pFsCommitterName committer to set in filesystem config
138-
* @param pJobCommitterName committer to set in job config
139-
* @param pCommitterClass expected committer class
140-
* @param pDescription debug text for thread names.
143+
* @param fsCommitterName committer to set in filesystem config
144+
* @param jobCommitterName committer to set in job config
145+
* @param committerClass expected committer class
146+
* @param description debug text for thread names.
141147
*/
142-
public void initITestS3ACommitterFactory(
143-
final String pFsCommitterName,
144-
final String pJobCommitterName,
145-
final Class<? extends AbstractS3ACommitter> pCommitterClass,
146-
final String pDescription) throws Exception {
147-
this.fsCommitterName = pFsCommitterName;
148-
this.jobCommitterName = pJobCommitterName;
149-
this.committerClass = pCommitterClass;
150-
this.description = pDescription;
151-
setup();
148+
public ITestS3ACommitterFactory(
149+
final String fsCommitterName,
150+
final String jobCommitterName,
151+
final Class<? extends AbstractS3ACommitter> committerClass,
152+
final String description) {
153+
this.fsCommitterName = fsCommitterName;
154+
this.jobCommitterName = jobCommitterName;
155+
this.committerClass = committerClass;
156+
this.description = description;
152157
}
153158

154159
@Override
@@ -176,6 +181,7 @@ private static void maybeSetCommitterName(final Configuration conf, final String
176181
}
177182

178183
@Override
184+
@BeforeEach
179185
public void setup() throws Exception {
180186
// destroy all filesystems from previous runs.
181187
FileSystem.closeAllForUGI(UserGroupInformation.getCurrentUser());
@@ -210,14 +216,8 @@ protected void deleteTestDirInTeardown() {
210216
* Verify that if all config options are unset, the FileOutputCommitter
211217
* is returned.
212218
*/
213-
@MethodSource("params")
214-
@ParameterizedTest(name = "{3}-fs=[{0}]-task=[{1}]-[{2}]")
215-
public void testBinding(String pFsCommitterName,
216-
String pJobCommitterName,
217-
Class<? extends AbstractS3ACommitter> pCommitterClass,
218-
String pDescription) throws Throwable {
219-
initITestS3ACommitterFactory(pFsCommitterName, pJobCommitterName, pCommitterClass,
220-
pDescription);
219+
@Test
220+
public void testBinding() throws Throwable {
221221
assertFactoryCreatesExpectedCommitter(committerClass);
222222
}
223223

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
import org.assertj.core.api.Assumptions;
3030
import org.junit.jupiter.api.AfterEach;
3131
import org.junit.jupiter.api.BeforeEach;
32-
import org.junit.jupiter.params.ParameterizedTest;
32+
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.params.ParameterizedClass;
3334
import org.junit.jupiter.params.provider.MethodSource;
3435
import org.slf4j.Logger;
3536
import org.slf4j.LoggerFactory;
@@ -68,14 +69,16 @@
6869
* Test upload recovery by injecting failures into the response chain.
6970
* The tests are parameterized on upload buffering.
7071
* <p>
71-
* The test case {@link #testCommitOperations(String, boolean)} is independent of this option;
72+
* The test case {@link #testCommitOperations()} is independent of this option;
7273
* the test parameterization only runs this once.
7374
* A bit inelegant but as the fault injection code is shared and the problem "adjacent"
7475
* this isolates all forms of upload recovery into the same test class without
7576
* wasting time with duplicate uploads.
7677
* <p>
7778
* Fault injection is implemented in {@link SdkFaultInjector}.
7879
*/
80+
@ParameterizedClass(name="buffer={0}-commit-test={1}")
81+
@MethodSource("params")
7982
public class ITestUploadRecovery extends AbstractS3ACostTest {
8083

8184
private static final Logger LOG =
@@ -102,22 +105,21 @@ public static Collection<Object[]> params() {
102105
/**
103106
* should the commit test be included?
104107
*/
105-
private boolean includeCommitTest;
108+
private final boolean includeCommitTest;
106109

107110
/**
108111
* Buffer type for this test run.
109112
*/
110-
private String buffer;
113+
private final String buffer;
111114

112115
/**
113116
* Parameterized test suite.
114-
* @param pBuffer buffer type
115-
* @param pIncludeCommitTest should the commit upload test be included?
117+
* @param buffer buffer type
118+
* @param includeCommitTest should the commit upload test be included?
116119
*/
117-
public void initITestUploadRecovery(final String pBuffer,
118-
final boolean pIncludeCommitTest) {
119-
this.includeCommitTest = pIncludeCommitTest;
120-
this.buffer = pBuffer;
120+
public ITestUploadRecovery(final String buffer, final boolean includeCommitTest) {
121+
this.includeCommitTest = includeCommitTest;
122+
this.buffer = buffer;
121123
}
122124

123125
@Override
@@ -172,11 +174,8 @@ public void teardown() throws Exception {
172174
/**
173175
* Verify that failures of simple PUT requests can be recovered from.
174176
*/
175-
@MethodSource("params")
176-
@ParameterizedTest(name = "{0}-commit-{1}")
177-
public void testPutRecovery(String pBuffer,
178-
boolean pIncludeCommitTest) throws Throwable {
179-
initITestUploadRecovery(pBuffer, pIncludeCommitTest);
177+
@Test
178+
public void testPutRecovery() throws Throwable {
180179
describe("test put recovery");
181180
final S3AFileSystem fs = getFileSystem();
182181
final Path path = methodPath();
@@ -192,11 +191,8 @@ public void testPutRecovery(String pBuffer,
192191
/**
193192
* Validate recovery of multipart uploads within a magic write sequence.
194193
*/
195-
@MethodSource("params")
196-
@ParameterizedTest(name = "{0}-commit-{1}")
197-
public void testMagicWriteRecovery(String pBuffer,
198-
boolean pIncludeCommitTest) throws Throwable {
199-
initITestUploadRecovery(pBuffer, pIncludeCommitTest);
194+
@Test
195+
public void testMagicWriteRecovery() throws Throwable {
200196
describe("test magic write recovery with multipart uploads");
201197
final S3AFileSystem fs = getFileSystem();
202198

@@ -235,11 +231,8 @@ public void testMagicWriteRecovery(String pBuffer,
235231
/**
236232
* Test the commit operations iff {@link #includeCommitTest} is true.
237233
*/
238-
@MethodSource("params")
239-
@ParameterizedTest(name = "{0}-commit-{1}")
240-
public void testCommitOperations(String pBuffer,
241-
boolean pIncludeCommitTest) throws Throwable {
242-
initITestUploadRecovery(pBuffer, pIncludeCommitTest);
234+
@Test
235+
public void testCommitOperations() throws Throwable {
243236
skipIfClientSideEncryption();
244237
Assumptions.assumeThat(includeCommitTest)
245238
.describedAs("commit test excluded")

0 commit comments

Comments
 (0)