Skip to content

Commit 7864b68

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 7864b68

File tree

1 file changed

+21
-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

+21
-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: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public class TestLogInfo {
7777

7878
@BeforeEach
7979
public void setup() throws Exception {
80+
prepareCleanTestRootDir();
8081
config.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, TEST_ROOT_DIR.toString());
8182
HdfsConfiguration hdfsConfig = new HdfsConfiguration();
8283
hdfsCluster = new MiniDFSCluster.Builder(hdfsConfig).numDataNodes(1).build();
@@ -106,7 +107,25 @@ public void tearDown() throws Exception {
106107
jsonGenerator.close();
107108
outStream.close();
108109
outStreamDomain.close();
110+
111+
FileSystem hdfsFs = hdfsCluster.getFileSystem();
112+
if (hdfsFs.exists(TEST_ROOT_DIR)) {
113+
hdfsFs.delete(TEST_ROOT_DIR, true);
114+
}
109115
hdfsCluster.shutdown();
116+
117+
FileSystem localFs = FileSystem.getLocal(config);
118+
if (localFs.exists(TEST_ROOT_DIR)) {
119+
localFs.delete(TEST_ROOT_DIR, true);
120+
}
121+
}
122+
123+
/**
124+
* Creates a fresh test root directory after cleanup.
125+
*/
126+
private void prepareCleanTestRootDir() throws IOException {
127+
FileSystem localFs = FileSystem.getLocal(config);
128+
localFs.mkdirs(TEST_ROOT_DIR);
110129
}
111130

112131
@Test
@@ -245,5 +264,5 @@ private Path getTestRootPath() {
245264
private Path getTestRootPath(String pathString) {
246265
return fileContextTestHelper.getTestRootPath(fc, pathString);
247266
}
248-
249-
}
267+
268+
}

0 commit comments

Comments
 (0)