[ 
https://issues.apache.org/jira/browse/ARTEMIS-4930?focusedWorklogId=927120&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-927120
 ]

ASF GitHub Bot logged work on ARTEMIS-4930:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 23/Jul/24 21:04
            Start Date: 23/Jul/24 21:04
    Worklog Time Spent: 10m 
      Work Description: jbertram commented on code in PR #5109:
URL: https://github.com/apache/activemq-artemis/pull/5109#discussion_r1688727615


##########
artemis-server/src/test/java/org/apache/activemq/artemis/core/config/BridgeConfigurationEncodingTest.java:
##########
@@ -0,0 +1,522 @@
+/*
+ * 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.artemis.core.config;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
+import org.apache.activemq.artemis.api.core.ActiveMQBuffers;
+import 
org.apache.activemq.artemis.core.server.ComponentConfigurationRoutingType;
+import org.apache.activemq.artemis.utils.DataConstants;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class BridgeConfigurationEncodingTest {
+
+   @Test
+   public void testEncodedBytesWithTransformer() {
+      doEncodedBytesTestImpl(true, true);
+   }
+
+   @Test
+   public void testEncodedBytesWithTransformerWithNoProperties() {
+      doEncodedBytesTestImpl(true, false);
+   }
+
+   @Test
+   public void testEncodedBytesWithoutTransformer() {
+      doEncodedBytesTestImpl(false, false);
+   }
+
+   private void doEncodedBytesTestImpl(final boolean transformer, boolean 
properties) {
+      if (properties && !transformer) {
+         throw new IllegalArgumentException("Must have transformer to have 
properties for it");
+      }
+
+      final String name = "aa";
+      final String parentName = "bb";
+      final String queueName = "cc";
+      final String forwardingAddress = "dd";
+      final String filterString = "ee";
+      final String discoveryGroup = "ff";
+      final boolean ha = true;
+      final long retryInterval = 0L;
+      final double retryIntervalMultiplier = 0.0;
+      final int initialConnectAttempts = 0;
+      final int reconnectAttempts = 1;
+      final int reconnectAttemptsOnSameNode = 2;
+      final boolean useDuplicateDetection = false;
+      final int confirmationWindowSize = 3;
+      final int producerWindowSize = 4;
+      final long clientFailureCheckPeriod = 1L;
+      final String user = "gg";
+      final String password = "hh";
+      final long connectionTtl = 2L;
+      final long maxRetryInterval = 3L;
+      final int minLargeMessageSize = 5;
+      final long callTimeout = 4L;
+      final int concurrency = 6;
+      final boolean configurationManaged = false;
+      final ComponentConfigurationRoutingType routingType = 
ComponentConfigurationRoutingType.ANYCAST;
+      final long pendingAckTimeout = 5L;
+      final String staticConnector = "ii";
+
+      BridgeConfiguration configuration = new BridgeConfiguration()
+         .setName(name)
+         .setParentName(parentName)
+         .setQueueName(queueName)
+         .setForwardingAddress(forwardingAddress)
+         .setFilterString(filterString)
+         .setDiscoveryGroupName(discoveryGroup)
+         .setHA(ha)
+         .setRetryInterval(retryInterval)
+         .setRetryIntervalMultiplier(retryIntervalMultiplier)
+         .setInitialConnectAttempts(initialConnectAttempts)
+         .setReconnectAttempts(reconnectAttempts)
+         .setReconnectAttemptsOnSameNode(reconnectAttemptsOnSameNode)
+         .setUseDuplicateDetection(useDuplicateDetection)
+         .setConfirmationWindowSize(confirmationWindowSize)
+         .setProducerWindowSize(producerWindowSize)
+         .setClientFailureCheckPeriod(clientFailureCheckPeriod)
+         .setUser(user)
+         .setPassword(password)
+         .setConnectionTTL(connectionTtl)
+         .setMaxRetryInterval(maxRetryInterval)
+         .setMinLargeMessageSize(minLargeMessageSize)
+         .setCallTimeout(callTimeout)
+         .setConcurrency(concurrency)
+         .setConfigurationManaged(configurationManaged)
+         .setRoutingType(routingType);
+
+      if (transformer) {
+         final String transformerClass = "jj";
+         final TransformerConfiguration myDivertTransformer = new 
TransformerConfiguration(transformerClass);
+
+         if (properties) {
+            final String transformerKey = "kk";
+            final String transformerValue = "ll";
+            myDivertTransformer.getProperties().put(transformerKey, 
transformerValue);
+         }
+
+         configuration.setTransformerConfiguration(myDivertTransformer);
+      }
+
+      configuration.setStaticConnectors(List.of(staticConnector))
+                   .setPendingAckTimeout(pendingAckTimeout);
+
+      int encodeSize = configuration.getEncodeSize();
+      ActiveMQBuffer data = ActiveMQBuffers.fixedBuffer(encodeSize);
+      configuration.encode(data);
+      assertEquals(encodeSize, data.writerIndex());
+
+      // name
+      byte[] read = new byte[9];
+      data.readBytes(read, 0, 9);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 2, 0, 97, 
0, 97}, read);
+
+      // parentName
+      read = new byte[9];
+      data.readBytes(read, 0, 9);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 2, 0, 98, 
0, 98}, read);
+
+      // queueName
+      read = new byte[9];
+      data.readBytes(read, 0, 9);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 2, 0, 99, 
0, 99}, read);
+
+      // forwardingAddress
+      read = new byte[9];
+      data.readBytes(read, 0, 9);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 2, 0, 
100, 0, 100}, read);
+
+      // filterString
+      read = new byte[9];
+      data.readBytes(read, 0, 9);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 2, 0, 
101, 0, 101}, read);
+
+      // discoveryGroup
+      read = new byte[9];
+      data.readBytes(read, 0, 9);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 2, 0, 
102, 0, 102}, read);
+
+      // ha
+      read = new byte[2];
+      data.readBytes(read, 0, 2);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, -1}, read);
+
+      // retryInterval
+      read = new byte[9];
+      data.readBytes(read, 0, 9);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 0, 0, 0, 
0, 0}, read);
+
+      // retryIntervalMultiplier
+      read = new byte[9];
+      data.readBytes(read, 0, 9);
+      assertArrayEquals(new byte[] {-1, 0, 0, 0, 0, 0, 0, 0, 0}, read);
+
+      // initialConnectAttempts
+      read = new byte[5];
+      data.readBytes(read, 0, 5);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 0}, read);
+
+      // reconnectAttempts
+      read = new byte[5];
+      data.readBytes(read, 0, 5);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 1}, read);
+
+      // reconnectAttemptsOnSameNode
+      read = new byte[5];
+      data.readBytes(read, 0, 5);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 2}, read);
+
+      // useDuplicateDetection
+      read = new byte[2];
+      data.readBytes(read, 0, 2);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0}, read);
+
+      // confirmationWindowSize
+      read = new byte[5];
+      data.readBytes(read, 0, 5);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 3}, read);
+
+      // producerWindowSize
+      read = new byte[5];
+      data.readBytes(read, 0, 5);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 4}, read);
+
+      // clientFailureCheckPeriod
+      read = new byte[9];
+      data.readBytes(read, 0, 9);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 0, 0, 0, 
0, 1}, read);
+
+      // user
+      read = new byte[9];
+      data.readBytes(read, 0, 9);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 2, 0, 
103, 0, 103}, read);
+
+      // password
+      read = new byte[9];
+      data.readBytes(read, 0, 9);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 2, 0, 
104, 0, 104}, read);
+
+      // connectionTtl
+      read = new byte[9];
+      data.readBytes(read, 0, 9);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 0, 0, 0, 
0, 2}, read);
+
+      // maxRetryInterval
+      read = new byte[9];
+      data.readBytes(read, 0, 9);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 0, 0, 0, 
0, 3}, read);
+
+      // minLargeMessageSize
+      read = new byte[5];
+      data.readBytes(read, 0, 5);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 5}, read);
+
+      // callTimeout
+      read = new byte[9];
+      data.readBytes(read, 0, 9);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 0, 0, 0, 
0, 4}, read);
+
+      // concurrency
+      read = new byte[5];
+      data.readBytes(read, 0, 5);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 6}, read);
+
+      // configurationManaged
+      read = new byte[2];
+      data.readBytes(read, 0, 2);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0}, read);
+
+      // routingType
+      assertEquals(ComponentConfigurationRoutingType.ANYCAST.getType(), 
data.readByte());
+
+      if (transformer) {
+         // transformerClassName
+         read = new byte[9];
+         data.readBytes(read, 0, 9);
+         assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 2, 0, 
106, 0, 106}, read);
+
+         if (properties) {
+            // number of transformer properties
+            read = new byte[4];
+            data.readBytes(read, 0, 4);
+            assertArrayEquals(new byte[] {0, 0, 0, 1}, read);
+
+            // transformer key name
+            read = new byte[9];
+            data.readBytes(read, 0, 9);
+            assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 2, 
0, 107, 0, 107}, read);
+
+            // transformer key value
+            read = new byte[9];
+            data.readBytes(read, 0, 9);
+            assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 2, 
0, 108, 0, 108}, read);
+         } else {
+            // transformer properties not present (indicated via 0 count)
+            read = new byte[4];
+            data.readBytes(read, 0, 4);
+            assertArrayEquals(new byte[] {0, 0, 0, 0}, read);
+         }
+      } else {
+         // transformer not present
+         assertEquals(DataConstants.NULL, data.readByte());
+      }
+
+      // staticConnector count
+      read = new byte[4];
+      data.readBytes(read, 0, 4);
+      assertArrayEquals(new byte[] {0, 0, 0, 1}, read);
+
+      // static connector
+      read = new byte[9];
+      data.readBytes(read, 0, 9);
+      assertArrayEquals(new byte[] {DataConstants.NOT_NULL, 0, 0, 0, 2, 0, 
105, 0, 105}, read);

Review Comment:
   Tests added.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 927120)
    Time Spent: 0.5h  (was: 20m)

> Refactor storage manager tests
> ------------------------------
>
>                 Key: ARTEMIS-4930
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-4930
>             Project: ActiveMQ Artemis
>          Issue Type: Improvement
>            Reporter: Justin Bertram
>            Assignee: Justin Bertram
>            Priority: Major
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to