https://issues.apache.org/jira/browse/AMQ-3912 - Durable subs store messages in error with broker attribute persistent="false" - fix with test

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1356724 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2012-07-03 13:31:32 +00:00
parent ae5bd2ec3c
commit ae816dcb3f
2 changed files with 94 additions and 0 deletions

View File

@ -1036,6 +1036,10 @@ public class BrokerService implements Service {
* @throws IOException * @throws IOException
*/ */
public void setPersistenceAdapter(PersistenceAdapter persistenceAdapter) throws IOException { public void setPersistenceAdapter(PersistenceAdapter persistenceAdapter) throws IOException {
if (!isPersistent() && ! (persistenceAdapter instanceof MemoryPersistenceAdapter)) {
LOG.warn("persistent=\"false\", ignoring configured persistenceAdapter: " + persistenceAdapter);
return;
}
this.persistenceAdapter = persistenceAdapter; this.persistenceAdapter = persistenceAdapter;
configureService(this.persistenceAdapter); configureService(this.persistenceAdapter);
this.persistenceAdapter = registerPersistenceAdapterMBean(persistenceAdapter); this.persistenceAdapter = registerPersistenceAdapterMBean(persistenceAdapter);

View File

@ -0,0 +1,90 @@
/**
* 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.broker;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import junit.framework.Test;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.transport.failover.FailoverTransport;
public class DurablePersistentFalseRestartTest extends BrokerRestartTestSupport {
@Override
protected void configureBroker(BrokerService broker) throws Exception {
super.configureBroker(broker);
broker.setPersistent(false);
broker.setPersistenceAdapter(new KahaDBPersistenceAdapter());
broker.addConnector("tcp://0.0.0.0:0");
}
public void testValidateNoPersistenceForDurableAfterRestart() throws Exception {
ConnectionFactory connectionFactory =
new ActiveMQConnectionFactory("failover:(" + broker.getTransportConnectors().get(0).getPublishableConnectString() + ")");
ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();
connection.setClientID("clientId");
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic destination = session.createTopic(queueName);
MessageConsumer consumer = session.createDurableSubscriber(destination, "subscriberName");
populateDestination(10, destination, connection);
restartBroker();
// make failover aware of the restarted auto assigned port
((FailoverTransport) connection.getTransport().narrow(FailoverTransport.class)).add(true, broker.getTransportConnectors().get(0).getPublishableConnectString());
TextMessage msg = (TextMessage) consumer.receive(4000);
assertNull("did not get a message when persistent=false, message: " + msg, msg);
connection.close();
}
private void populateDestination(final int nbMessages,
final Destination destination, javax.jms.Connection connection)
throws JMSException {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(destination);
for (int i = 1; i <= nbMessages; i++) {
producer.send(session.createTextMessage("<hello id='" + i + "'/>"));
}
producer.close();
session.close();
}
public static Test suite() {
return suite(DurablePersistentFalseRestartTest.class);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
}