slfan1989 commented on PR #7369:
URL: https://github.com/apache/hadoop/pull/7369#issuecomment-2645006747
I am trying to modify the code of hadoop-azure, this is part 1. I am syncing
the improvements so that it can be better reviewed:
### 1. TestName
In JUnit 5, the `org.junit.rules.TestName` class no longer exists.
We need to use `org.junit.jupiter.api.TestInfo.getDisplayName()` as a
replacement and pass `TestInfo` in the parameters of `setUp`, `tearDown`, and
`tests`.
Here is an example:
> setUp
```
@BeforeEach
@Override
public void setUp(TestInfo testInfo) throws Exception {
super.setUp(testInfo);
Configuration conf = new Configuration();
conf.setInt(AzureNativeFileSystemStore.KEY_INPUT_STREAM_VERSION, 1);
}
```
> tearDown
```
@AfterEach
public void tearDown(TestInfo info) throws Exception {
describe(info,"closing test account and filesystem");
testAccount = cleanupTestAccount(testAccount);
IOUtils.closeStream(fs);
fs = null;
}
```
> Junit Test
```
@Test
public void testBlobMd5StoreOffByDefault(TestInfo testInfo) throws Exception
{
testAccount = AzureBlobStorageTestAccount.create();
testStoreBlobMd5(false, testInfo);
}
```
### 2. Timeout
In JUnit 5, `@Timeou`t can be set on the test method or class to specify a
timeout, with the unit in seconds.
Here is an example:
> method
```
@Test
@Timeout(1)
void shouldFailAfterOneSecond() throws InterruptedException {
Thread.sleep(10_000);
}
```
> class
```
@Timeout(5)
class TimeoutUnitTest {
@Test
void shouldFailAfterOneSecond() throws InterruptedException {
Thread.sleep(10_000);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]