java - H2 server suspends while debugging -


i have spring application starts following in memory h2 database junit tests:

db.jdbc.driver=org.h2.driver db.jdbc.url=jdbc:h2:mem:sampledb db.jdbc.username= db.jdbc.password= hibernate.dialect=org.hibernate.dialect.h2dialect 

i debug when junit tests running , meantime browse database state, before test suite start h2 server:

org.h2.tools.server.createtcpserver("-tcpport", "9092", "-tcpallowothers").start(); 

unfortunately when put breakpoint suspends threads suspends h2 server thread, not able connect. cannot start h2 server in different process because in memory database not accessible outside vm.

i understand can use other type of breakpoint (that suspends current thread) it's kind of limitation. have found other solutions such problem?

starting tcp server not here, you're creating memory database.

i suggest starting console instead in thread, , in same piece of code (using jdbc example) open connection database not close/release it.

do this snippet: please add options allow others according h2 documentation (i suggest leaving now)

org.h2.tools.server.createwebserver().start(); 

opening database in 2nd thread jdbc/jooq (this in nashorn javascript can adapted java):

var conn = (new org.h2.driver()).connect('jdbc:h2:mem:sampledb',new java.util.properties()); var db = org.jooq.impl.dsl.using(conn, org.jooq.sqldialect.h2); 

like this, memory based database not accidentally closed , you'll able access remotely. putting in thread guard breakpoints.

updates: based on discussion original author of question, best solution open memory based h2 in separate process , provide tcp server on it. solves issue, in separate process.

here's how start separate process:

java -jar h2-1.4.188.jar -tcp -tcpport 9092 -basedir mem:mydb 

here's jdbc url use: jdbc:h2:tcp://localhost:9092/mem:mydb

important note: if connections on memory based db closed, content disappear. method used caution. if need persistence through tests, please use standard file-based h2 db.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -