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

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

commit 5e080aa3694458fb4fc21187b549bb82077dd729
Author: Justin Bertram <[email protected]>
AuthorDate: Tue Feb 4 13:23:27 2025 -0600

    ARTEMIS-5297 extract common code from if branches
---
 .../protocol/amqp/broker/AMQPStandardMessage.java  |  8 +++-----
 .../connect/mirror/AMQPMirrorControllerTarget.java |  6 ++----
 .../remoting/impl/netty/HttpAcceptorHandler.java   |  6 ++----
 .../xa/recovery/ActiveMQXAResourceWrapper.java     | 22 ++++++++--------------
 .../tests/integration/client/LargeMessageTest.java |  9 +++------
 .../artemis/tests/integration/stomp/StompTest.java |  7 ++-----
 .../tests/integration/stomp/v11/StompV11Test.java  |  3 +--
 .../tests/integration/stomp/v12/StompV12Test.java  |  3 +--
 8 files changed, 22 insertions(+), 42 deletions(-)

diff --git 
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPStandardMessage.java
 
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPStandardMessage.java
index b1e8af0523..5e99ae398a 100644
--- 
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPStandardMessage.java
+++ 
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPStandardMessage.java
@@ -193,15 +193,13 @@ public class AMQPStandardMessage extends AMQPMessage {
    public int getMemoryEstimate() {
       if (memoryEstimate == -1) {
          if (isPaged) {
-            // When the message is paged, we don't take the unmarshalled 
application properties
-            // because it could be updated at different places.
-            // we just keep the estimate simple when paging
+            // When the message is paged, we don't take the unmarshalled 
application properties because it could be
+            // updated at different places. We just keep the estimate simple 
when paging.
             memoryEstimate = memoryOffset + (data != null ? data.capacity() : 
0);
-            originalEstimate = memoryEstimate;
          } else {
             memoryEstimate = memoryOffset + (data != null ? data.capacity() + 
unmarshalledApplicationPropertiesMemoryEstimateFromData(data) : 0);
-            originalEstimate = memoryEstimate;
          }
+         originalEstimate = memoryEstimate;
       }
 
       return memoryEstimate;
diff --git 
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/connect/mirror/AMQPMirrorControllerTarget.java
 
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/connect/mirror/AMQPMirrorControllerTarget.java
index 7bbf7203c1..5c4304c474 100644
--- 
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/connect/mirror/AMQPMirrorControllerTarget.java
+++ 
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/connect/mirror/AMQPMirrorControllerTarget.java
@@ -512,16 +512,14 @@ public class AMQPMirrorControllerTarget extends 
ProtonAbstractReceiver implement
       routingContext.setDuplicateDetection(false); // we do our own duplicate 
detection here
 
       DuplicateIDCache duplicateIDCache;
-      if (lruDuplicateIDKey != null && 
lruDuplicateIDKey.equals(internalMirrorID)) {
-         duplicateIDCache = lruduplicateIDCache;
-      } else {
+      if (lruDuplicateIDKey == null || 
!lruDuplicateIDKey.equals(internalMirrorID)) {
          // we use the number of credits for the duplicate detection, as that 
means the maximum number of elements you can have pending
          logger.trace("Setting up duplicate detection cache on {}, ServerID={} 
with {} elements, being the number of credits", 
ProtonProtocolManager.MIRROR_ADDRESS, internalMirrorID, 
connection.getAmqpCredits());
 
          lruDuplicateIDKey = internalMirrorID;
          lruduplicateIDCache = 
server.getPostOffice().getDuplicateIDCache(SimpleString.of(ProtonProtocolManager.MIRROR_ADDRESS
 + "_" + internalMirrorID), connection.getAmqpCredits());
-         duplicateIDCache = lruduplicateIDCache;
       }
+      duplicateIDCache = lruduplicateIDCache;
 
       byte[] duplicateIDBytes = ByteUtil.longToBytes(internalIDLong);
 
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/HttpAcceptorHandler.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/HttpAcceptorHandler.java
index 1b230cc7a1..22d9d9eb3c 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/HttpAcceptorHandler.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/HttpAcceptorHandler.java
@@ -154,13 +154,11 @@ public class HttpAcceptorHandler extends 
ChannelDuplexHandler {
          while (responseHolder == null);
          if (!bogusResponse) {
             piggyBackResponses(responseHolder.response.content());
-            
responseHolder.response.headers().set(HttpHeaderNames.CONTENT_LENGTH, 
String.valueOf(responseHolder.response.content().readableBytes()));
-            channel.writeAndFlush(responseHolder.response, promise);
          } else {
             responseHolder.response.content().writeBytes(buffer);
-            
responseHolder.response.headers().set(HttpHeaderNames.CONTENT_LENGTH, 
String.valueOf(responseHolder.response.content().readableBytes()));
-            channel.writeAndFlush(responseHolder.response, promise);
          }
+         responseHolder.response.headers().set(HttpHeaderNames.CONTENT_LENGTH, 
String.valueOf(responseHolder.response.content().readableBytes()));
+         channel.writeAndFlush(responseHolder.response, promise);
 
          buffer.release();
 
diff --git 
a/artemis-service-extensions/src/main/java/org/apache/activemq/artemis/service/extensions/xa/recovery/ActiveMQXAResourceWrapper.java
 
b/artemis-service-extensions/src/main/java/org/apache/activemq/artemis/service/extensions/xa/recovery/ActiveMQXAResourceWrapper.java
index 1e30b017b7..029a6b1492 100644
--- 
a/artemis-service-extensions/src/main/java/org/apache/activemq/artemis/service/extensions/xa/recovery/ActiveMQXAResourceWrapper.java
+++ 
b/artemis-service-extensions/src/main/java/org/apache/activemq/artemis/service/extensions/xa/recovery/ActiveMQXAResourceWrapper.java
@@ -235,26 +235,20 @@ public class ActiveMQXAResourceWrapper implements 
XAResource, SessionFailureList
       if (result == null) {
          // we should always throw a retry for certain methods commit etc, if 
not the tx is marked as a heuristic and
          // all chaos is let loose
+         XAException xae;
          if (retry) {
-            XAException xae = new XAException("Connection unavailable for xa 
recovery");
+            xae = new XAException("Connection unavailable for xa recovery");
             xae.errorCode = XAException.XA_RETRY;
-            if (error != null) {
-               xae.initCause(error);
-            }
-            logger.debug("Cannot get connectionFactory XAResource", xae);
-
-            throw xae;
          } else {
-            XAException xae = new XAException("Error trying to connect to any 
providers for xa recovery");
+            xae = new XAException("Error trying to connect to any providers 
for xa recovery");
             xae.errorCode = XAException.XAER_RMFAIL;
-            if (error != null) {
-               xae.initCause(error);
-            }
-            logger.debug("Cannot get connectionFactory XAResource", xae);
-
-            throw xae;
          }
 
+         if (error != null) {
+            xae.initCause(error);
+         }
+         logger.debug("Cannot get connectionFactory XAResource", xae);
+         throw xae;
       }
 
       return result;
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/LargeMessageTest.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/LargeMessageTest.java
index fd3db5f310..480b13ed75 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/LargeMessageTest.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/LargeMessageTest.java
@@ -1882,18 +1882,15 @@ public class LargeMessageTest extends 
LargeMessageTestBase {
             clientMessage.acknowledge();
 
             if (isXA) {
+               session.end(xid, XAResource.TMSUCCESS);
                if (i == 0) {
-                  session.end(xid, XAResource.TMSUCCESS);
                   session.prepare(xid);
                   session.rollback(xid);
-                  xid = newXID();
-                  session.start(xid, XAResource.TMNOFLAGS);
                } else {
-                  session.end(xid, XAResource.TMSUCCESS);
                   session.commit(xid, true);
-                  xid = newXID();
-                  session.start(xid, XAResource.TMNOFLAGS);
                }
+               xid = newXID();
+               session.start(xid, XAResource.TMNOFLAGS);
             } else {
                if (i == 0) {
                   session.rollback();
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTest.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTest.java
index caae468d9d..33aff339db 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTest.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTest.java
@@ -1082,12 +1082,9 @@ public class StompTest extends StompTestBase {
 
       if (sendDisconnect) {
          conn.disconnect();
-         conn.destroy();
-         conn = StompClientConnectionFactory.createClientConnection(uri);
-      } else {
-         conn.destroy();
-         conn = StompClientConnectionFactory.createClientConnection(uri);
       }
+      conn.destroy();
+      conn = StompClientConnectionFactory.createClientConnection(uri);
 
       // message should be received since message was not acknowledged
       conn.connect(defUser, defPass);
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v11/StompV11Test.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v11/StompV11Test.java
index 4716fdc5d4..3337cc7159 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v11/StompV11Test.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v11/StompV11Test.java
@@ -2289,11 +2289,10 @@ public class StompV11Test extends StompTestBase {
 
       if (sendDisconnect) {
          conn.disconnect();
-         conn = StompClientConnectionFactory.createClientConnection(uri);
       } else {
          conn.destroy();
-         conn = StompClientConnectionFactory.createClientConnection(uri);
       }
+      conn = StompClientConnectionFactory.createClientConnection(uri);
 
       // message should be received since message was not acknowledged
       conn.connect(defUser, defPass);
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v12/StompV12Test.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v12/StompV12Test.java
index 960f03727c..9d9465bf1a 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v12/StompV12Test.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v12/StompV12Test.java
@@ -2272,11 +2272,10 @@ public class StompV12Test extends StompTestBase {
 
       if (sendDisconnect) {
          conn.disconnect();
-         conn = (StompClientConnectionV12) 
StompClientConnectionFactory.createClientConnection(uri);
       } else {
          conn.destroy();
-         conn = (StompClientConnectionV12) 
StompClientConnectionFactory.createClientConnection(uri);
       }
+      conn = (StompClientConnectionV12) 
StompClientConnectionFactory.createClientConnection(uri);
 
       // message should be received since message was not acknowledged
       conn.connect(defUser, defPass);


---------------------------------------------------------------------
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