From 9383c6d697658f6ac7902e621124649b510b6bb3 Mon Sep 17 00:00:00 2001 From: Gary Tully Date: Thu, 14 May 2009 09:57:24 +0000 Subject: [PATCH] resolve alternative path to https://issues.apache.org/activemq/browse/AMQ-2241 via ra where connection is reused. state tracker was not notified when remove command is suppressed and simulated during transport outage git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@774712 13f79535-47bb-0310-9956-ffa450edef68 --- .../transport/failover/FailoverTransport.java | 1 + .../ra/FailoverManagedConnectionTest.java | 102 ++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100755 activemq-ra/src/test/java/org/apache/activemq/ra/FailoverManagedConnectionTest.java diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java b/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java index 77f7f04541..dd6010b56a 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java @@ -397,6 +397,7 @@ public class FailoverTransport implements CompositeTransport { } if(command instanceof RemoveInfo) { // Simulate response to RemoveInfo command + stateTracker.track(command); Response response = new Response(); response.setCorrelationId(command.getCommandId()); myTransportListener.onCommand(response); diff --git a/activemq-ra/src/test/java/org/apache/activemq/ra/FailoverManagedConnectionTest.java b/activemq-ra/src/test/java/org/apache/activemq/ra/FailoverManagedConnectionTest.java new file mode 100755 index 0000000000..49661eba67 --- /dev/null +++ b/activemq-ra/src/test/java/org/apache/activemq/ra/FailoverManagedConnectionTest.java @@ -0,0 +1,102 @@ +/** + * 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.ra; + +import java.util.HashSet; + +import javax.resource.spi.ManagedConnection; + +import junit.framework.TestCase; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerService; + + +public class FailoverManagedConnectionTest extends TestCase { + + private static final String BROKER_TRANSPORT = "tcp://localhost:61616"; + private static final String BROKER_URL = "failover://" + BROKER_TRANSPORT; + + private ActiveMQManagedConnectionFactory managedConnectionFactory; + private ManagedConnection managedConnection; + private ManagedConnectionProxy proxy; + private BrokerService broker; + private HashSet connections; + private ActiveMQConnectionRequestInfo connectionInfo; + + protected void setUp() throws Exception { + + createAndStartBroker(); + + connectionInfo = new ActiveMQConnectionRequestInfo(); + connectionInfo.setServerUrl(BROKER_URL); + connectionInfo.setUserName(ActiveMQConnectionFactory.DEFAULT_USER); + connectionInfo.setPassword(ActiveMQConnectionFactory.DEFAULT_PASSWORD); + + managedConnectionFactory = new ActiveMQManagedConnectionFactory(); + managedConnection = managedConnectionFactory.createManagedConnection(null, connectionInfo); + + connections = new HashSet(); + connections.add(managedConnection); + } + + + private void createAndStartBroker() throws Exception { + broker = new BrokerService(); + broker.addConnector(BROKER_TRANSPORT); + broker.start(); + broker.waitUntilStarted(); + } + + public void testFailoverBeforeClose() throws Exception { + + createConnectionAndProxyAndSession(); + + stopBroker(); + + cleanupConnectionAndProxyAndSession(); + + createAndStartBroker(); + + for (int i=0; i<2; i++) { + createConnectionAndProxyAndSession(); + cleanupConnectionAndProxyAndSession(); + } + } + + + private void cleanupConnectionAndProxyAndSession() throws Exception { + proxy.close(); + managedConnection.cleanup(); + } + + + private void createConnectionAndProxyAndSession() throws Exception { + managedConnection = + managedConnectionFactory.matchManagedConnections(connections, null, connectionInfo); + proxy = + (ManagedConnectionProxy) managedConnection.getConnection(null, null); + proxy.createSession(false, 0); + } + + + private void stopBroker() throws Exception { + broker.stop(); + broker.waitUntilStopped(); + } + +}