Search in sources :

Example 11 with TraceSystem

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();
    }
}
Also used : FileLock(org.h2.store.FileLock) TraceSystem(org.h2.message.TraceSystem)

Example 12 with TraceSystem

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();
}
Also used : FileLock(org.h2.store.FileLock) TraceSystem(org.h2.message.TraceSystem)

Example 13 with TraceSystem

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");
}
Also used : TraceSystem(org.h2.message.TraceSystem)

Example 14 with TraceSystem

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();
}
Also used : TraceSystem(org.h2.message.TraceSystem)

Example 15 with TraceSystem

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");
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TraceSystem(org.h2.message.TraceSystem)

Aggregations

TraceSystem (org.h2.message.TraceSystem)14 FileLock (org.h2.store.FileLock)5 DbException (org.h2.message.DbException)4 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 FileChannel (java.nio.channels.FileChannel)1 AccessControlException (java.security.AccessControlException)1 BitSet (java.util.BitSet)1 Properties (java.util.Properties)1 CreateTableData (org.h2.command.ddl.CreateTableData)1 Constraint (org.h2.constraint.Constraint)1 Database (org.h2.engine.Database)1 Cursor (org.h2.index.Cursor)1 Schema (org.h2.schema.Schema)1 Column (org.h2.table.Column)1 IndexColumn (org.h2.table.IndexColumn)1 Transfer (org.h2.value.Transfer)1