You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2022/05/22 19:13:39 UTC

[logging-log4j2] 03/09: Modernize Java API usage

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

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

commit e98c3e5fe3811740dd9b32607c4f955da77861e4
Author: Matt Sicker <ma...@apache.org>
AuthorDate: Sun May 22 12:58:54 2022 -0500

    Modernize Java API usage
    
    Signed-off-by: Matt Sicker <ma...@apache.org>
---
 .../jmh/ConcurrentAsyncLoggerToFileBenchmark.java  | 29 +++++++++++-----------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ConcurrentAsyncLoggerToFileBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ConcurrentAsyncLoggerToFileBenchmark.java
index 6eda1eea2e..6540226f60 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ConcurrentAsyncLoggerToFileBenchmark.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ConcurrentAsyncLoggerToFileBenchmark.java
@@ -38,9 +38,9 @@ import org.openjdk.jmh.annotations.TearDown;
 import org.openjdk.jmh.annotations.Threads;
 import org.openjdk.jmh.annotations.Warmup;
 
-import java.io.File;
-import java.util.Collections;
-import java.util.HashMap;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
@@ -83,8 +83,8 @@ public class ConcurrentAsyncLoggerToFileBenchmark {
         private Logger logger;
 
         @Setup
-        public final void before() {
-            new File("target/ConcurrentAsyncLoggerToFileBenchmark.log").delete();
+        public final void before() throws IOException {
+            Files.deleteIfExists(Path.of("target", "ConcurrentAsyncLoggerToFileBenchmark.log"));
             System.setProperty("log4j2.is.webapp", "false");
             asyncLoggerType.setProperties();
             queueFullPolicy.setProperties();
@@ -92,22 +92,21 @@ public class ConcurrentAsyncLoggerToFileBenchmark {
         }
 
         @TearDown
-        public final void after() {
+        public final void after() throws IOException {
             ((LifeCycle) LogManager.getContext(false)).stop();
-            new File("target/ConcurrentAsyncLoggerToFileBenchmark.log").delete();
+            Files.deleteIfExists(Path.of("target", "ConcurrentAsyncLoggerToFileBenchmark.log"));
             logger = null;
         }
 
         @SuppressWarnings("unused") // Used by JMH
         public enum QueueFullPolicy {
-            ENQUEUE(Collections.singletonMap("log4j2.AsyncQueueFullPolicy", "Default")),
-            ENQUEUE_UNSYNCHRONIZED(new HashMap<>() {{
-                put("log4j2.AsyncQueueFullPolicy", "Default");
-                put("AsyncLogger.SynchronizeEnqueueWhenQueueFull", "false");
-                put("AsyncLoggerConfig.SynchronizeEnqueueWhenQueueFull", "false");
-            }
-            }),
-            SYNCHRONOUS(Collections.singletonMap("log4j2.AsyncQueueFullPolicy",
+            ENQUEUE(Map.of("log4j2.AsyncQueueFullPolicy", "Default")),
+            ENQUEUE_UNSYNCHRONIZED(Map.of(
+                "log4j2.AsyncQueueFullPolicy", "Default",
+                "AsyncLogger.SynchronizeEnqueueWhenQueueFull", "false",
+                "AsyncLoggerConfig.SynchronizeEnqueueWhenQueueFull", "false"
+            )),
+            SYNCHRONOUS(Map.of("log4j2.AsyncQueueFullPolicy",
                     SynchronousAsyncQueueFullPolicy.class.getName()));
 
             private final Map<String, String> properties;