You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jb...@apache.org on 2022/12/15 19:14:29 UTC

[activemq-artemis] branch main updated: ARTEMIS-3993 changed some MB style uses to use MiB; added support for MiB/GiB/etc in config

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

jbertram 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 065e4246e1 ARTEMIS-3993 changed some MB style uses to use MiB; added support for MiB/GiB/etc in config
065e4246e1 is described below

commit 065e4246e1c2c2022d1cd0ffa021080bb140d013
Author: Erwin Dondorp <er...@cgi.com>
AuthorDate: Wed Sep 14 19:51:45 2022 +0200

    ARTEMIS-3993 changed some MB style uses to use MiB; added support for MiB/GiB/etc in config
---
 .../apache/activemq/artemis/utils/ByteUtil.java    |  6 ++--
 .../activemq/artemis/utils/SizeFormatterUtil.java  |  2 +-
 .../src/main/webapp/plugin/js/components/browse.js |  6 ++--
 .../src/main/webapp/plugin/js/components/status.js |  2 +-
 .../resources/schema/artemis-configuration.xsd     | 40 +++++++++++++---------
 .../config/impl/FileConfigurationParserTest.java   | 21 ++++++++++++
 6 files changed, 52 insertions(+), 25 deletions(-)

diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java
index b9e7741258..43783b91c9 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java
@@ -39,9 +39,9 @@ public class ByteUtil {
    private static final String prefix = "^\\s*(\\d+)\\s*";
    private static final String suffix = "(b)?\\s*$";
    private static final Pattern ONE = Pattern.compile(prefix + suffix, Pattern.CASE_INSENSITIVE);
-   private static final Pattern KILO = Pattern.compile(prefix + "k" + suffix, Pattern.CASE_INSENSITIVE);
-   private static final Pattern MEGA = Pattern.compile(prefix + "m" + suffix, Pattern.CASE_INSENSITIVE);
-   private static final Pattern GIGA = Pattern.compile(prefix + "g" + suffix, Pattern.CASE_INSENSITIVE);
+   private static final Pattern KILO = Pattern.compile(prefix + "ki?" + suffix, Pattern.CASE_INSENSITIVE);
+   private static final Pattern MEGA = Pattern.compile(prefix + "mi?" + suffix, Pattern.CASE_INSENSITIVE);
+   private static final Pattern GIGA = Pattern.compile(prefix + "gi?" + suffix, Pattern.CASE_INSENSITIVE);
    private static final String[] BYTE_SUFFIXES = new String[] {"E", "P", "T", "G", "M", "K", ""};
    private static final double[] BYTE_MAGNITUDES = new double[7];
 
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SizeFormatterUtil.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SizeFormatterUtil.java
index 23b151706c..4f3831f735 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SizeFormatterUtil.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SizeFormatterUtil.java
@@ -36,7 +36,7 @@ public class SizeFormatterUtil {
          suffix = "MiB";
       } else if (s > SizeFormatterUtil.oneKiB) {
          s /= SizeFormatterUtil.oneKiB;
-         suffix = "kiB";
+         suffix = "KiB";
       }
       return String.format("%.2f %s", s, suffix);
    }
diff --git a/artemis-hawtio/artemis-plugin/src/main/webapp/plugin/js/components/browse.js b/artemis-hawtio/artemis-plugin/src/main/webapp/plugin/js/components/browse.js
index 7b1284018f..4249973cc5 100644
--- a/artemis-hawtio/artemis-plugin/src/main/webapp/plugin/js/components/browse.js
+++ b/artemis-hawtio/artemis-plugin/src/main/webapp/plugin/js/components/browse.js
@@ -554,9 +554,9 @@ var Artemis;
         function formatPersistentSize(bytes) {
             if(isNaN(bytes) || typeof bytes !== "number" || bytes < 0) return "N/A";
             if(bytes < 10240) return bytes.toLocaleString() + " Bytes";
-            if(bytes < 1048576) return (bytes / 1024).toFixed(2) + " KB";
-            if(bytes < 1073741824) return (bytes / 1048576).toFixed(2) + " MB";
-            return (bytes / 1073741824).toFixed(2) + " GB";
+            if(bytes < 1048576) return (bytes / 1024).toFixed(2) + " KiB";
+            if(bytes < 1073741824) return (bytes / 1048576).toFixed(2) + " MiB";
+            return (bytes / 1073741824).toFixed(2) + " GiB";
         }
 
         ctrl.openMoveDialog = function () {
diff --git a/artemis-hawtio/artemis-plugin/src/main/webapp/plugin/js/components/status.js b/artemis-hawtio/artemis-plugin/src/main/webapp/plugin/js/components/status.js
index 42d44c8cc6..460716fe06 100644
--- a/artemis-hawtio/artemis-plugin/src/main/webapp/plugin/js/components/status.js
+++ b/artemis-hawtio/artemis-plugin/src/main/webapp/plugin/js/components/status.js
@@ -104,7 +104,7 @@ var Artemis;
         };
         ctrl.addressMemoryConfig = {
             'chartId': 'addressMemoryChart',
-            'units': 'MB',
+            'units': 'MiB',
             'thresholds':{'warning':'75','error':'90'}
         };
 
diff --git a/artemis-server/src/main/resources/schema/artemis-configuration.xsd b/artemis-server/src/main/resources/schema/artemis-configuration.xsd
index 8615b1c1d6..9288343e19 100644
--- a/artemis-server/src/main/resources/schema/artemis-configuration.xsd
+++ b/artemis-server/src/main/resources/schema/artemis-configuration.xsd
@@ -736,7 +736,7 @@
                               Notice we first remove files based on period and if you're using more storage then you
                               configured we start removing older files.
                               By default this is unlimited (not filled).
-                              Supports byte notation like "K", "Mb", "GB", etc.
+                              Supports byte notation like "K", "Mb", "MiB", "GB", etc.
                            </xsd:documentation>
                         </xsd:annotation>
                      </xsd:attribute>
@@ -797,8 +797,8 @@
          <xsd:element name="journal-buffer-size" type="xsd:string" default="501760" maxOccurs="1" minOccurs="0">
             <xsd:annotation>
                <xsd:documentation>
-                  The size (in bytes) of the internal buffer on the journal. Supports byte notation like "K", "Mb",
-                  "GB", etc.
+                  The size (in bytes) of the internal buffer on the journal.
+                  Supports byte notation like "K", "Mb", "MiB", "GB", etc.
                </xsd:documentation>
             </xsd:annotation>
          </xsd:element>
@@ -832,7 +832,8 @@
          <xsd:element name="journal-file-size" default="10485760" type="xsd:string" maxOccurs="1" minOccurs="0">
             <xsd:annotation>
                <xsd:documentation>
-                  The size (in bytes) of each journal file. Supports byte notation like "K", "Mb", "GB", etc.
+                  The size (in bytes) of each journal file.
+                  Supports byte notation like "K", "Mb", "MiB", "GB", etc.
                </xsd:documentation>
             </xsd:annotation>
          </xsd:element>
@@ -907,7 +908,8 @@
             <xsd:annotation>
                <xsd:documentation>
                   Size (in bytes) before all addresses will enter into their Full Policy configured upon messages being
-                  produced. Supports byte notation like "K", "Mb", "GB", etc.
+                  produced.
+                  Supports byte notation like "K", "Mb", "MiB", "GB", etc.
                </xsd:documentation>
             </xsd:annotation>
          </xsd:element>
@@ -1619,7 +1621,8 @@
             <xsd:annotation>
                <xsd:documentation>
                   Any message larger than this size (in bytes) is considered a large message (to be sent in
-                  chunks). Supports byte notation like "K", "Mb", "GB", etc.
+                  chunks).
+                  Supports byte notation like "K", "Mb", "MiB", "GB", etc.
                </xsd:documentation>
             </xsd:annotation>
          </xsd:element>
@@ -1703,8 +1706,8 @@
          <xsd:element name="confirmation-window-size" type="xsd:string" maxOccurs="1" minOccurs="0" default="1048576">
             <xsd:annotation>
                <xsd:documentation>
-                  Once the bridge has received this many bytes, it sends a confirmation. Supports byte notation like
-                  "K", "Mb", "GB", etc.
+                  Once the bridge has received this many bytes, it sends a confirmation.
+                  Supports byte notation like "K", "Mb", "MiB", "GB", etc.
                </xsd:documentation>
             </xsd:annotation>
          </xsd:element>
@@ -1712,7 +1715,8 @@
          <xsd:element name="producer-window-size" type="xsd:string" maxOccurs="1" minOccurs="0" default="1048576">
             <xsd:annotation>
                <xsd:documentation>
-                  Producer flow control. Supports byte notation like "K", "Mb", "GB", etc.
+                  Producer flow control.
+                  Supports byte notation like "K", "Mb", "MiB", "GB", etc.
                </xsd:documentation>
             </xsd:annotation>
          </xsd:element>
@@ -2510,8 +2514,8 @@
          <xsd:element name="min-large-message-size" type="xsd:string" maxOccurs="1" minOccurs="0">
             <xsd:annotation>
                <xsd:documentation>
-                  Messages larger than this are considered large-messages. Supports byte notation like
-                  "K", "Mb", "GB", etc.
+                  Messages larger than this are considered large-messages.
+                  Supports byte notation like "K", "Mb", "MiB", "GB", etc.
                </xsd:documentation>
             </xsd:annotation>
          </xsd:element>
@@ -2608,8 +2612,8 @@
          <xsd:element name="confirmation-window-size" type="xsd:string" default="1048576" maxOccurs="1" minOccurs="0">
             <xsd:annotation>
                <xsd:documentation>
-                  The size (in bytes) of the window used for confirming data from the server connected to. Supports
-                  byte notation like "K", "Mb", "GB", etc.
+                  The size (in bytes) of the window used for confirming data from the server connected to.
+                  Supports byte notation like "K", "Mb", "MiB", "GB", etc.
                </xsd:documentation>
             </xsd:annotation>
          </xsd:element>
@@ -2617,7 +2621,8 @@
          <xsd:element name="producer-window-size" type="xsd:string" maxOccurs="1" minOccurs="0" default="1048576">
             <xsd:annotation>
                <xsd:documentation>
-                  Producer flow control. Supports byte notation like "K", "Mb", "GB", etc.
+                  Producer flow control.
+                  Supports byte notation like "K", "Mb", "MiB", "GB", etc.
                </xsd:documentation>
             </xsd:annotation>
          </xsd:element>
@@ -3955,7 +3960,8 @@
                <xsd:annotation>
                   <xsd:documentation>
                      the maximum size (in bytes) for an address (-1 means no limits). This is used in PAGING, BLOCK and
-                     FAIL policies. Supports byte notation like "K", "Mb", "GB", etc.
+                     FAIL policies.
+                     Supports byte notation like "K", "Mb", "MiB", "GB", etc.
                   </xsd:documentation>
                </xsd:annotation>
             </xsd:element>
@@ -3982,8 +3988,8 @@
             <xsd:element name="page-size-bytes" type="xsd:string" default="10485760" maxOccurs="1" minOccurs="0">
                <xsd:annotation>
                   <xsd:documentation>
-                     The page size (in bytes) to use for an address. Supports byte notation like "K", "Mb",
-                     "GB", etc.
+                     The page size (in bytes) to use for an address.
+                     Supports byte notation like "K", "Mb", "MiB", "GB", etc.
                   </xsd:documentation>
                </xsd:annotation>
             </xsd:element>
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationParserTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationParserTest.java
index 88a1000cf2..e69bf520e1 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationParserTest.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationParserTest.java
@@ -525,6 +525,27 @@ public class FileConfigurationParserTest extends ActiveMQTestBase {
 
    }
 
+   @Test
+   public void testNotations() throws Exception {
+      StringPrintStream stringPrintStream = new StringPrintStream();
+      PrintStream stream = stringPrintStream.newStream();
+
+      stream.println("<configuration><core>");
+      stream.println("<global-max-size>100MiB</global-max-size>");
+      stream.println("<journal-file-size>10M</journal-file-size>");
+      stream.println("<journal-buffer-size>5Mb</journal-buffer-size>");
+      stream.println("</core></configuration>");
+
+      ByteArrayInputStream inputStream = new ByteArrayInputStream(stringPrintStream.getBytes());
+      FileConfigurationParser parser = new FileConfigurationParser();
+      Configuration configuration = parser.parseMainConfig(inputStream);
+
+      // check that suffixes were interpreted well
+      Assert.assertEquals(100 * 1024 * 1024, configuration.getGlobalMaxSize());
+      Assert.assertEquals(10 * 1024 * 1024, configuration.getJournalFileSize());
+      Assert.assertEquals(5 * 1024 * 1024, configuration.getJournalBufferSize_NIO());
+   }
+
    @Test
    public void testRetentionJournalOptionsDays() throws Exception {
       testStreamDatesOption("DAYS", TimeUnit.DAYS);