Skip to content

Commit b52214a

Browse files
author
fanshilun
committed
HADOOP-19425. Fix CheckStyle & Junit Test.
1 parent a44ce7d commit b52214a

File tree

42 files changed

+755
-748
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

+755
-748
lines changed

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/AbstractWasbTestBase.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.hadoop.conf.Configuration;
2424
import org.junit.jupiter.api.AfterEach;
2525
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.TestInfo;
2627
import org.slf4j.Logger;
2728
import org.slf4j.LoggerFactory;
2829

@@ -50,15 +51,15 @@ public abstract class AbstractWasbTestBase extends AbstractWasbTestWithTimeout
5051
protected AzureBlobStorageTestAccount testAccount;
5152

5253
@BeforeEach
53-
public void setUp() throws Exception {
54+
public void setUp(TestInfo testInfo) throws Exception {
5455
AzureBlobStorageTestAccount account = createTestAccount();
5556
assumeNotNull("test account", account);
5657
bindToTestAccount(account);
5758
}
5859

5960
@AfterEach
60-
public void tearDown() throws Exception {
61-
describe("closing test account and filesystem");
61+
public void tearDown(TestInfo info) throws Exception {
62+
describe(info,"closing test account and filesystem");
6263
testAccount = cleanupTestAccount(testAccount);
6364
IOUtils.closeStream(fs);
6465
fs = null;
@@ -146,31 +147,37 @@ protected Path path(String filepath) throws IOException {
146147
/**
147148
* Return a path bonded to this method name, unique to this fork during
148149
* parallel execution.
150+
* @param testInfo Provides information about the currently executing test method.
151+
* This can include details such as the name of the test method, display name.
149152
* @return a method name unique to (fork, method).
150153
* @throws IOException IO problems
151154
*/
152-
protected Path methodPath() throws IOException {
153-
return path(methodName.getMethodName());
155+
protected Path methodPath(TestInfo testInfo) throws IOException {
156+
return path(testInfo.getDisplayName());
154157
}
155158

156159
/**
157160
* Return a blob path bonded to this method name, unique to this fork during
158161
* parallel execution.
162+
* @param testInfo Provides information about the currently executing test method.
163+
* This can include details such as the name of the test method, display name.
159164
* @return a method name unique to (fork, method).
160165
* @throws IOException IO problems
161166
*/
162-
protected Path methodBlobPath() throws IOException {
163-
return blobPath(methodName.getMethodName());
167+
protected Path methodBlobPath(TestInfo testInfo) throws IOException {
168+
return blobPath(testInfo.getDisplayName());
164169
}
165170

166171
/**
167172
* Describe a test in the logs.
173+
* @param testInfo Provides information about the currently executing test method.
174+
* This can include details such as the name of the test method, display name.
168175
* @param text text to print
169176
* @param args arguments to format in the printing
170177
*/
171-
protected void describe(String text, Object... args) {
178+
protected void describe(TestInfo testInfo, String text, Object... args) {
172179
LOG.info("\n\n{}: {}\n",
173-
methodName.getMethodName(),
180+
testInfo.getDisplayName(),
174181
String.format(text, args));
175182
}
176183
}

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/AbstractWasbTestWithTimeout.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,20 @@
1919
package org.apache.hadoop.fs.azure;
2020

2121
import org.junit.jupiter.api.Assertions;
22-
import org.junit.jupiter.api.BeforeEach;
2322
import org.junit.jupiter.api.BeforeAll;
24-
import org.junit.Rule;
25-
import org.junit.rules.TestName;
26-
import org.junit.rules.Timeout;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.TestInfo;
25+
import org.junit.jupiter.api.Timeout;
2726

2827
import org.apache.hadoop.fs.azure.integration.AzureTestConstants;
2928

3029
/**
3130
* Base class for any Wasb test with timeouts & named threads.
3231
* This class does not attempt to bind to Azure.
3332
*/
33+
@Timeout(AzureTestConstants.AZURE_TEST_TIMEOUT)
3434
public class AbstractWasbTestWithTimeout extends Assertions {
3535

36-
/**
37-
* The name of the current method.
38-
*/
39-
@Rule
40-
public TestName methodName = new TestName();
41-
/**
42-
* Set the timeout for every test.
43-
* This is driven by the value returned by {@link #getTestTimeoutMillis()}.
44-
*/
45-
@Rule
46-
public Timeout testTimeout = new Timeout(getTestTimeoutMillis());
47-
4836
/**
4937
* Name the junit thread for the class. This will overridden
5038
* before the individual test methods are run.
@@ -58,8 +46,8 @@ public static void nameTestThread() {
5846
* Name the thread to the current test method.
5947
*/
6048
@BeforeEach
61-
public void nameThread() {
62-
Thread.currentThread().setName("JUnit-" + methodName.getMethodName());
49+
public void nameThread(TestInfo testInfo) {
50+
Thread.currentThread().setName("JUnit-" + testInfo.getDisplayName());
6351
}
6452

6553
/**

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/AzureBlobStorageTestAccount.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.microsoft.azure.storage.*;
2222
import com.microsoft.azure.storage.blob.*;
2323
import com.microsoft.azure.storage.core.Base64;
24-
import org.junit.jupiter.api.Assertions;
2524
import org.slf4j.Logger;
2625
import org.slf4j.LoggerFactory;
2726

@@ -50,6 +49,7 @@
5049
import static org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.KEY_USE_LOCAL_SAS_KEY_MODE;
5150
import static org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.KEY_USE_SECURE_MODE;
5251
import static org.apache.hadoop.fs.azure.integration.AzureTestUtils.verifyWasbAccountNameInConfig;
52+
import static org.junit.jupiter.api.Assertions.assertNotNull;
5353

5454
/**
5555
* Helper class to create WASB file systems backed by either a mock in-memory
@@ -212,9 +212,9 @@ public Number getLatestMetricValue(String metricName, Number defaultValue)
212212
* @return
213213
*/
214214
private boolean wasGeneratedByMe(MetricsRecord currentRecord) {
215-
Assertions.assertNotNull(fs, "null filesystem");
216-
Assertions.assertNotNull(
217-
fs.getInstrumentation().getFileSystemInstanceId(), "null filesystemn instance ID");
215+
assertNotNull(fs, "null filesystem");
216+
assertNotNull(fs.getInstrumentation().getFileSystemInstanceId(),
217+
"null filesystemn instance ID");
218218
String myFsId = fs.getInstrumentation().getFileSystemInstanceId().toString();
219219
for (MetricsTag currentTag : currentRecord.tags()) {
220220
if (currentTag.name().equalsIgnoreCase("wasbFileSystemId")) {

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/ITestAzureFileSystemErrorConditions.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
import static org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.NO_ACCESS_TO_CONTAINER_MSG;
4343
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
44-
import static org.junit.Assume.assumeNotNull;
44+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
4545

4646
/**
4747
* Error handling.
@@ -157,7 +157,7 @@ public void testTransientErrorOnDelete() throws Exception {
157157
// Need to do this test against a live storage account
158158
AzureBlobStorageTestAccount testAccount =
159159
AzureBlobStorageTestAccount.create();
160-
assumeNotNull(testAccount);
160+
assumeTrue(testAccount != null);
161161
try {
162162
NativeAzureFileSystem fs = testAccount.getFileSystem();
163163
injectTransientError(fs, new ConnectionRecognizer() {
@@ -200,7 +200,7 @@ public void testTransientErrorOnCommitBlockList() throws Exception {
200200
// Need to do this test against a live storage account
201201
AzureBlobStorageTestAccount testAccount =
202202
AzureBlobStorageTestAccount.create();
203-
assumeNotNull(testAccount);
203+
assumeTrue(testAccount != null);
204204
try {
205205
NativeAzureFileSystem fs = testAccount.getFileSystem();
206206
injectTransientError(fs, new ConnectionRecognizer() {
@@ -224,7 +224,7 @@ public void testTransientErrorOnRead() throws Exception {
224224
// Need to do this test against a live storage account
225225
AzureBlobStorageTestAccount testAccount =
226226
AzureBlobStorageTestAccount.create();
227-
assumeNotNull(testAccount);
227+
assumeTrue(testAccount != null);
228228
try {
229229
NativeAzureFileSystem fs = testAccount.getFileSystem();
230230
Path testFile = new Path("/a/b");

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/ITestBlobDataValidation.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import static org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.KEY_CHECK_BLOCK_MD5;
2222
import static org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.KEY_STORE_BLOB_MD5;
23-
import static org.junit.Assume.assumeNotNull;
23+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2424

2525
import java.io.ByteArrayInputStream;
2626
import java.io.IOException;
@@ -37,6 +37,7 @@
3737

3838
import org.junit.jupiter.api.AfterEach;
3939
import org.junit.jupiter.api.Test;
40+
import org.junit.jupiter.api.TestInfo;
4041

4142
import com.microsoft.azure.storage.Constants;
4243
import com.microsoft.azure.storage.OperationContext;
@@ -65,21 +66,21 @@ public void tearDown() throws Exception {
6566
* Test that by default we don't store the blob-level MD5.
6667
*/
6768
@Test
68-
public void testBlobMd5StoreOffByDefault() throws Exception {
69+
public void testBlobMd5StoreOffByDefault(TestInfo testInfo) throws Exception {
6970
testAccount = AzureBlobStorageTestAccount.create();
70-
testStoreBlobMd5(false);
71+
testStoreBlobMd5(false, testInfo);
7172
}
7273

7374
/**
7475
* Test that we get blob-level MD5 storage and validation if we specify that
7576
* in the configuration.
7677
*/
7778
@Test
78-
public void testStoreBlobMd5() throws Exception {
79+
public void testStoreBlobMd5(TestInfo testInfo) throws Exception {
7980
Configuration conf = new Configuration();
8081
conf.setBoolean(KEY_STORE_BLOB_MD5, true);
8182
testAccount = AzureBlobStorageTestAccount.create(conf);
82-
testStoreBlobMd5(true);
83+
testStoreBlobMd5(true, testInfo);
8384
}
8485

8586
/**
@@ -91,12 +92,12 @@ private static String trim(String s, String toTrim) {
9192
toTrim);
9293
}
9394

94-
private void testStoreBlobMd5(boolean expectMd5Stored) throws Exception {
95-
assumeNotNull(testAccount);
95+
private void testStoreBlobMd5(boolean expectMd5Stored, TestInfo testInfo) throws Exception {
96+
assumeTrue(testAccount != null);
9697
// Write a test file.
9798
NativeAzureFileSystem fs = testAccount.getFileSystem();
9899
Path testFilePath = AzureTestUtils.pathForTests(fs,
99-
methodName.getMethodName());
100+
testInfo.getDisplayName());
100101
String testFileKey = trim(testFilePath.toUri().getPath(), "/");
101102
OutputStream outStream = fs.create(testFilePath);
102103
outStream.write(new byte[] { 5, 15 });
@@ -211,7 +212,7 @@ private static boolean isGetRange(HttpURLConnection connection) {
211212

212213
private void testCheckBlockMd5(final boolean expectMd5Checked)
213214
throws Exception {
214-
assumeNotNull(testAccount);
215+
assumeTrue(testAccount != null);
215216
Path testFilePath = new Path("/testFile");
216217

217218
// Add a hook to check that for GET/PUT requests we set/don't set

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/ITestBlockBlobInputStream.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
import java.util.Random;
2626
import java.util.concurrent.Callable;
2727

28-
import org.junit.FixMethodOrder;
29-
import org.junit.jupiter.api.Test;
30-
import org.junit.runners.MethodSorters;
28+
import org.junit.jupiter.api.*;
3129
import org.slf4j.Logger;
3230
import org.slf4j.LoggerFactory;
3331

@@ -53,7 +51,7 @@
5351
* (KEY_INPUT_STREAM_VERSION=1) and the new
5452
* <code>BlockBlobInputStream</code> (KEY_INPUT_STREAM_VERSION=2).
5553
*/
56-
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
54+
@TestMethodOrder(MethodOrderer.Alphanumeric.class)
5755

5856
public class ITestBlockBlobInputStream extends AbstractAzureScaleTest {
5957
private static final Logger LOG = LoggerFactory.getLogger(
@@ -73,9 +71,10 @@ public class ITestBlockBlobInputStream extends AbstractAzureScaleTest {
7371
private FileStatus testFileStatus;
7472
private Path hugefile;
7573

74+
@BeforeEach
7675
@Override
77-
public void setUp() throws Exception {
78-
super.setUp();
76+
public void setUp(TestInfo testInfo) throws Exception {
77+
super.setUp(testInfo);
7978
Configuration conf = new Configuration();
8079
conf.setInt(AzureNativeFileSystemStore.KEY_INPUT_STREAM_VERSION, 1);
8180

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/ITestContainerChecks.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
package org.apache.hadoop.fs.azure;
2020

21-
import static org.junit.Assume.assumeNotNull;
21+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
22+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2223

2324
import java.io.FileNotFoundException;
2425
import java.util.EnumSet;
@@ -32,7 +33,6 @@
3233
import org.apache.hadoop.test.LambdaTestUtils;
3334

3435
import org.junit.jupiter.api.AfterEach;
35-
import org.junit.Assume;
3636
import org.junit.jupiter.api.BeforeEach;
3737
import org.junit.jupiter.api.Test;
3838

@@ -61,7 +61,7 @@ public void setMode() {
6161
@Test
6262
public void testContainerExistAfterDoesNotExist() throws Exception {
6363
testAccount = blobStorageTestAccount();
64-
assumeNotNull(testAccount);
64+
assumeTrue(testAccount != null);
6565
CloudBlobContainer container = testAccount.getRealContainer();
6666
FileSystem fs = testAccount.getFileSystem();
6767

@@ -101,7 +101,7 @@ protected AzureBlobStorageTestAccount blobStorageTestAccount()
101101
@Test
102102
public void testContainerCreateAfterDoesNotExist() throws Exception {
103103
testAccount = blobStorageTestAccount();
104-
assumeNotNull(testAccount);
104+
assumeTrue(testAccount != null);
105105
CloudBlobContainer container = testAccount.getRealContainer();
106106
FileSystem fs = testAccount.getFileSystem();
107107

@@ -127,7 +127,7 @@ public void testContainerCreateAfterDoesNotExist() throws Exception {
127127
@Test
128128
public void testContainerCreateOnWrite() throws Exception {
129129
testAccount = blobStorageTestAccount();
130-
assumeNotNull(testAccount);
130+
assumeTrue(testAccount != null);
131131
CloudBlobContainer container = testAccount.getRealContainer();
132132
FileSystem fs = testAccount.getFileSystem();
133133

@@ -170,10 +170,10 @@ public String call() throws Exception {
170170
@Test
171171
public void testContainerChecksWithSas() throws Exception {
172172

173-
Assume.assumeFalse(runningInSASMode);
173+
assumeFalse(runningInSASMode);
174174
testAccount = AzureBlobStorageTestAccount.create("",
175175
EnumSet.of(CreateOptions.UseSas));
176-
assumeNotNull(testAccount);
176+
assumeTrue(testAccount != null);
177177
CloudBlobContainer container = testAccount.getRealContainer();
178178
FileSystem fs = testAccount.getFileSystem();
179179

0 commit comments

Comments
 (0)