You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by gp...@apache.org on 2018/10/31 21:30:16 UTC

deltaspike git commit: DELTASPIKE-1361 small improvements (esp. for CdiTestRunner)

Repository: deltaspike
Updated Branches:
  refs/heads/master a62bec4dd -> 6aceb6f34


DELTASPIKE-1361 small improvements (esp. for CdiTestRunner)


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/6aceb6f3
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/6aceb6f3
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/6aceb6f3

Branch: refs/heads/master
Commit: 6aceb6f3437e608dae8f19c57c6578fcce72752e
Parents: a62bec4
Author: gpetracek <gp...@apache.org>
Authored: Wed Oct 31 22:29:13 2018 +0100
Committer: gpetracek <gp...@apache.org>
Committed: Wed Oct 31 22:29:13 2018 +0100

----------------------------------------------------------------------
 .../testcontrol/api/junit/CdiTestRunner.java    | 33 ++++++++++++++------
 .../api/junit/CdiTestSuiteRunner.java           | 31 +++++++++++++++---
 2 files changed, 50 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6aceb6f3/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
index 11be0d4..70ec6e5 100644
--- a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
+++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
@@ -64,6 +64,8 @@ import java.util.logging.Handler;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import static java.lang.Boolean.TRUE;
+
 /**
  * A JUnit test runner to start up with a CDI or embedded JavaEE container.
  *
@@ -132,16 +134,27 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
     @Override
     public void run(RunNotifier runNotifier)
     {
-        if (!CdiTestSuiteRunner.isContainerStarted()) //not called as a part of a test-suite
+        try
         {
-            int identityHashCode = System.identityHashCode(runNotifier);
-            if (!notifierIdentities.contains(identityHashCode))
+            CdiTestSuiteRunner.getCdiTestRunnerExecutionRef().set(TRUE);
+
+            if (!CdiTestSuiteRunner.isContainerStarted()) //not called as a part of a test-suite
             {
-                addLogRunListener(runNotifier, identityHashCode);
+                int identityHashCode = System.identityHashCode(runNotifier);
+                if (!notifierIdentities.contains(identityHashCode))
+                {
+                    addLogRunListener(runNotifier, identityHashCode);
+                }
             }
-        }
 
-        super.run(runNotifier);
+            super.run(runNotifier);
+
+        }
+        finally
+        {
+            CdiTestSuiteRunner.getCdiTestRunnerExecutionRef().set(null);
+            CdiTestSuiteRunner.getCdiTestRunnerExecutionRef().remove();
+        }
     }
 
     private static synchronized void addLogRunListener(RunNotifier notifier, int identityHashCode)
@@ -608,8 +621,8 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
                 setCurrentTestMethod(null);
                 ProjectStageProducer.setProjectStage(previousProjectStage);
                 previousProjectStage = null;
-                currentTestRunner.remove();
                 currentTestRunner.set(null);
+                currentTestRunner.remove();
             }
         }
 
@@ -626,7 +639,7 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
         {
             try
             {
-                automaticScopeHandlingActive.set(Boolean.TRUE);
+                automaticScopeHandlingActive.set(TRUE);
 
                 ContextControl contextControl = container.getContextControl();
 
@@ -700,8 +713,8 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
             }
             finally
             {
-                automaticScopeHandlingActive.remove();
                 automaticScopeHandlingActive.set(null);
+                automaticScopeHandlingActive.remove();
             }
         }
 
@@ -745,7 +758,7 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
         {
             try
             {
-                automaticScopeHandlingActive.set(Boolean.TRUE);
+                automaticScopeHandlingActive.set(TRUE);
 
                 while (!this.startedScopes.empty())
                 {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6aceb6f3/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestSuiteRunner.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestSuiteRunner.java b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestSuiteRunner.java
index 5a31765..40fdbc4 100644
--- a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestSuiteRunner.java
+++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestSuiteRunner.java
@@ -45,6 +45,8 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import static java.lang.Boolean.TRUE;
+
 @SuppressWarnings("UnusedDeclaration")
 public class CdiTestSuiteRunner extends Suite
 {
@@ -66,6 +68,8 @@ public class CdiTestSuiteRunner extends Suite
 
     private static final boolean STOP_CONTAINER;
 
+    private static final ThreadLocal<Boolean> IS_CDI_TEST_RUNNER_EXECUTION = new ThreadLocal<Boolean>();
+
     private static volatile boolean containerStarted; //TODO
 
     private final Class<?> testSuiteClass;
@@ -145,6 +149,11 @@ public class CdiTestSuiteRunner extends Suite
         return STOP_CONTAINER;
     }
 
+    static ThreadLocal<Boolean> getCdiTestRunnerExecutionRef()
+    {
+        return IS_CDI_TEST_RUNNER_EXECUTION;
+    }
+
     static void setContainerStarted(boolean containerStarted)
     {
         CdiTestSuiteRunner.containerStarted = containerStarted;
@@ -164,7 +173,11 @@ public class CdiTestSuiteRunner extends Suite
             Level level = this.logger.getLevel();
 
             this.logger.setLevel(Level.INFO);
-            this.logger.info("[run] " + description.getClassName() + "#" + description.getMethodName());
+            if (TRUE.equals(IS_CDI_TEST_RUNNER_EXECUTION.get()))
+            {
+                this.logger.info("[run] " + description.getClassName() + "#" + description.getMethodName());
+            }
+
             try
             {
                 super.testRunStarted(description);
@@ -181,7 +194,12 @@ public class CdiTestSuiteRunner extends Suite
             Level level = this.logger.getLevel();
 
             this.logger.setLevel(Level.INFO);
-            this.logger.info("[finished] " + description.getClassName() + "#" + description.getMethodName());
+
+            if (TRUE.equals(IS_CDI_TEST_RUNNER_EXECUTION.get()))
+            {
+                this.logger.info("[finished] " + description.getClassName() + "#" + description.getMethodName());
+            }
+
             try
             {
                 super.testFinished(description);
@@ -198,9 +216,14 @@ public class CdiTestSuiteRunner extends Suite
             Level level = this.logger.getLevel();
 
             this.logger.setLevel(Level.INFO);
-            Description description = failure.getDescription();
-            this.logger.info("[failed] " + description.getClassName() + "#" + description.getMethodName() +
+
+            if (TRUE.equals(IS_CDI_TEST_RUNNER_EXECUTION.get()))
+            {
+                Description description = failure.getDescription();
+                this.logger.info("[failed] " + description.getClassName() + "#" + description.getMethodName() +
                     " message: " + failure.getMessage());
+            }
+
             try
             {
                 super.testFailure(failure);