Hi everyone,
I have a little problem when it comes to testing my H2 based Application 
with JUnit4.
I am using H2 v 1.4.196
I have several testcases within one Test, and I am getting 'concurrent 
update' or 'recently modified lockfile' Exceptions on starting up my server 
occasionally.

The 'Before' Method of my test is not doing much

@Before 
public void setupCase() throws Exception { 
  dbServer = new DBServer(tcpPort, webPort); 
}

 I am creating a server the following way:

super("H2DBServer", true); 
LOG.info("Starting internal DB-Server"); 

logDebug(" ... loading H2-Driver."); 
Driver.load(); 

logDebug(" ... creating database connection."); 
String dbPath = PATHTOMYVARDIR + DBNAME; 

//@formatter:off 
String dbAttrs = ";AUTO_SERVER=TRUE" 
               + ";CIPHER=AES" 
               + ";MVCC=TRUE" 
               + ";MODE=MYSQL" 
               + ";MULTI_THREADED=FALSE"; 
//@formatter:on 

dataSource = new JdbcDataSource(); 
dataSource.setURL("jdbc:h2:file:" + dbPath + dbAttrs); 
dataSource.setUser(DBROOT); 
dataSource.setPassword(ENCPW + " " + ROOTPW); 

dbLockFile = new File(dbPath + ".lock.db"); 
conn = dataSource.getConnection(); 
stmnt = conn.createStatement();

logDebug(" ... starting webservice."); 
webServer = Server.createWebServer("-webAllowOthers", "-webPort", webPort + "", 
"-baseDir", varDir, "-properties", "null").start(); 
logDebug(" ... webservice reachable via '" + webServer.getURL() + "'."); 

logDebug(" ... starting tcpservice."); tcpServer = 
Server.createTcpServer("-tcpAllowOthers", "-tcpPort", tcpPort + "", "-baseDir", 
varDir).start();

 Which works quite fine most of the times. Server is started and running 
and I can execute my statements.

After each test i am calling

@After 
public void teardownCase() throws Exception { 
  dbServer.cancel(); 
  while (dbServer.isAlive()) { 
    RuntimeFunctions.sleepGuaranteed(100); 
  } 
}


 Within the DBServers 'cancel' method the following stuff is done:


LOG.info("Stopping internal DB-Server."); 

logDebug(" ... stopping tcpservice."); 
tcpServer.shutdown(); 
tcpServer.stop(); 

logDebug(" ... stopping webservice."); 
webServer.shutdown(); 
webServer.stop(); 

logDebug(" ... shutting down db via sql statement."); 
while (!stmnt.execute("SHUTDOWN")) { 
  RuntimeFunctions.sleepGuaranteed(250); 
} 

logDebug(" ... closing statement."); 
stmnt.close(); 

logDebug(" ... closing db connection."); 
conn.close();

while (!conn.isClosed() && !stmnt.isClosed() && webServer.isRunning(false) && 
tcpServer.isRunning(false)) { 
  RuntimeFunctions.sleepGuaranteed(100); 
} 
logDebug(" ... unloading H2-driver."); Driver.unload(); LOG.info("... done.");

 Unfortunately the H2 jdbsource has no close (or whatever) method.
With the above 'cancel' code I would think everything is closed.
However, the H2s internal Watchdog keeps writing into the LockFile and is 
not killed due to the circumstance that it gets only killed on JVM shutdown.

Maybe I am instantiating the database in the wrong way?
I've already tried:

   - Looking for thread(s) starting with 'H2 File Lock Watchdog' and 
   calling 'interrupt()'. However, as interrupted exceptions are caught within 
   the 'run()' method of FileLock this has no relevance
   - Trying MVCC=FALSE and MULTI_THREADED=TRUE, however, this changed 
   nothing
   - Delete the *.lock file manually, however it was immediately created a 
   new by the watchdog.

To my Understanding with AUTO_SERVER set to true and MULTI_THREaDED also 
set to true, shouldn't it be possible to connect multiple times?
This is another point which cnfuses me, as the exception gets thrown on the 
'connect' method.

If you need any additional information, I'll be glad to provide them.

Thanks in advance for every kind of help.


Best regards,
Sno0tCode 

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to