https://issues.apache.org/jira/browse/AMQ-3526 - JDBC persistence adapter, destination mbeans not visible on restart till producers or consumers reattach. query to find inactive destinations was checking the wrong table name, resolved with new test

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1179999 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2011-10-07 10:57:41 +00:00
parent c3a0de54b7
commit ab12a60a3a
2 changed files with 99 additions and 1 deletions

View File

@ -356,7 +356,7 @@ public class Statements {
public String getFindAllDestinationsStatement() {
if (findAllDestinationsStatement == null) {
findAllDestinationsStatement = "SELECT DISTINCT CONTAINER FROM " + getFullAckTableName();
findAllDestinationsStatement = "SELECT DISTINCT CONTAINER FROM " + getFullMessageTableName();
}
return findAllDestinationsStatement;
}

View File

@ -0,0 +1,98 @@
/**
* 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.MessageProducer;
import javax.jms.Session;
import javax.management.ObjectName;
import junit.framework.Test;
import org.apache.activemq.TestSupport;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.util.JMXSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class QueueMbeanRestartTest extends TestSupport {
private static final transient Logger LOG = LoggerFactory.getLogger(QueueMbeanRestartTest.class);
BrokerService broker;
public static Test suite() {
return suite(QueueMbeanRestartTest.class);
}
public void setUp() throws Exception {
topic = false;
super.setUp();
}
public void tearDown() throws Exception {
super.tearDown();
broker.stop();
}
public void initCombosForTestMBeanPresenceOnRestart() {
addCombinationValues("defaultPersistenceAdapter",
new Object[]{PersistenceAdapterChoice.KahaDB, PersistenceAdapterChoice.JDBC});
}
public void testMBeanPresenceOnRestart() throws Exception {
createBroker(true);
sendMessages();
verifyPresenceOfQueueMbean();
LOG.info("restart....");
restartBroker();
verifyPresenceOfQueueMbean();
}
private void restartBroker() throws Exception {
broker.stop();
broker.waitUntilStopped();
createBroker(false);
}
private void verifyPresenceOfQueueMbean() throws Exception {
for (ObjectName name : broker.getManagementContext().queryNames(null, null)) {
LOG.info("candidate :" + name);
String type = name.getKeyProperty("Type");
if (type != null && type.equals("Queue")) {
assertEquals(
JMXSupport.encodeObjectNamePart(((ActiveMQQueue) createDestination()).getPhysicalName()),
name.getKeyProperty("Destination"));
LOG.info("found mbbean " + name);
return;
}
}
fail("expected to find matching queue mbean for: " + createDestination());
}
private void sendMessages() throws Exception {
Session session = createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(createDestination());
producer.send(session.createTextMessage());
}
private void createBroker(boolean deleteAll) throws Exception {
broker = new BrokerService();
setDefaultPersistenceAdapter(broker);
broker.setDeleteAllMessagesOnStartup(deleteAll);
broker.start();
}
}