rzo1 commented on code in PR #218:
URL: https://github.com/apache/openjpa/pull/218#discussion_r4359085167
##########
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/AbstractCriteriaTestCase.java:
##########
@@ -69,10 +69,73 @@ public DBDictionary getDictionary() {
@Override
public void tearDown() throws Exception {
- dict = null;
- super.tearDown();
+ releaseResources();
}
+ /**
+ * Releases everything {@code setUp()} opened: the EntityManager, the
audited SQL and the
+ * shared EntityManagerFactory, in that order and each step in its own
{@code finally}, so
+ * that a failure releasing one resource cannot leave the next one open -
an exception out
+ * of {@code em.close()} must not skip {@code emf.close()} and leak the
whole connection
+ * pool. Every step is null-safe, because {@link #runBare()} calls {@code
tearDown()} even
+ * when {@code setUp()} failed part way through, and the method is
idempotent
+ * (OPENJPA-3016).
+ * <p>
+ * All three criteria base classes delegate here, so the guarantee {@link
#runBare()}
+ * relies on holds for each of them.
+ */
+ protected final void releaseResources() throws Exception {
+ try {
Review Comment:
@solomax done, thanks
##########
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/AbstractCriteriaTestCase.java:
##########
@@ -371,6 +447,32 @@ public void runBare() throws Throwable {
}
}
+ /**
+ * Mirrors {@link junit.framework.TestCase#runBare()} except that {@code
setUp()} is
+ * covered by the try/finally, so {@code tearDown()} always releases what
{@code setUp()}
+ * opened. Both are called exactly once.
+ */
+ private void runBareReleasingResources() throws Throwable {
+ Throwable exception = null;
+ try {
+ setUp();
+ runTest();
+ } catch (Throwable running) {
+ exception = running;
+ } finally {
+ try {
+ tearDown();
+ } catch (Throwable tearingDown) {
+ if (exception == null) {
Review Comment:
@solomax done, thanks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]