Skip to content

Commit b2a57ee

Browse files
author
fanshilun
committed
HADOOP-19415. Fix CheckStyle & UnitTest.
1 parent 3541390 commit b2a57ee

File tree

42 files changed

+367
-221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+367
-221
lines changed

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractFSContractTestBase.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
import org.apache.hadoop.fs.FileSystem;
2424
import org.apache.hadoop.fs.Path;
2525
import org.apache.hadoop.fs.extend.TestName;
26-
import org.junit.jupiter.api.*;
26+
import org.junit.jupiter.api.AfterEach;
27+
import org.junit.jupiter.api.Assertions;
28+
import org.junit.jupiter.api.BeforeAll;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Timeout;
2731
import org.junit.AssumptionViolatedException;
2832
import org.junit.jupiter.api.extension.RegisterExtension;
2933
import org.slf4j.Logger;
Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
118
package org.apache.hadoop.fs.extend;
219

320
import org.junit.jupiter.api.extension.BeforeEachCallback;
421
import org.junit.jupiter.api.extension.ExtensionContext;
522

23+
/**
24+
* This is a custom JUnit5 `RegisterExtension`
25+
* we created to obtain the methond name of the executing function.
26+
*/
627
public class TestName implements BeforeEachCallback {
728

8-
private volatile String name;
29+
private volatile String name;
930

10-
@Override
11-
public void beforeEach(ExtensionContext extensionContext) throws Exception {
12-
name = extensionContext.getTestMethod().get().getName();
13-
}
31+
@Override
32+
public void beforeEach(ExtensionContext extensionContext) throws Exception {
33+
name = extensionContext.getTestMethod().get().getName();
34+
}
1435

15-
public String getMethodName() {
16-
return this.name;
17-
}
36+
public String getMethodName() {
37+
return this.name;
38+
}
1839
}

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/lib/output/committer/manifest/AbstractManifestCommitterTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import org.assertj.core.api.Assertions;
3939
import org.junit.jupiter.api.AfterAll;
40+
import org.junit.jupiter.api.BeforeEach;
4041
import org.slf4j.Logger;
4142
import org.slf4j.LoggerFactory;
4243

@@ -309,6 +310,7 @@ protected Configuration createConfiguration() {
309310
return enableManifestCommitter(super.createConfiguration());
310311
}
311312

313+
@BeforeEach
312314
@Override
313315
public void setup() throws Exception {
314316

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.apache.hadoop.io.IOUtils;
3333

3434
import org.junit.jupiter.api.AfterAll;
35-
import org.junit.Assume;
35+
import org.junit.jupiter.api.AfterEach;
3636
import org.junit.jupiter.api.BeforeEach;
3737
import org.slf4j.Logger;
3838
import org.slf4j.LoggerFactory;
@@ -44,6 +44,7 @@
4444
import static org.apache.hadoop.fs.contract.ContractTestUtils.writeDataset;
4545
import static org.apache.hadoop.fs.statistics.IOStatisticsLogging.ioStatisticsToPrettyString;
4646
import static org.apache.hadoop.fs.statistics.IOStatisticsSupport.snapshotIOStatistics;
47+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
4748

4849
/**
4950
* An extension of the contract test base set up for S3A tests.
@@ -112,6 +113,7 @@ public void setup() throws Exception {
112113
IOStatisticsContext.getCurrentIOStatisticsContext().reset();
113114
}
114115

116+
@AfterEach
115117
@Override
116118
public void teardown() throws Exception {
117119
Thread.currentThread().setName("teardown");
@@ -233,8 +235,8 @@ protected AuditSpan span(AuditSpanSource source) throws IOException {
233235
* Method to assume that S3 client side encryption is disabled on a test.
234236
*/
235237
public void skipIfClientSideEncryption() {
236-
Assume.assumeTrue("Skipping test if CSE is enabled",
237-
!getFileSystem().isCSEEnabled());
238+
assumeTrue(!getFileSystem().isCSEEnabled(),
239+
"Skipping test if CSE is enabled");
238240
}
239241

240242
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.FileNotFoundException;
2222
import java.io.IOException;
2323

24+
import org.junit.jupiter.api.BeforeEach;
2425
import org.junit.jupiter.api.Test;
2526
import org.slf4j.Logger;
2627
import org.slf4j.LoggerFactory;
@@ -68,6 +69,7 @@ public Configuration createConfiguration() {
6869
return conf;
6970
}
7071

72+
@BeforeEach
7173
@Override
7274
public void setup() throws Exception {
7375
super.setup();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.IOException;
2222

23+
import org.junit.jupiter.api.BeforeEach;
2324
import org.slf4j.Logger;
2425
import org.slf4j.LoggerFactory;
2526

@@ -59,6 +60,7 @@ protected Configuration createConfiguration() {
5960
return disableCreateSession(super.createConfiguration());
6061
}
6162

63+
@BeforeEach
6264
@Override
6365
public void setup() throws Exception {
6466
super.setup();

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.concurrent.ExecutorService;
3030

3131
import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;
32+
import org.junit.jupiter.api.BeforeEach;
3233
import org.junit.jupiter.api.Test;
3334
import org.slf4j.Logger;
3435
import org.slf4j.LoggerFactory;
@@ -116,14 +117,14 @@ protected String getDelegationBinding() {
116117
return DELEGATION_TOKEN_SESSION_BINDING;
117118
}
118119

120+
@BeforeEach
119121
@Override
120122
public void setup() throws Exception {
121123
super.setup();
122124
assumeSessionTestsEnabled(getConfiguration());
123125
S3AFileSystem fileSystem = getFileSystem();
124-
assertNotNull(
125-
126-
fileSystem.getCanonicalServiceName(), "No delegation tokens in FS");
126+
assertNotNull(fileSystem.getCanonicalServiceName(),
127+
"No delegation tokens in FS");
127128
dataDir = GenericTestUtils.getTestDir("kerberos");
128129
dataDir.mkdirs();
129130
}

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
import java.util.Collection;
2222

2323
import org.junit.jupiter.api.AfterAll;
24+
import org.junit.jupiter.api.AfterEach;
2425
import org.junit.jupiter.api.BeforeAll;
25-
import org.junit.jupiter.api.Test;
26-
import org.junit.runner.RunWith;
27-
import org.junit.runners.Parameterized;
26+
import org.junit.jupiter.params.ParameterizedTest;
27+
import org.junit.jupiter.params.provider.MethodSource;
2828
import org.slf4j.Logger;
2929
import org.slf4j.LoggerFactory;
3030

@@ -86,7 +86,6 @@
8686
* This is needed to verify that job resources have their tokens extracted
8787
* too.
8888
*/
89-
@RunWith(Parameterized.class)
9089
public class ITestDelegatedMRJob extends AbstractDelegationIT {
9190

9291
private static final Logger LOG =
@@ -98,11 +97,11 @@ public class ITestDelegatedMRJob extends AbstractDelegationIT {
9897
@SuppressWarnings("StaticNonFinalField")
9998
private static MiniKerberizedHadoopCluster cluster;
10099

101-
private final String name;
100+
private String name;
102101

103-
private final String tokenBinding;
102+
private String tokenBinding;
104103

105-
private final Text tokenKind;
104+
private Text tokenKind;
106105

107106
/**
108107
* Created in test setup.
@@ -127,7 +126,6 @@ public class ITestDelegatedMRJob extends AbstractDelegationIT {
127126
* Test array for parameterized test runs.
128127
* @return a list of parameter tuples.
129128
*/
130-
@Parameterized.Parameters
131129
public static Collection<Object[]> params() {
132130
return Arrays.asList(new Object[][]{
133131
{"session", DELEGATION_TOKEN_SESSION_BINDING, SESSION_TOKEN_KIND},
@@ -136,10 +134,12 @@ public static Collection<Object[]> params() {
136134
});
137135
}
138136

139-
public ITestDelegatedMRJob(String name, String tokenBinding, Text tokenKind) {
140-
this.name = name;
141-
this.tokenBinding = tokenBinding;
142-
this.tokenKind = tokenKind;
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();
143143
}
144144

145145
/***
@@ -213,6 +213,7 @@ public void setup() throws Exception {
213213

214214
}
215215

216+
@AfterEach
216217
@Override
217218
public void teardown() throws Exception {
218219
describe("Teardown operations");
@@ -241,17 +242,23 @@ protected int getTestTimeoutMillis() {
241242
return getTestTimeoutSeconds() * 1000;
242243
}
243244

244-
@Test
245-
public void testCommonCrawlLookup() throws Throwable {
245+
@MethodSource("params")
246+
@ParameterizedTest
247+
public void testCommonCrawlLookup(String pName, String pTokenBinding,
248+
Text pTokenKind) throws Throwable {
249+
initITestDelegatedMRJob(pName, pTokenBinding, pTokenKind);
246250
FileSystem resourceFS = extraJobResourcePath.getFileSystem(
247251
getConfiguration());
248252
FileStatus status = resourceFS.getFileStatus(extraJobResourcePath);
249253
LOG.info("Extra job resource is {}", status);
250254
assertTrue(status.isEncrypted(), "Not encrypted: " + status);
251255
}
252256

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.apache.hadoop.fs.s3a.S3AFileSystem;
2424
import org.apache.hadoop.io.Text;
25+
import org.junit.jupiter.api.BeforeEach;
2526

2627
import static org.apache.hadoop.fs.s3a.auth.RoleTestUtils.probeForAssumedRoleARN;
2728
import static org.apache.hadoop.fs.s3a.auth.delegation.DelegationConstants.DELEGATION_TOKEN_ROLE_BINDING;
@@ -35,6 +36,7 @@
3536
public class ITestRoleDelegationInFilesystem extends
3637
ITestSessionDelegationInFilesystem {
3738

39+
@BeforeEach
3840
@Override
3941
public void setup() throws Exception {
4042
super.setup();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.EnumSet;
2222
import java.util.List;
2323

24+
import org.junit.jupiter.api.BeforeEach;
2425
import org.junit.jupiter.api.Test;
2526
import org.slf4j.Logger;
2627
import org.slf4j.LoggerFactory;
@@ -56,6 +57,7 @@ public Text getTokenKind() {
5657
return ROLE_TOKEN_KIND;
5758
}
5859

60+
@BeforeEach
5961
@Override
6062
public void setup() throws Exception {
6163
super.setup();

0 commit comments

Comments
 (0)