Richard Zowalla created TOMEE-4714:
--------------------------------------

             Summary: TomEEEmbeddedExtension (JUnit 5) can not start the 
container again after it was closed
                 Key: TOMEE-4714
                 URL: https://issues.apache.org/jira/browse/TOMEE-4714
             Project: TomEE
          Issue Type: Bug
            Reporter: Richard Zowalla


The JUnit 5 extension for TomEE embedded \({{@RunWithTomEEEmbedded}} / 
{{TomEEEmbeddedExtension}}\) only works for the first container start within a 
JVM. Every test \(class\) executed afterwards runs without a container.

h3. Cause

{{TomEEEmbeddedExtension}} holds a static {{TomEEEmbeddedBase}}, which holds a 
static {{TomEEEmbeddedApplicationRunner}}. The extension closes the runner in 
{{afterAll}} \(lifecycle {{PER\_CLASS}}\) or {{afterEach}} \(default 
lifecycle\) and starts it again for the next test \(class\).

{{TomEEEmbeddedApplicationRunner#close\(\)}} stops the container and sets {{app 
= null}}, but never resets the {{started}} flag. The next call of 
{{start\(...\)}} therefore returns early:

{code:java}
public synchronized void start\(final Class<?> marker, final Properties config, 
final String... args\) throws Exception {
    if \(started\) {
        return;
    }
    ...
{code}

No container is started and {{app}} stays {{null}}, so 
{{composerInject\(...\)}} injects {{null}} into fields annotated with 
{{@Application}} and {{@RandomPort}} is not populated.

h3. Observed behaviour* Lifecycle {{PER\_CLASS}}: the first test class passes, 
all tests of every following test class fail, e.g. with a 
{{NullPointerException}} on the {{@Application}} field.
* Default lifecycle \({{PER\_METHOD}}\): the container is closed after the 
first test method, so only the first test method of the JVM has a container.

h3. How to reproduce

Two test classes annotated with {{@RunWithTomEEEmbedded}} \(and 
{{@TestInstance\(TestInstance.Lifecycle.PER\_CLASS\)}}\) sharing one 
{{@Application}} descriptor, executed in the same surefire JVM. The existing 
tests \({{SingleInstanceRunnerExtensionTest}}, 
{{NoScannerSingleRunnerExtensionTest}}\) do not hit this, as they consist of a 
single test method each.

h3. Expected behaviour

Either the runner can be started again after {{close\(\)}} \(reset 
{{started}}\), or the extension keeps a single container per JVM like 
{{TomEEEmbeddedSingleRunner}} does for JUnit 4 and does not close it between 
tests. A mode switch similar to {{ExtensionMode}} of 
{{@RunWithApplicationComposer}} would be nice to have.

h3. Context

Found while migrating JAX\-RS tests from {{ApplicationComposer}} \+ 
{{@EnableServices\("jaxrs"\)}} to TomEE embedded \(TOMEE\-4707 removes the 
embedded HTTP server\). Seen with 10.2.0 and 11.0.0\-SNAPSHOT.





--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to