8000 HADOOP-19425. Upgrade JUnit from 4 to 5 in hadoop-azure Part1. · apache/hadoop@0cb509f · GitHub
[go: up one dir, main page]

Skip to content

Commit 0cb509f

Browse files
author
fanshilun
committed
HADOOP-19425. Upgrade JUnit from 4 to 5 in hadoop-azure Part1.
1 parent cfe76e4 commit 0cb509f

File tree

53 files changed

+566
-540
lines changed

Some content is hidden

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

53 files changed

+566
-540
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import java.io.IOException;
2222

2323
import org.apache.hadoop.conf.Configuration;
24-
import org.junit.After;
25-
import org.junit.Before;
24+
import org.junit.jupiter.api.AfterEach;
25+
import org.junit.jupiter.api.BeforeEach;
2626
import org.slf4j.Logger;
2727
import org.slf4j.LoggerFactory;
2828

@@ -49,14 +49,14 @@ public abstract class AbstractWasbTestBase extends AbstractWasbTestWithTimeout
4949
protected NativeAzureFileSystem fs;
5050
protected AzureBlobStorageTestAccount testAccount;
5151

52-
@Before
52+
@BeforeEach
5353
public void setUp() throws Exception {
5454
AzureBlobStorageTestAccount account = createTestAccount();
5555
assumeNotNull("test account", account);
5656
bindToTestAccount(account);
5757
}
5858

59-
@After
59+
@AfterEach
6060
public void tearDown() throws Exception {
6161
describe("closing test account and filesystem");
6262
testAccount = cleanupTestAccount(testAccount);

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

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

21-
import org.junit.Assert;
22-
import org.junit.Before;
23-
import org.junit.BeforeClass;
21+
import org.junit.jupiter.api.Assertions;
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.BeforeAll;
2424
import org.junit.Rule;
2525
import org.junit.rules.TestName;
2626
import org.junit.rules.Timeout;
@@ -31,7 +31,7 @@
3131
* Base class for any Wasb test with timeouts & named threads.
3232
* This class does not attempt to bind to Azure.
3333
*/
34-
public class AbstractWasbTestWithTimeout extends Assert {
34+
public class AbstractWasbTestWithTimeout extends Assertions {
3535

3636
/**
3737
* The name of the current method.
@@ -49,15 +49,15 @@ public class AbstractWasbTestWithTimeout extends Assert {
4949
* Name the junit thread for the class. This will overridden
5050
* before the individual test methods are run.
5151
*/
52-
@BeforeClass
52+
@BeforeAll
5353
public static void nameTestThread() {
5454
Thread.currentThread().setName("JUnit");
5555
}
5656

5757
/**
5858
* Name the thread to the current test method.
5959
*/
60-
@Before
60+
@BeforeEach
6161
public void nameThread() {
6262
Thread.currentThread().setName("JUnit-" + methodName.getMethodName());
6363
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
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.Assert;
24+
import org.junit.jupiter.api.Assertions;
2525
import org.slf4j.Logger;
2626
import org.slf4j.LoggerFactory;
2727

@@ -212,9 +212,9 @@ public Number getLatestMetricValue(String metricName, Number defaultValue)
212212
* @return
213213
*/
214214
private boolean wasGeneratedByMe(MetricsRecord currentRecord) {
215-
Assert.assertNotNull("null filesystem", fs);
216-
Assert.assertNotNull("null filesystemn instance ID",
217-
fs.getInstrumentation().getFileSystemInstanceId());
215+
Assertions.assertNotNull(fs, "null filesystem");
216+
Assertions.assertNotNull(
217+
fs.getInstrumentation().getFileSystemInstanceId(), "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/ITestAzureConcurrentOutOfBandIo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.io.OutputStream;
2424
import java.util.Arrays;
2525

26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727
import org.slf4j.Logger;
2828
import org.slf4j.LoggerFactory;
2929

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import com.microsoft.azure.storage.OperationContext;
3131
import com.microsoft.azure.storage.SendingRequestEvent;
3232
import com.microsoft.azure.storage.StorageEvent;
33-
import org.junit.Test;
33+
import org.junit.jupiter.api.Test;
3434

3535
import org.apache.hadoop.conf.Configuration;
3636
import org.apache.hadoop.fs.FileStatus;
@@ -76,7 +76,7 @@ public void testAccessUnauthorizedPublicContainer() throws Exception {
7676
try {
7777
FileSystem.get(noAccessPath.toUri(), new Configuration())
7878
.open(noAccessPath);
79-
assertTrue("Should've thrown.", false);
79+
assertTrue(false, "Should've thrown.");
8080
} catch (AzureException ex) {
8181
GenericTestUtils.assertExceptionContains(
8282
String.format(NO_ACCESS_TO_CONTAINER_MSG, account, container), ex);

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
import org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.TestHookOperationContext;
3636
import org.apache.hadoop.fs.azure.integration.AzureTestUtils;
3737

38-
import org.junit.After;
39-
import org.junit.Test;
38+
import org.junit.jupiter.api.AfterEach;
39+
import org.junit.jupiter.api.Test;
4040

4141
import com.microsoft.azure.storage.Constants;
4242
import com.microsoft.azure.storage.OperationContext;
@@ -56,7 +56,7 @@
5656
public class ITestBlobDataValidation extends AbstractWasbTestWithTimeout {
5757
private AzureBlobStorageTestAccount testAccount;
5858

59-
@After
59+
@AfterEach
6060
public void tearDown() throws Exception {
6161
testAccount = AzureTestUtils.cleanupTestAccount(testAccount);
6262
}
@@ -109,7 +109,7 @@ private void testStoreBlobMd5(boolean expectMd5Stored) throws Exception {
109109
if (expectMd5Stored) {
110110
assertNotNull(obtainedMd5);
111111
} else {
112-
assertNull("Expected no MD5, found: " + obtainedMd5, obtainedMd5);
112+
assertNull(obtainedMd5, "Expected no MD5, found: " + obtainedMd5);
113113
}
114114

115115
// Mess with the content so it doesn't match the MD5.
@@ -137,8 +137,8 @@ private void testStoreBlobMd5(boolean expectMd5Stored) throws Exception {
137137
}
138138
StorageException cause = (StorageException)ex.getCause();
139139
assertNotNull(cause);
140-
assertEquals("Unexpected cause: " + cause,
141-
StorageErrorCodeStrings.INVALID_MD5, cause.getErrorCode());
140+
assertEquals(
141+
StorageErrorCodeStrings.INVALID_MD5, cause.getErrorCode(), "Unexpected cause: " + cause);
142142
}
143143
}
144144

@@ -192,7 +192,7 @@ private void checkObtainedMd5(String obtainedMd5) {
192192
if (expectMd5) {
193193
assertNotNull(obtainedMd5);
194194
} else {
195-
assertNull("Expected no MD5, found: " + obtainedMd5, obtainedMd5);
195+
assertNull(obtainedMd5, "Expected no MD5, found: " + obtainedMd5);
196196
}
197197
}
198198

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.Arrays;
2424
import java.util.Date;
2525

26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727

2828
import org.apache.hadoop.conf.Configuration;
2929
import org.apache.hadoop.fs.FileSystem;

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

+29-29
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.concurrent.Callable;
2727

2828
import org.junit.FixMethodOrder;
29-
import org.junit.Test;
29+
import org.junit.jupiter.api.Test;
3030
import org.junit.runners.MethodSorters;
3131
import org.slf4j.Logger;
3232
import org.slf4j.LoggerFactory;
@@ -172,7 +172,7 @@ void assumeHugeFileExists() throws IOException {
172172
ContractTestUtils.assertPathExists(fs, "huge file not created", hugefile);
173173
FileStatus status = fs.getFileStatus(hugefile);
174174
ContractTestUtils.assertIsFile(hugefile, status);
175-
assertTrue("File " + hugefile + " is empty", status.getLen() > 0);
175+
assertTrue(status.getLen() > 0, "File " + hugefile + " is empty");
176176
}
177177

178178
/**
@@ -299,12 +299,12 @@ private void verifyConsistentReads(FSDataInputStream inputStreamV1,
299299
byte[] bufferV2) throws IOException {
300300
int size = bufferV1.length;
301301
final int numBytesReadV1 = inputStreamV1.read(bufferV1, 0, size);
302-
assertEquals("Bytes read from V1 stream", size, numBytesReadV1);
302+
assertEquals(size, numBytesReadV1, "Bytes read from V1 stream");
303303

304304
final int numBytesReadV2 = inputStreamV2.read(bufferV2, 0, size);
305-
assertEquals("Bytes read from V2 stream", size, numBytesReadV2);
305+
assertEquals(size, numBytesReadV2, "Bytes read from V2 stream");
306306

307-
assertArrayEquals("Mismatch in read data", bufferV1, bufferV2);
307+
assertArrayEquals(bufferV1, bufferV2, "Mismatch in read data");
308308
}
309309

310310
@Test
@@ -348,18 +348,18 @@ private void verifyConsistentReads(FSDataInputStream inputStreamV1,
348348
throws IOException {
349349
int size = bufferV1.length;
350350
int numBytesReadV1 = inputStreamV1.read(pos, bufferV1, 0, size);
351-
assertEquals("Bytes read from V1 stream", size, numBytesReadV1);
351+
assertEquals(size, numBytesReadV1, "Bytes read from V1 stream");
352352

353353
int numBytesReadV2 = inputStreamV2.read(pos, bufferV2, 0, size);
354-
assertEquals("Bytes read from V2 stream", size, numBytesReadV2);
354+
assertEquals(size, numBytesReadV2, "Bytes read from V2 stream");
355355

356356
int numBytesReadV2NoBuffer = inputStreamV2NoBuffer.read(pos,
357357
bufferV2NoBuffer, 0, size);
358-
assertEquals("Bytes read from V2 stream (buffered pread disabled)", size,
359-
numBytesReadV2NoBuffer);
358+
assertEquals(size
359+
, numBytesReadV2NoBuffer, "Bytes read from V2 stream (buffered pread disabled)");
360360

361-
assertArrayEquals("Mismatch in read data", bufferV1, bufferV2);
362-
assertArrayEquals("Mismatch in read data", bufferV2, bufferV2NoBuffer);
361+
assertArrayEquals(bufferV1, bufferV2, "Mismatch in read data");
362+
assertArrayEquals(bufferV2, bufferV2NoBuffer, "Mismatch in read data");
363363
}
364364

365365
/**
@@ -383,7 +383,7 @@ public void test_0302_MarkSupportedV2() throws IOException {
383383
private void validateMarkSupported(FileSystem fs) throws IOException {
384384
assumeHugeFileExists();
385385
try (FSDataInputStream inputStream = fs.open(TEST_FILE_PATH)) {
386-
assertTrue("mark is not supported", inputStream.markSupported());
386+
assertTrue(inputStream.markSupported(), "mark is not supported");
387387
}
388388
}
389389

@@ -417,7 +417,7 @@ private void validateMarkAndReset(FileSystem fs) throws Exception {
417417
assertEquals(buffer.length, bytesRead);
418418

419419
inputStream.reset();
420-
assertEquals("rest -> pos 0", 0, inputStream.getPos());
420+
assertEquals(0, inputStream.getPos(), "rest -> pos 0");
421421

422422
inputStream.mark(8 * KILOBYTE - 1);
423423

@@ -511,10 +511,10 @@ public Long call() throws Exception {
511511
);
512512
long elapsedTimeMs = timer.elapsedTimeMs();
513513
assertTrue(
514-
String.format(
514+
515+
elapsedTimeMs < 20, String.format(
515516
"There should not be any network I/O (elapsedTimeMs=%1$d).",
516-
elapsedTimeMs),
517-
elapsedTimeMs < 20);
517+
elapsedTimeMs));
518518
}
519519
}
520520

@@ -559,7 +559,7 @@ public FSDataInputStream call() throws Exception {
559559
}
560560
);
561561

562-
assertTrue("Test file length only " + testFileLength, testFileLength > 0);
562+
assertTrue(testFileLength > 0, "Test file length only " + testFileLength);
563563
inputStream.seek(testFileLength);
564564
assertEquals(testFileLength, inputStream.getPos());
565565

@@ -576,10 +576,10 @@ public FSDataInputStream call() throws Exception {
576576

577577
long elapsedTimeMs = timer.elapsedTimeMs();
578578
assertTrue(
579-
String.format(
579+
580+
elapsedTimeMs < 20, String.format(
580581
"There should not be any network I/O (elapsedTimeMs=%1$d).",
581-
elapsedTimeMs),
582-
elapsedTimeMs < 20);
582+
elapsedTimeMs));
583583
}
584584
}
585585

@@ -770,13 +770,13 @@ public void test_0315_SequentialReadPerformance() throws IOException {
770770
(long) v2ElapsedMs,
771771
ratio));
772772
}
773-
assertTrue(String.format(
773+
assertTrue(
774+
ratio < maxAcceptableRatio, String.format(
774775
"Performance of version 2 is not acceptable: v1ElapsedMs=%1$d,"
775776
+ " v2ElapsedMs=%2$d, ratio=%3$.2f",
776777
(long) v1ElapsedMs,
777778
(long) v2ElapsedMs,
778-
ratio),
779-
ratio < maxAcceptableRatio);
779+
ratio));
780780
}
781781

782782
/**
@@ -804,14 +804,14 @@ public void test_0316_SequentialReadAfterReverseSeekPerformanceV2()
804804
(long) afterSeekElapsedMs,
805805
ratio));
806806
}
807-
assertTrue(String.format(
807+
assertTrue(
808+
ratio < maxAcceptableRatio, String.format(
808809
"Performance of version 2 after reverse seek is not acceptable:"
809810
+ " beforeSeekElapsedMs=%1$d, afterSeekElapsedMs=%2$d,"
810811
+ " ratio=%3$.2f",
811812
(long) beforeSeekElapsedMs,
812813
(long) afterSeekElapsedMs,
813-
ratio),
814-
ratio < maxAcceptableRatio);
814+
ratio));
815815
}
816816

817817
private long sequentialRead(int version,
@@ -871,13 +871,13 @@ public void test_0317_RandomReadPerformance() throws IOException {
871871
(long) v2ElapsedMs,
872872
ratio));
873873
}
874-
assertTrue(String.format(
874+
assertTrue(
875+
ratio < maxAcceptableRatio, String.format(
875876
"Performance of version 2 is not acceptable: v1ElapsedMs=%1$d,"
876877
+ " v2ElapsedMs=%2$d, ratio=%3$.2f",
877878
(long) v1ElapsedMs,
878879
(long) v2ElapsedMs,
879-
ratio),
880-
ratio < maxAcceptableRatio);
880+
ratio));
881881
}
882882

883883
private long randomRead(int version, FileSystem fs) throws IOException {

0 commit comments

Comments
 (0)
0