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 24dde9d4b5 ARTEMIS-4354 Allow the recovery XAResource to close and
reconnect the underlying ClientSession if the connection configuration has
changed.
24dde9d4b5 is described below
commit 24dde9d4b56e53df4dd0113f19452c0b97464d31
Author: Emmanuel Hugonnet <[email protected]>
AuthorDate: Mon Jul 17 17:55:56 2023 +0200
ARTEMIS-4354 Allow the recovery XAResource to close and reconnect the
underlying ClientSession if the connection configuration has changed.
Signed-off-by: Emmanuel Hugonnet <[email protected]>
---
.../xa/recovery/ActiveMQXAResourceWrapper.java | 7 +++++++
.../unit/ra/ActiveMQXAResourceWrapperTest.java | 21 ++++++++++++++++++---
2 files changed, 25 insertions(+), 3 deletions(-)
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 d672b7c5ab..219ec8c433 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
@@ -67,6 +67,13 @@ public class ActiveMQXAResourceWrapper implements
XAResource, SessionFailureList
}
}
+ public void updateRecoveryConfig(XARecoveryConfig... xaRecoveryConfigs) {
+ synchronized (ActiveMQXAResourceWrapper.lock) {
+ close();
+ this.xaRecoveryConfigs = xaRecoveryConfigs;
+ }
+ }
+
@Override
public Xid[] recover(final int flag) throws XAException {
XAResource xaResource = getDelegate(false);
diff --git
a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/ActiveMQXAResourceWrapperTest.java
b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/ActiveMQXAResourceWrapperTest.java
index f344c2c80d..8734182fa0 100644
---
a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/ActiveMQXAResourceWrapperTest.java
+++
b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/ActiveMQXAResourceWrapperTest.java
@@ -17,6 +17,8 @@
package org.apache.activemq.artemis.tests.unit.ra;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.activemq.artemis.api.core.client.ClientSession;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.ra.ActiveMQResourceAdapter;
@@ -26,6 +28,8 @@ import
org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.junit.Test;
import javax.transaction.xa.XAResource;
+import org.apache.activemq.artemis.api.core.TransportConfiguration;
+import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
public class ActiveMQXAResourceWrapperTest extends ActiveMQTestBase {
@@ -45,8 +49,8 @@ public class ActiveMQXAResourceWrapperTest extends
ActiveMQTestBase {
ra.setConnectionTTL(4000L);
ra.start(new BootstrapContext());
-
- TestActiveMQXAResourceWrapper wrapper = new
TestActiveMQXAResourceWrapper(ra.getRecoveryManager().getResources().toArray(new
XARecoveryConfig[]{}));
+ XARecoveryConfig[] configs =
ra.getRecoveryManager().getResources().toArray(new XARecoveryConfig[]{});
+ TestActiveMQXAResourceWrapper wrapper = new
TestActiveMQXAResourceWrapper(configs);
XAResource res = wrapper.connect();
if (!(res instanceof ClientSession)) {
@@ -54,7 +58,18 @@ public class ActiveMQXAResourceWrapperTest extends
ActiveMQTestBase {
}
cs = (ClientSession) res;
assertEquals(4000L,
cs.getSessionFactory().getServerLocator().getConnectionTTL());
-
+ Map<String, Object> params = new HashMap<>();
+ params.put(TransportConstants.HOST_PROP_NAME, "localhost");
+ params.put(TransportConstants.PORT_PROP_NAME, 61616);
+ params.put(TransportConstants.CONNECTION_TTL, 60000L);
+ XARecoveryConfig backup = new XARecoveryConfig(true, new
TransportConfiguration[] {new TransportConfiguration(NETTY_CONNECTOR_FACTORY,
params)}, null, null, null, configs[0].getClientProtocolManager());
+ wrapper.updateRecoveryConfig(backup);
+ res = wrapper.connect();
+ if (!(res instanceof ClientSession)) {
+ fail("Unexpected XAResource type");
+ }
+ cs = (ClientSession) res;
+ assertEquals(60000L,
cs.getSessionFactory().getServerLocator().getConnectionTTL());
} finally {
if (cs != null)
cs.close();