提交 9cb0a0cd 编写于 作者: S shroman 提交者: yukon

[ROCKETMQ-5] Avoid creating directories in...

[ROCKETMQ-5] Avoid creating directories in UtilAll#getDiskPartitionSpaceUsedPercent(), closes apache/incubator-rocketmq#23
上级 c4f12497
......@@ -183,17 +183,16 @@ public class UtilAll {
try {
File file = new File(path);
if (!file.exists()) {
boolean result = file.mkdirs();
if (!result) {
//TO DO
}
}
if (!file.exists())
return -1;
long totalSpace = file.getTotalSpace();
long freeSpace = file.getFreeSpace();
long usedSpace = totalSpace - freeSpace;
if (totalSpace > 0) {
long freeSpace = file.getFreeSpace();
long usedSpace = totalSpace - freeSpace;
return usedSpace / (double) totalSpace;
}
} catch (Exception e) {
......
......@@ -21,6 +21,8 @@ import java.net.URL;
import java.util.Properties;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
public class UtilAllTest {
......@@ -78,6 +80,17 @@ public class UtilAllTest {
assertTrue(pid > 0);
}
@Test
public void test_getDiskPartitionSpaceUsedPercent() {
assertEquals(-1, UtilAll.getDiskPartitionSpaceUsedPercent(null), 0);
assertEquals(-1, UtilAll.getDiskPartitionSpaceUsedPercent(""), 0);
assertEquals(-1, UtilAll.getDiskPartitionSpaceUsedPercent("nonExistingPath"), 0);
String tmpDir = System.getProperty("java.io.tmpdir");
assertNotEquals(-1, UtilAll.getDiskPartitionSpaceUsedPercent(tmpDir), 0);
}
@Test
public void test_isBlank() {
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册