Unit tests for H2Database.

This commit is contained in:
akwizgran
2011-07-04 16:06:10 +01:00
parent 6384256c06
commit 390b316724
13 changed files with 646 additions and 20 deletions

View File

@@ -10,31 +10,32 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.briar.api.crypto.Password;
import net.sf.briar.api.db.DatabaseComponent;
import net.sf.briar.api.db.DatabasePassword;
import net.sf.briar.api.db.DbException;
import net.sf.briar.api.protocol.MessageFactory;
import net.sf.briar.util.FileUtils;
import com.google.inject.Inject;
/** Contains all the H2-specific code for the database. */
class H2Database extends JdbcDatabase {
private static final Logger LOG =
Logger.getLogger(H2Database.class.getName());
private final Password password;
private final File home;
private final Password password;
private final String url;
private final long maxSize;
@Inject
H2Database(MessageFactory messageFactory,
@DatabasePassword Password password) {
H2Database(File dir, MessageFactory messageFactory,
@DatabasePassword Password password, long maxSize) {
super(messageFactory, "BINARY(32)");
home = new File(dir, "db");
this.password = password;
home = new File(FileUtils.getBriarDirectory(), "Data/db/db");
url = "jdbc:h2:split:" + home.getPath()
+ ";CIPHER=AES;DB_CLOSE_ON_EXIT=false";
this.maxSize = maxSize;
}
public void open(boolean resume) throws DbException {
@@ -54,7 +55,7 @@ class H2Database extends JdbcDatabase {
File dir = home.getParentFile();
long free = dir.getFreeSpace();
long used = getDiskSpace(dir);
long quota = DatabaseComponent.MAX_DB_SIZE - used;
long quota = maxSize - used;
long min = Math.min(free, quota);
if(LOG.isLoggable(Level.FINE)) LOG.fine("Free space: " + min);
return min;