You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2022/07/21 00:06:28 UTC

[activemq-artemis] 24/26: Removing Reload4J

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

clebertsuconic pushed a commit to branch new-logging
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 94f35bf3c8e51f2d6a18998f47fa33c7051a9897
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Tue Jul 19 11:31:58 2022 -0400

    Removing Reload4J
---
 tests/activemq5-unit-tests/pom.xml                 | 18 +++--
 .../activemq/ReconnectWithSameClientIDTest.java    | 23 ++----
 .../activemq/transport/failover/AMQ1925Test.java   |  7 +-
 .../transport/failover/FailoverUpdateURIsTest.java | 13 ++--
 .../apache/activemq/util/DefaultTestAppender.java  | 83 ----------------------
 5 files changed, 30 insertions(+), 114 deletions(-)

diff --git a/tests/activemq5-unit-tests/pom.xml b/tests/activemq5-unit-tests/pom.xml
index df4fe69098..d914df779c 100644
--- a/tests/activemq5-unit-tests/pom.xml
+++ b/tests/activemq5-unit-tests/pom.xml
@@ -38,12 +38,22 @@
          <artifactId>mockito-core</artifactId>
          <scope>compile</scope>
       </dependency>
-
       <dependency>
-         <groupId>org.slf4j</groupId>
-         <artifactId>slf4j-reload4j</artifactId>
-         <version>${slf4j.version}</version>
+         <groupId>org.apache.logging.log4j</groupId>
+         <artifactId>log4j-slf4j-impl</artifactId>
+         <version>${log4j.version}</version>
+      </dependency>
+      <dependency>
+         <groupId>org.apache.logging.log4j</groupId>
+         <artifactId>log4j-api</artifactId>
+         <version>${log4j.version}</version>
       </dependency>
+      <dependency>
+         <groupId>org.apache.logging.log4j</groupId>
+         <artifactId>log4j-core</artifactId>
+         <version>${log4j.version}</version>
+      </dependency>
+
 
       <dependency>
          <groupId>org.apache.activemq</groupId>
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ReconnectWithSameClientIDTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ReconnectWithSameClientIDTest.java
index 0a2d52bfd4..b3aeb7347e 100644
--- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ReconnectWithSameClientIDTest.java
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ReconnectWithSameClientIDTest.java
@@ -25,9 +25,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import junit.framework.Test;
 
-import org.apache.activemq.util.DefaultTestAppender;
-import org.apache.log4j.Appender;
-import org.apache.log4j.spi.LoggingEvent;
+import org.apache.activemq.artemis.logs.AssertionLoggerHandler;
+import org.junit.Assert;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,20 +48,8 @@ public class ReconnectWithSameClientIDTest extends EmbeddedBrokerTestSupport {
    }
 
    public void testReconnectMultipleTimesWithSameClientID() throws Exception {
+      AssertionLoggerHandler.startCapture();
 
-      org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger(org.apache.activemq.broker.jmx.ManagedTransportConnection.class);
-      final AtomicBoolean failed = new AtomicBoolean(false);
-
-      Appender appender = new DefaultTestAppender() {
-         @Override
-         public void doAppend(LoggingEvent event) {
-            if (event.getMessage().toString().startsWith("Failed to register MBean")) {
-               LOG.info("received unexpected log message: " + event.getMessage());
-               failed.set(true);
-            }
-         }
-      };
-      log4jLogger.addAppender(appender);
       try {
          connection = connectionFactory.createConnection();
          useConnection(connection);
@@ -85,10 +72,10 @@ public class ReconnectWithSameClientIDTest extends EmbeddedBrokerTestSupport {
          connection.close();
          connection = connectionFactory.createConnection();
          useConnection(connection);
+         Assert.assertFalse(AssertionLoggerHandler.findText("Failed to register MBean"));
       } finally {
-         log4jLogger.removeAppender(appender);
+         AssertionLoggerHandler.stopCapture();
       }
-      assertFalse("failed on unexpected log event", failed.get());
    }
 
    @Override
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/AMQ1925Test.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/AMQ1925Test.java
index 2f9de01097..c82e59609b 100644
--- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/AMQ1925Test.java
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/AMQ1925Test.java
@@ -40,18 +40,19 @@ import org.apache.activemq.artemis.core.server.impl.QueueImpl;
 import org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl;
 import org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS;
 import org.apache.activemq.broker.artemiswrapper.OpenwireArtemisBaseTest;
-import org.apache.log4j.Logger;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * TestCase showing the message-destroying described in AMQ-1925
  */
 public class AMQ1925Test extends OpenwireArtemisBaseTest implements ExceptionListener {
 
-   private static final Logger log = Logger.getLogger(AMQ1925Test.class);
+   private static final Logger log = LoggerFactory.getLogger(AMQ1925Test.class);
 
    private static final String QUEUE_NAME = "test.amq1925";
    private static final String PROPERTY_MSG_NUMBER = "NUMBER";
@@ -207,7 +208,7 @@ public class AMQ1925Test extends OpenwireArtemisBaseTest implements ExceptionLis
             bs = null;
          }
       } catch (Exception e) {
-         log.error(e);
+         log.error(e.getMessage(), e);
       }
    }
 
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverUpdateURIsTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverUpdateURIsTest.java
index a8d0eebe14..0ef32ccedd 100644
--- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverUpdateURIsTest.java
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverUpdateURIsTest.java
@@ -33,15 +33,16 @@ import org.apache.activemq.artemis.core.config.Configuration;
 import org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl;
 import org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS;
 import org.apache.activemq.broker.artemiswrapper.OpenwireArtemisBaseTest;
-import org.apache.log4j.Logger;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class FailoverUpdateURIsTest extends OpenwireArtemisBaseTest {
 
    private static final String QUEUE_NAME = "test.failoverupdateuris";
-   private static final Logger LOG = Logger.getLogger(FailoverUpdateURIsTest.class);
+   private static final Logger LOG = LoggerFactory.getLogger(FailoverUpdateURIsTest.class);
 
    String firstTcpUri = newURI(0);
    String secondTcpUri = newURI(10);
@@ -68,10 +69,10 @@ public class FailoverUpdateURIsTest extends OpenwireArtemisBaseTest {
       String targetDir = "target/testUpdateURIsViaFile";
       new File(targetDir).mkdir();
       File updateFile = new File(targetDir + "/updateURIsFile.txt");
-      LOG.info(updateFile);
-      LOG.info(updateFile.toURI());
-      LOG.info(updateFile.getAbsoluteFile());
-      LOG.info(updateFile.getAbsoluteFile().toURI());
+      LOG.info(updateFile.toString());
+      LOG.info("" + updateFile.toURI());
+      LOG.info("" + updateFile.getAbsoluteFile());
+      LOG.info("" + updateFile.getAbsoluteFile().toURI());
       FileOutputStream out = new FileOutputStream(updateFile);
       out.write(firstTcpUri.getBytes());
       out.close();
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/util/DefaultTestAppender.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/util/DefaultTestAppender.java
deleted file mode 100644
index 241b09eddb..0000000000
--- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/util/DefaultTestAppender.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
- * 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.activemq.util;
-
-import org.apache.log4j.Appender;
-import org.apache.log4j.Layout;
-import org.apache.log4j.spi.ErrorHandler;
-import org.apache.log4j.spi.Filter;
-
-public abstract class DefaultTestAppender implements Appender {
-
-   String name = this.getClass().getSimpleName();
-
-   @Override
-   public void addFilter(Filter newFilter) {
-
-   }
-
-   @Override
-   public Filter getFilter() {
-      return null;
-   }
-
-   @Override
-   public void clearFilters() {
-
-   }
-
-   @Override
-   public void close() {
-
-   }
-
-   @Override
-   public String getName() {
-      return name;
-   }
-
-   @Override
-   public void setErrorHandler(ErrorHandler errorHandler) {
-
-   }
-
-   @Override
-   public ErrorHandler getErrorHandler() {
-      return null;
-   }
-
-   @Override
-   public void setLayout(Layout layout) {
-
-   }
-
-   @Override
-   public Layout getLayout() {
-      return null;
-   }
-
-   @Override
-   public void setName(String name) {
-      this.name = name;
-   }
-
-   @Override
-   public boolean requiresLayout() {
-      return false;
-   }
-}