[
https://issues.apache.org/jira/browse/TOMEE-4714?focusedWorklogId=1044323&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1044323
]
ASF GitHub Bot logged work on TOMEE-4714:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 28/Sep/26 08:15
Start Date: 28/Sep/26 08:15
Worklog Time Spent: 10m
Work Description: rzo1 opened a new pull request, #2957:
URL: https://github.com/apache/tomee/pull/2957
https://issues.apache.org/jira/browse/TOMEE-4714
## Problem
`@RunWithTomEEEmbedded` only works for the first container start of a JVM.
The extension closes the container after each test (class), but
`TomEEEmbeddedApplicationRunner#close()` never resets `started`, so the next
`start(...)` returns early. No container is started and `@Application` /
`@RandomPort` fields stay `null`.
## Change
- `TomEEEmbeddedApplicationRunner#close()` resets `started`, so the runner
can be started again.
- `@RunWithTomEEEmbedded` gets a `mode` (`PER_JVM`, `PER_ALL`, `PER_EACH`,
`AUTO`), like `@RunWithApplicationComposer`. `AUTO` is the default and keeps
the current behaviour: it follows the lifecycle of the test instance.
- `@RunWithTomEEEmbedded` is `@Inherited` now, like
`@RunWithApplicationComposer`.
- `TomEEEmbeddedBase` gets a `start(Class)` overload, as there is no test
instance yet if the container is started for a test class.
- `PER_JVM` can't be combined with the other modes in the same JVM, same
restriction as for the ApplicationComposer.
## Tests
Two new surefire executions in `tomee-embedded`, each running its test
classes in one shared JVM:
- `junit5-extension-modes`: `PER_EACH`, `PER_ALL` and `AUTO` (both test
instance lifecycles). The container is started 8 times in that JVM.
- `junit5-extension-mode-per-jvm`: two test classes sharing a single
container.
Not covered by a test: the guard rejecting a mix of `PER_JVM` and the other
modes.
Issue Time Tracking
-------------------
Worklog Id: (was: 1044323)
Time Spent: 20m (was: 10m)
> 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
> Priority: Major
> Time Spent: 20m
> Remaining Estimate: 0h
>
> 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)