You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2022/06/23 18:25:14 UTC

[logging-log4j2] 02/02: Add a global test listener

This is an automated email from the ASF dual-hosted git repository.

pkarwasz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit ea10933c5a13270f4874170db90f81f749ec211e
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Thu Jun 23 20:24:02 2022 +0200

    Add a global test listener
    
    The `Log4j2LauncherSessionListener` provides the global setup necessary
    for a parallel run.
    
    At the moment it initializes `PropertiesUtil` to prevent initialization
    during a test case and the caching of non-default properties.
---
 .../test/junit/Log4j2LauncherSessionListener.java  | 35 ++++++++++++++++++++++
 ...junit.platform.launcher.LauncherSessionListener | 16 ++++++++++
 2 files changed, 51 insertions(+)

diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/Log4j2LauncherSessionListener.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/Log4j2LauncherSessionListener.java
new file mode 100644
index 0000000000..51abd82afe
--- /dev/null
+++ b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/Log4j2LauncherSessionListener.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.test.junit;
+
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.junit.platform.launcher.LauncherSession;
+import org.junit.platform.launcher.LauncherSessionListener;
+
+/**
+ * Global Log4j2 test setup.
+ */
+public class Log4j2LauncherSessionListener implements LauncherSessionListener {
+
+    @Override
+    public void launcherSessionOpened(LauncherSession session) {
+        // Prevents `PropertiesUtil` from initializing (and caching the results)
+        // in the middle of a test.
+        PropertiesUtil.getProperties();
+    }
+
+}
diff --git a/log4j-api-test/src/main/resources/META-INF/services/org.junit.platform.launcher.LauncherSessionListener b/log4j-api-test/src/main/resources/META-INF/services/org.junit.platform.launcher.LauncherSessionListener
new file mode 100644
index 0000000000..e492405c76
--- /dev/null
+++ b/log4j-api-test/src/main/resources/META-INF/services/org.junit.platform.launcher.LauncherSessionListener
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache license, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the license for the specific language governing permissions and
+# limitations under the license.
+
+org.apache.logging.log4j.test.junit.Log4j2LauncherSessionListener
\ No newline at end of file