mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Use commons-io to measure free space.
This commit is contained in:
@@ -55,7 +55,8 @@ class H2Database extends JdbcDatabase {
|
|||||||
public long getFreeSpace() throws DbException {
|
public long getFreeSpace() throws DbException {
|
||||||
try {
|
try {
|
||||||
File dir = home.getParentFile();
|
File dir = home.getParentFile();
|
||||||
long free = FileSystemUtils.freeSpaceKb(dir.getAbsolutePath());
|
String path = dir.getAbsolutePath();
|
||||||
|
long free = FileSystemUtils.freeSpaceKb(path) * 1024L;
|
||||||
long used = getDiskSpace(dir);
|
long used = getDiskSpace(dir);
|
||||||
long quota = maxSize - used;
|
long quota = maxSize - used;
|
||||||
long min = Math.min(free, quota);
|
long min = Math.min(free, quota);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import net.sf.briar.api.protocol.GroupId;
|
|||||||
import net.sf.briar.api.protocol.Message;
|
import net.sf.briar.api.protocol.Message;
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileSystemUtils;
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.Mockery;
|
import org.jmock.Mockery;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@@ -628,7 +629,7 @@ public class H2DatabaseTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFreeSpace() throws DbException {
|
public void testGetFreeSpace() throws Exception {
|
||||||
byte[] largeBody = new byte[ONE_MEGABYTE];
|
byte[] largeBody = new byte[ONE_MEGABYTE];
|
||||||
for(int i = 0; i < largeBody.length; i++) largeBody[i] = (byte) i;
|
for(int i = 0; i < largeBody.length; i++) largeBody[i] = (byte) i;
|
||||||
Message message1 = new TestMessage(messageId, MessageId.NONE, groupId,
|
Message message1 = new TestMessage(messageId, MessageId.NONE, groupId,
|
||||||
@@ -636,7 +637,8 @@ public class H2DatabaseTest extends TestCase {
|
|||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
|
|
||||||
// Sanity check: there should be enough space on disk for this test
|
// Sanity check: there should be enough space on disk for this test
|
||||||
assertTrue(testDir.getFreeSpace() > MAX_SIZE);
|
String path = testDir.getAbsolutePath();
|
||||||
|
assertTrue(FileSystemUtils.freeSpaceKb(path) * 1024L > MAX_SIZE);
|
||||||
// The free space should not be more than the allowed maximum size
|
// The free space should not be more than the allowed maximum size
|
||||||
long free = db.getFreeSpace();
|
long free = db.getFreeSpace();
|
||||||
assertTrue(free <= MAX_SIZE);
|
assertTrue(free <= MAX_SIZE);
|
||||||
|
|||||||
Reference in New Issue
Block a user