use of org.h2.message.TraceSystem in project h2database by h2database.
the class TestFileLock method run.
@Override
public void run() {
FileLock lock = null;
while (!stop) {
lock = new FileLock(new TraceSystem(null), getFile(), 100);
try {
lock.lock(allowSockets ? FileLockMethod.SOCKET : FileLockMethod.FILE);
base.trace(lock + " locked");
locks++;
if (locks > 1) {
System.err.println("ERROR! LOCKS=" + locks + " sockets=" + allowSockets);
stop = true;
}
Thread.sleep(wait + (int) (Math.random() * wait));
locks--;
base.trace(lock + " unlock");
lock.unlock();
if (locks < 0) {
System.err.println("ERROR! LOCKS=" + locks);
stop = true;
}
} catch (Exception e) {
// log(id+" cannot lock: " + e);
}
try {
Thread.sleep(wait + (int) (Math.random() * wait));
} catch (InterruptedException e1) {
// ignore
}
}
if (lock != null) {
lock.unlock();
}
}
use of org.h2.message.TraceSystem in project h2database by h2database.
the class TestFileLock method testSimple.
private void testSimple() {
FileLock lock1 = new FileLock(new TraceSystem(null), getFile(), Constants.LOCK_SLEEP);
FileLock lock2 = new FileLock(new TraceSystem(null), getFile(), Constants.LOCK_SLEEP);
lock1.lock(FileLockMethod.FILE);
createClassProxy(FileLock.class);
assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, lock2).lock(FileLockMethod.FILE);
lock1.unlock();
lock2 = new FileLock(new TraceSystem(null), getFile(), Constants.LOCK_SLEEP);
lock2.lock(FileLockMethod.FILE);
lock2.unlock();
}
use of org.h2.message.TraceSystem in project h2database by h2database.
the class TestDataSource method test.
// public static void main(String... args) throws SQLException {
//
// // first, need to start on the command line:
// // rmiregistry 1099
//
// // System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
// "com.sun.jndi.ldap.LdapCtxFactory");
// System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
// "com.sun.jndi.rmi.registry.RegistryContextFactory");
// System.setProperty(Context.PROVIDER_URL, "rmi://localhost:1099");
//
// JdbcDataSource ds = new JdbcDataSource();
// ds.setURL("jdbc:h2:test");
// ds.setUser("test");
// ds.setPassword("");
//
// Context ctx = new InitialContext();
// ctx.bind("jdbc/test", ds);
//
// DataSource ds2 = (DataSource)ctx.lookup("jdbc/test");
// Connection conn = ds2.getConnection();
// conn.close();
// }
@Override
public void test() throws Exception {
if (config.traceLevelFile > 0) {
TraceSystem sys = JdbcDataSourceFactory.getTraceSystem();
sys.setFileName(getBaseDir() + "/test/trace");
sys.setLevelFile(3);
}
testDataSourceFactory();
testDataSource();
testUnwrap();
testXAConnection();
deleteDb("dataSource");
}
use of org.h2.message.TraceSystem in project h2database by h2database.
the class TestTraceSystem method testReadOnly.
private void testReadOnly() throws Exception {
String readOnlyFile = getBaseDir() + "/readOnly.log";
FileUtils.delete(readOnlyFile);
FileUtils.newOutputStream(readOnlyFile, false).close();
FileUtils.setReadOnly(readOnlyFile);
TraceSystem ts = new TraceSystem(readOnlyFile);
ts.setLevelFile(TraceSystem.INFO);
ts.getTrace("test").info("test");
FileUtils.delete(readOnlyFile);
ts.close();
}
use of org.h2.message.TraceSystem in project h2database by h2database.
the class TestTraceSystem method testTraceDebug.
private void testTraceDebug() {
TraceSystem ts = new TraceSystem(null);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ts.setSysOut(new PrintStream(out));
ts.setLevelSystemOut(TraceSystem.DEBUG);
ts.getTrace("test").debug(new Exception("error"), "test");
ts.close();
String outString = new String(out.toByteArray());
assertContains(outString, "error");
assertContains(outString, "Exception");
assertContains(outString, "test");
}
Aggregations