AnsweredAssumed Answered

Failure with h2 DB Unit test; Connection is broken: 'session closed'

Question asked by martan on Jan 25, 2016
Latest reply on Jan 26, 2016 by martan
Trying the 2nd Unit test in the Book: Activiti In Action  from Chapter 1, bookorder.bpmn20.xml
Activiti engine Unit test failing in very first call:
ProcessEngine processEngine = ProcessEngineConfiguration
         .createStandaloneProcessEngineConfiguration()
          .buildProcessEngine();
In org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDataSource call to:
try {
      connection = dataSource.getConnection();
Fails with
Connection is broken: "session closed"
Using Eclipse Mars jdk7, and the downloaded code from the book(bpmn-examples), which uses activiti-engine-5.9.jar
Complete stack:
org.h2.jdbc.JdbcSQLException: Connection is broken: "session closed" [90067-132]
   at org.h2.message.DbException.getJdbcSQLException(DbException.java:316)
   at org.h2.message.DbException.get(DbException.java:167)
   at org.h2.message.DbException.get(DbException.java:144)
   at org.h2.engine.SessionRemote.checkClosed(SessionRemote.java:447)
   at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:326)
   at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:219)
   at org.h2.engine.SessionRemote.createSession(SessionRemote.java:213)
   at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:110)
   at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:94)
   at org.h2.Driver.connect(Driver.java:58)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:201)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:196)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:93)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:385)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:89)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDatabaseType(ProcessEngineConfigurationImpl.java:489)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDataSource(ProcessEngineConfigurationImpl.java:451)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:305)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:282)
   at org.bpmnwithactiviti.chapter1.BookOrderTest.startBookOrder(BookOrderTest.java:27)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
   at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
   at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
   at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
   at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
   at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
   at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
   at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
   at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
   at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
   at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
   at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Just a hunch, but ProcessEngineConfigurationImpl.initDataSource() has this:
      if (dataSource instanceof PooledDataSource) {
        // ACT-233: connection pool of Ibatis is not properely initialized if this is not called!
        ((PooledDataSource)dataSource).forceCloseAll();
      }
which I think might be related to the issue.
Aside: (snowed in at home during SnowZilla 2016, and trying to learn about Activiti; this stack is a drag..)

Outcomes