Skip to content

Commit 042204f

Browse files
pacoc218chanp1
authored andcommitted
YARN-11894 clean up file system before and after each state to address order dependency if other tests are run in between test class.
1 parent 8726690 commit 042204f

File tree

1 file changed

+22
-2
lines changed
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline

1 file changed

+22
-2
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestLogInfo.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public class TestLogInfo {
7777

7878
@BeforeEach
7979
public void setup() throws Exception {
80+
prepareCleanTestRootDir();
81+
8082
config.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, TEST_ROOT_DIR.toString());
8183
HdfsConfiguration hdfsConfig = new HdfsConfiguration();
8284
hdfsCluster = new MiniDFSCluster.Builder(hdfsConfig).numDataNodes(1).build();
@@ -106,7 +108,26 @@ public void tearDown() throws Exception {
106108
jsonGenerator.close();
107109
outStream.close();
108110
outStreamDomain.close();
111+
112+
FileSystem hdfsFs = hdfsCluster.getFileSystem();
113+
if (hdfsFs.exists(TEST_ROOT_DIR)) {
114+
hdfsFs.delete(TEST_ROOT_DIR, true);
115+
}
109116
hdfsCluster.shutdown();
117+
118+
FileSystem localFs = FileSystem.getLocal(config);
119+
if (localFs.exists(TEST_ROOT_DIR)) {
120+
localFs.delete(TEST_ROOT_DIR, true);
121+
}
122+
}
123+
124+
125+
/**
126+
* Creates a fresh test root directory after cleanup.
127+
*/
128+
private void prepareCleanTestRootDir() throws IOException {
129+
FileSystem localFs = FileSystem.getLocal(config);
130+
localFs.mkdirs(TEST_ROOT_DIR);
110131
}
111132

112133
@Test
@@ -245,5 +266,4 @@ private Path getTestRootPath() {
245266
private Path getTestRootPath(String pathString) {
246267
return fileContextTestHelper.getTestRootPath(fc, pathString);
247268
}
248-
249-
}
269+
}

0 commit comments

Comments
 (0)