mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +01:00
Add trace tests.
This commit is contained in:
@@ -92,6 +92,10 @@ class H2Database extends JdbcDatabase {
|
|||||||
// Separate the file password from the user password with a space
|
// Separate the file password from the user password with a space
|
||||||
String hex = StringUtils.toHexString(key.getBytes());
|
String hex = StringUtils.toHexString(key.getBytes());
|
||||||
props.put("password", hex + " password");
|
props.put("password", hex + " password");
|
||||||
return DriverManager.getConnection(url, props);
|
return DriverManager.getConnection(getUrl(), props);
|
||||||
|
}
|
||||||
|
|
||||||
|
String getUrl() {
|
||||||
|
return url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package org.briarproject.bramble.db;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.sql.Connection;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
public class H2DatabaseTraceTest extends JdbcDatabaseTraceTest {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Database<Connection> createDatabase(DatabaseConfig databaseConfig,
|
||||||
|
Clock clock) {
|
||||||
|
return new H2Database(databaseConfig, clock) {
|
||||||
|
@Override
|
||||||
|
@Nonnull
|
||||||
|
String getUrl() {
|
||||||
|
return super.getUrl() + ";TRACE_LEVEL_FILE=3";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected File getTraceFile() {
|
||||||
|
return new File(testDir, "db.trace.db");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTestName() {
|
||||||
|
return getClass().getSimpleName();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package org.briarproject.bramble.db;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.briarproject.bramble.system.SystemClock;
|
||||||
|
import org.briarproject.bramble.test.TestDatabaseConfig;
|
||||||
|
import org.briarproject.bramble.util.IoUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
||||||
|
|
||||||
|
public abstract class JdbcDatabaseTraceTest
|
||||||
|
extends JdbcDatabasePerformanceTest {
|
||||||
|
|
||||||
|
abstract Database<Connection> createDatabase(DatabaseConfig databaseConfig,
|
||||||
|
Clock clock);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
protected abstract File getTraceFile();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void benchmark(String name,
|
||||||
|
BenchmarkTask<Database<Connection>> task) throws Exception {
|
||||||
|
deleteTestDirectory(testDir);
|
||||||
|
Database<Connection> db = openDatabase();
|
||||||
|
populateDatabase(db);
|
||||||
|
db.close();
|
||||||
|
File traceFile = getTraceFile();
|
||||||
|
if (traceFile != null) traceFile.delete();
|
||||||
|
db = openDatabase();
|
||||||
|
measureOne(db, task);
|
||||||
|
db.close();
|
||||||
|
if (traceFile != null) copyTraceFile(name, traceFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Database<Connection> openDatabase() throws DbException {
|
||||||
|
Database<Connection> db = createDatabase(
|
||||||
|
new TestDatabaseConfig(testDir, MAX_SIZE), new SystemClock());
|
||||||
|
db.open();
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyTraceFile(String name, File src) throws IOException {
|
||||||
|
if (!src.exists()) return;
|
||||||
|
File dest = new File(testDir.getParentFile(), name + ".trace.txt");
|
||||||
|
IoUtils.copyAndClose(new FileInputStream(src),
|
||||||
|
new FileOutputStream(dest));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user