Subject: integration testing headless process


I have a headless quartz job that works fine when I test it from the webapp
with jetty:run.  It subclasses HeadlessAbstract and gets user and group
membership from the quartz configuration.  When I do a Cucumber test with
it then it seems to function fine, but the code following the job execution
- the steps that check if the result is good -- fails because the JDO
session is closed.  The teardown code throws an error that says
org.apache.isis.applib.NonRecoverableException: No IsisSession on current
thread. [1]

I tried having the job create a new thread and create authSession.  I get
the same error in the test and the teardown code says
javax.jdo.JDOFatalUserException: Persistence Manager has been closed [2]

Would this be a bug in some code that is not thread-safe in
HeadlessAbstract, or is there another way I can code tests for a headless
process?   It seems to also sabotage all the tests that follow - they get
marked as skipped.  I am using Isis version 2.0.0-M2.

Thanks!
Brian

[1] Stack trace (same thread):
java.lang.NullPointerException
    at
org.apache.isis.applib.services.jdosupport.IsisJdoSupportDN5.getPersistenceSession(IsisJdoSupportDN5.java:223)
    at
org.apache.isis.applib.services.jdosupport.IsisJdoSupportDN5.getJdoPersistenceManager(IsisJdoSupportDN5.java:233)
    at
org.apache.isis.applib.services.jdosupport.IsisJdoSupportDN5.newTypesafeQuery(IsisJdoSupportDN5.java:195)
    at
domainapp.modules.simple.dom.impl.J300eSessions.listAll(J300eSessions.java:54)
    at
domainapp.modules.simple.dom.impl.J300eSessions.listAll(J300eSessions.java:72)
    at
domainapp.modules.simple.specglue.PollingGlue.first_questionnaire_is_loaded_to_Onbase(PollingGlue.java:84)
    at ✽.Then first questionnaire is loaded to
Onbase(domainapp/application/bdd/specs/PollingSpec.feature:12)

org.apache.isis.applib.NonRecoverableException: No IsisSession on current
thread.
    at
org.apache.isis.core.runtime.services.persistsession.PersistenceSessionServiceInternalDefault.lambda$getPersistenceSession$0(PersistenceSessionServiceInternalDefault.java:213)
    at java.util.Optional.orElseThrow(Optional.java:290)
    at
org.apache.isis.core.runtime.services.persistsession.PersistenceSessionServiceInternalDefault.getPersistenceSession(PersistenceSessionServiceInternalDefault.java:213)
    at
org.apache.isis.core.runtime.services.persistsession.PersistenceSessionServiceInternalDefault.getTransactionManager(PersistenceSessionServiceInternalDefault.java:222)
    at
org.apache.isis.core.runtime.services.persistsession.PersistenceSessionServiceInternalDefault.getTransactionState(PersistenceSessionServiceInternalDefault.java:202)
    at
org.apache.isis.core.runtime.services.xactn.TransactionServiceDefault.getTransactionState(TransactionServiceDefault.java:104)
    at
org.apache.isis.core.runtime.services.xactn.TransactionServiceDefault.nextTransaction(TransactionServiceDefault.java:63)
    at
org.apache.isis.core.runtime.services.xactn.TransactionServiceDefault.nextTransaction(TransactionServiceDefault.java:58)
    at
org.apache.isis.core.runtime.headless.HeadlessWithBootstrappingAbstract.tearDownAllModules(HeadlessWithBootstrappingAbstract.java:138)
    at
domainapp.application.bdd.specglue.BootstrappingGlue.afterScenario(BootstrappingGlue.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at cucumber.runtime.Utils$1.call(Utils.java:37)
    at cucumber.runtime.Timeout.timeout(Timeout.java:13)
    at cucumber.runtime.Utils.invoke(Utils.java:31)
    at
cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:60)
    at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:223)
    at cucumber.runtime.Runtime.runHooks(Runtime.java:211)
    at cucumber.runtime.Runtime.runAfterHooks(Runtime.java:205)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:46)
    at
cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:91)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:93)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:98)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    at
org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:39)
    at
java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
    at
java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Iterator.forEachRemaining(Iterator.java:116)
    at
java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
    at java.util.stream.AbstractPipeline.copyInto(Abstract