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/08/02 12:58:55 UTC

[activemq-artemis] branch main updated: ARTEMIS-3917 Fix incorrect getters/setters on Configuration API

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 609343ec78 ARTEMIS-3917 Fix incorrect getters/setters on Configuration API
609343ec78 is described below

commit 609343ec787208e175ff5b3b34945591726dd96e
Author: Andy Taylor <an...@gmail.com>
AuthorDate: Tue Aug 2 10:29:21 2022 +0100

    ARTEMIS-3917 Fix incorrect getters/setters on Configuration API
    
    and added test for primitive configuration properties
    
    https://issues.apache.org/jira/browse/ARTEMIS-3917
---
 .../artemis/core/config/Configuration.java         | 11 +++-
 .../core/config/impl/ConfigurationImpl.java        | 10 ++++
 .../deployers/impl/FileConfigurationParser.java    |  2 +-
 .../core/config/impl/ConfigurationImplTest.java    | 58 ++++++++++++++++++++++
 4 files changed, 79 insertions(+), 2 deletions(-)

diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java
index f57cb1a481..af35a66210 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java
@@ -674,6 +674,12 @@ public interface Configuration {
     */
    Configuration setNodeManagerLockDirectory(String dir);
 
+   /**
+    * the directory that contains the lock file
+    * @return the directory
+    */
+   String getNodeManagerLockDirectory();
+
    /**
     * Sets the file system directory used to store journal log.
     */
@@ -1169,7 +1175,7 @@ public interface Configuration {
    Configuration setMaskPassword(Boolean maskPassword);
 
    /**
-    * If passwords are masked. True means the passwords are masked.
+    * If passwords are masked. True means the passwords are masked.enableda
     */
    Boolean isMaskPassword();
 
@@ -1286,8 +1292,11 @@ public interface Configuration {
    int getNetworkCheckTimeout();
 
    /** The NIC name to be used on network checks */
+   @Deprecated
    Configuration setNetworCheckNIC(String nic);
 
+   /** The NIC name to be used on network checks */
+   Configuration setNetworkCheckNIC(String nic);
    String getNetworkCheckNIC();
 
    String getNetworkCheckPingCommand();
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
index aeabf6c453..5e57058d94 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
@@ -1168,6 +1168,10 @@ public class ConfigurationImpl implements Configuration, Serializable {
       return this;
    }
 
+   @Override
+   public String getNodeManagerLockDirectory() {
+      return nodeManagerLockDirectory;
+   }
    @Override
    public JournalType getJournalType() {
       return journalType;
@@ -2661,6 +2665,12 @@ public class ConfigurationImpl implements Configuration, Serializable {
       return this;
    }
 
+   @Override
+   public Configuration setNetworkCheckNIC(String nic) {
+      this.networkCheckNIC = nic;
+      return this;
+   }
+
    @Override
    public String getNetworkCheckNIC() {
       return networkCheckNIC;
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
index c229476ab0..a8fa75d771 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
@@ -767,7 +767,7 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
 
       config.setNetworkCheckTimeout(getInteger(e, "network-check-timeout", config.getNetworkCheckTimeout(), Validators.GT_ZERO));
 
-      config.setNetworCheckNIC(getString(e, "network-check-NIC", config.getNetworkCheckNIC(), Validators.NO_CHECK));
+      config.setNetworkCheckNIC(getString(e, "network-check-NIC", config.getNetworkCheckNIC(), Validators.NO_CHECK));
 
       config.setNetworkCheckPing6Command(getString(e, "network-check-ping6-command", config.getNetworkCheckPing6Command(), Validators.NO_CHECK));
 
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
index fd3db44343..5213cbbea9 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
@@ -20,10 +20,14 @@ import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.PrintWriter;
+import java.lang.reflect.Method;
+import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.LinkedList;
+import java.util.Map;
 import java.util.Properties;
+import java.util.Random;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -53,6 +57,7 @@ import org.apache.activemq.artemis.core.settings.impl.ResourceLimitSettings;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
 import org.apache.activemq.artemis.utils.RandomUtil;
 import org.apache.activemq.artemis.utils.critical.CriticalAnalyzerPolicy;
+import org.apache.commons.lang3.ClassUtils;
 import org.jboss.logging.Logger;
 import org.junit.Assert;
 import org.junit.Before;
@@ -599,6 +604,59 @@ public class ConfigurationImplTest extends ActiveMQTestBase {
 
    }
 
+   @Test
+   public void testRootPrimitives() throws Exception {
+      ConfigurationImpl configuration = new ConfigurationImpl();
+      Properties properties = new Properties();
+      Method[] declaredMethods = Configuration.class.getDeclaredMethods();
+      HashMap<String, Object> props = new HashMap<>();
+      int nextInt = 1;
+      long nextLong = 1;
+      // add random entries for all root primitive bean properties
+      for (Method declaredMethod : declaredMethods) {
+         if (declaredMethod.getName().startsWith("set") && declaredMethod.getAnnotation(Deprecated.class) == null &&
+                 declaredMethod.getParameterCount() == 1 && (ClassUtils.isPrimitiveOrWrapper(declaredMethod.getParameters()[0].getType())
+                 || declaredMethod.getParameters()[0].getType().equals(String.class))) {
+            String prop = declaredMethod.getName().substring(3);
+            prop = Character.toLowerCase(prop.charAt(0)) +
+                    (prop.length() > 1 ? prop.substring(1) : "");
+            Class<?> type = declaredMethod.getParameters()[0].getType();
+            if (type.equals(Boolean.class)) {
+               properties.put(prop, Boolean.TRUE);
+            } else if (type.equals(boolean.class)) {
+               properties.put(prop, true);
+            } else if (type.equals(Long.class) || type.equals(long.class)) {
+               properties.put(prop, nextLong++);
+            } else if (type.equals(Integer.class) || type.equals(int.class)) {
+               properties.put(prop, nextInt++);
+            } else if (type.equals(String.class)) {
+               byte[] array = new byte[7]; // length is bounded by 7
+               new Random().nextBytes(array);
+               String generatedString = new String(array, Charset.forName("UTF-8"));
+
+               properties.put(prop, generatedString);
+            }
+         }
+      }
+      // now parse
+      configuration.parsePrefixedProperties(properties, null);
+
+      //then call the getter to make sure it gets set
+      for (Map.Entry<Object, Object> entry : properties.entrySet()) {
+         String methodName = entry.getKey().toString();
+         methodName = Character.toUpperCase(methodName.charAt(0)) +
+                 (methodName.length() > 1 ? methodName.substring(1) : "");
+         if (entry.getValue().getClass() == Boolean.class || entry.getValue().getClass() == boolean.class) {
+            methodName = "is" + methodName;
+         } else {
+            methodName = "get" + methodName;
+         }
+
+         Method declaredMethod = ConfigurationImpl.class.getDeclaredMethod(methodName);
+         Object value = declaredMethod.invoke(configuration);
+         Assert.assertEquals(value, properties.get(entry.getKey()));
+      }
+   }
 
    @Test
    public void testSetSystemProperty() throws Throwable {