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

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


The following commit(s) were added to refs/heads/main by this push:
     new ab6cfe2445 ARTEMIS-4424 Unecessary AMQ212025 (not connected) when no 
nodes are connected
ab6cfe2445 is described below

commit ab6cfe2445e6a82ab8f220028f007edfc3609226
Author: Clebert Suconic <[email protected]>
AuthorDate: Mon Sep 11 10:00:55 2023 -0400

    ARTEMIS-4424 Unecessary AMQ212025 (not connected) when no nodes are 
connected
    
    The exception thrown by serverLocator.connect() should be all you need on 
such case
    and the caller should then be responsible for taking appropriate action.
---
 .../core/client/impl/ServerLocatorImpl.java        |  5 +++-
 .../client/ServerLocatorConnectTest.java           | 28 +++++++++++++++++++++-
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java
index af7b304c86..763363cb7e 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java
@@ -1786,7 +1786,10 @@ public final class ServerLocatorImpl implements 
ServerLocatorInternal, Discovery
             return null;
          }
 
-         ActiveMQClientLogger.LOGGER.errorConnectingToNodes(traceException);
+         if (logger.isTraceEnabled()) {
+            logger.trace("Could not connect to any nodes. throwing an error 
now.", new Exception("trace"));
+         }
+
          throw 
ActiveMQClientMessageBundle.BUNDLE.cannotConnectToStaticConnectors2();
       }
 
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/ServerLocatorConnectTest.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/ServerLocatorConnectTest.java
index abc29851db..1d8fa1d695 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/ServerLocatorConnectTest.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/ServerLocatorConnectTest.java
@@ -29,10 +29,12 @@ import 
org.apache.activemq.artemis.api.core.client.ActiveMQClient;
 import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
 import org.apache.activemq.artemis.api.core.client.ServerLocator;
 import 
org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal;
+import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl;
 import org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal;
 import org.apache.activemq.artemis.core.config.Configuration;
 import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.logs.AssertionLoggerHandler;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
 import org.apache.activemq.artemis.uri.ServerLocatorParser;
 import org.junit.Assert;
@@ -49,11 +51,11 @@ public class ServerLocatorConnectTest extends 
ActiveMQTestBase {
       super.setUp();
       Configuration configuration = createDefaultConfig(isNetty());
       server = createServer(false, configuration);
-      server.start();
    }
 
    @Test
    public void testFailFastConnectOnClosing() throws Exception {
+      server.start();
       CountDownLatch connectLatch = new CountDownLatch(1);
       CountDownLatch subscribeLatch = new CountDownLatch(1);
       AtomicBoolean connectTimedOut = new AtomicBoolean(false);
@@ -95,6 +97,7 @@ public class ServerLocatorConnectTest extends 
ActiveMQTestBase {
 
    @Test
    public void testURL() throws Exception {
+      server.start();
       ServerLocatorParser parser = new ServerLocatorParser();
       // This URL was failing in some ConnectionFactoryTests.
       // The issue seemed to be the # to be creating extra spaces on the 
parsing
@@ -124,6 +127,7 @@ public class ServerLocatorConnectTest extends 
ActiveMQTestBase {
 
    @Test
    public void testSingleConnectorSingleServer() throws Exception {
+      server.start();
       ServerLocator locator = 
ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(),
 false, generateParams(0, isNetty())));
       ClientSessionFactory csf = createSessionFactory(locator);
       csf.close();
@@ -132,6 +136,7 @@ public class ServerLocatorConnectTest extends 
ActiveMQTestBase {
 
    @Test
    public void testSingleConnectorSingleServerConnect() throws Exception {
+      server.start();
       ServerLocatorInternal locator = (ServerLocatorInternal) 
ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(),
 false, generateParams(0, isNetty())));
       ClientSessionFactoryInternal csf = locator.connect();
       assertNotNull(csf);
@@ -141,6 +146,7 @@ public class ServerLocatorConnectTest extends 
ActiveMQTestBase {
 
    @Test
    public void testMultipleConnectorSingleServerConnect() throws Exception {
+      server.start();
       ServerLocatorInternal locator = (ServerLocatorInternal) 
ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(),
 false, generateParams(0, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(1, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(2, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(3, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(4, isNetty())));
       ClientSessionFactoryInternal csf = locator.connect();
       assertNotNull(csf);
@@ -150,6 +156,7 @@ public class ServerLocatorConnectTest extends 
ActiveMQTestBase {
 
    @Test
    public void testMultipleConnectorSingleServerConnectReconnect() throws 
Exception {
+      server.start();
       ServerLocatorInternal locator = (ServerLocatorInternal) 
ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(),
 false, generateParams(0, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(1, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(2, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(3, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(4, isNetty())));
       locator.setReconnectAttempts(15);
       ClientSessionFactoryInternal csf = locator.connect();
@@ -160,6 +167,7 @@ public class ServerLocatorConnectTest extends 
ActiveMQTestBase {
 
    @Test
    public void testMultipleConnectorSingleServerNoConnect() throws Exception {
+      server.start();
       ServerLocatorInternal locator = (ServerLocatorInternal) 
ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(),
 false, generateParams(1, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(2, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(3, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(4, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(5, isNetty())));
       ClientSessionFactoryInternal csf = null;
       try {
@@ -176,6 +184,7 @@ public class ServerLocatorConnectTest extends 
ActiveMQTestBase {
 
    @Test
    public void testMultipleConnectorSingleServerNoConnectAttemptReconnect() 
throws Exception {
+      server.start();
       ServerLocatorInternal locator = (ServerLocatorInternal) 
ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(),
 false, generateParams(1, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(2, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(3, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(4, isNetty())), createTransportConfiguration(isNetty(), 
false, generateParams(5, isNetty())));
       locator.setReconnectAttempts(15);
       CountDownLatch countDownLatch = new CountDownLatch(1);
@@ -189,6 +198,23 @@ public class ServerLocatorConnectTest extends 
ActiveMQTestBase {
       assertNull(target.csf);
    }
 
+   @Test
+   public void testNoWarningWhenNotConnecting() throws Exception {
+      try (AssertionLoggerHandler handler = new AssertionLoggerHandler()) {
+         try (ServerLocatorImpl locator = (ServerLocatorImpl) 
ServerLocatorImpl.newLocator("tcp://localhost:61616")) {
+            locator.connect();
+            Assert.fail("Expected an exception");
+         } catch (Exception expected) {
+         }
+
+         // The connect operation used to log a warning and throw an exception.
+         // which will flood the logs when a server is being started for the 
first time.
+         // Having the exception thrown only should be enough.
+         Assert.assertFalse(handler.findText("AMQ212025"));
+      }
+   }
+
+
    public boolean isNetty() {
       return true;
    }

Reply via email to