Skip to content

Commit

Permalink
ARTEMIS-4354 Allow the recovery XAResource to close and reconnect the…
Browse files Browse the repository at this point in the history
… underlying ClientSession if the connection configuration has changed.

Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
  • Loading branch information
ehsavoie authored and clebertsuconic committed Jul 18, 2023
1 parent 677d71b commit 24dde9d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public ActiveMQXAResourceWrapper(XARecoveryConfig... xaRecoveryConfigs) {
}
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +28,8 @@
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 {

Expand All @@ -45,16 +49,27 @@ public void testMe() throws Exception {
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)) {
fail("Unexpected XAResource type");
}
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();
Expand Down

0 comments on commit 24dde9d

Please sign in to comment.