我使用Gitlab CI和image从源代码构建apacheflinkjava:8u111 jdk,并发现对文件权限的 test失败,因为不尊重文件权限。
其中一个单元 test类似于:
@Test
public void testDeleteDirectory() throws Exception {
// deleting a non-existent file should not cause an error
File doesNotExist = new File(tmp.newFolder(), "abc");
FileUtils.deleteDirectory(doesNotExist);
// deleting a write protected file should throw an error
File cannotDeleteParent = tmp.newFolder();
File cannotDeleteChild = new File(cannotDeleteParent, "child");
try {
assumeTrue(cannotDeleteChild.createNewFile());
assumeTrue(cannotDeleteParent.setWritable(false));
assumeTrue(cannotDeleteChild.setWritable(false));
FileUtils.deleteDirectory(cannotDeleteParent);
fail("this should fail with an exception");
}
catch (AccessDeniedException ignored) {
// this is expected
}
finally {
//noinspection ResultOfMethodCallIgnored
cannotDeleteParent.setWritable(true);
//noinspection ResultOfMethodCallIgnored
cannotDeleteChild.setWritable(true);
}
}
试验结果为:
testDeleteDirectory(org.apache.flink.util.FileUtilsTest) Time elapsed: 0.022 sec <<< FAILURE!
java.lang.AssertionError: this should fail with an exception
at org.junit.Assert.fail(Assert.java:88)
at org.apache.flink.util.FileUtilsTest.testDeleteDirectory(FileUtilsTest.java:129)
当我深入研究代码时,我在java.io.File文件:
在某些平台上,可以使用特殊权限启动Java虚拟机,允许它修改不允许写操作的文件。
所以我怀疑是CI环境出了问题。如何进一步调试该问题?谢谢!
环境:
docker图像:java:8u111 jdk