You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2013/01/03 16:57:05 UTC
svn commit: r1428420 -
/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/RemoveDestinationTest.java
Author: tabish
Date: Thu Jan 3 15:57:05 2013
New Revision: 1428420
URL: http://svn.apache.org/viewvc?rev=1428420&view=rev
Log:
fix test case after changes in https://issues.apache.org/jira/browse/AMQ-4237 broke the test's MBean lookup
Modified:
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/RemoveDestinationTest.java
Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/RemoveDestinationTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/RemoveDestinationTest.java?rev=1428420&r1=1428419&r2=1428420&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/RemoveDestinationTest.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/RemoveDestinationTest.java Thu Jan 3 15:57:05 2013
@@ -16,6 +16,11 @@
*/
package org.apache.activemq;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.net.URI;
import javax.jms.Connection;
@@ -24,40 +29,39 @@ import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
-import javax.jms.Topic;
import javax.jms.TextMessage;
+import javax.jms.Topic;
import javax.management.ObjectName;
import org.apache.activemq.advisory.DestinationSource;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.jmx.DestinationViewMBean;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQTopic;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
-import junit.framework.TestCase;
-
-public class RemoveDestinationTest extends TestCase {
+public class RemoveDestinationTest {
private static final String VM_BROKER_URL = "vm://localhost?create=false";
private static final String BROKER_URL = "broker:vm://localhost?broker.persistent=false&broker.useJmx=true";
-
+
BrokerService broker;
-
- public RemoveDestinationTest(String name) {
- super(name);
- }
- protected void setUp() throws Exception {
- super.setUp();
-
+ @Before
+ public void setUp() throws Exception {
broker = BrokerFactory.createBroker(new URI(BROKER_URL));
broker.start();
-
+ broker.waitUntilStarted();
}
- protected void tearDown() throws Exception {
- super.tearDown();
+ @After
+ public void tearDown() throws Exception {
broker.stop();
+ broker.waitUntilStopped();
+ broker = null;
}
private Connection createConnection(final boolean start) throws JMSException {
@@ -69,6 +73,7 @@ public class RemoveDestinationTest exten
return conn;
}
+ @Test
public void testRemoveDestinationWithoutSubscriber() throws Exception {
ActiveMQConnection amqConnection = (ActiveMQConnection) createConnection(true);
@@ -80,29 +85,27 @@ public class RemoveDestinationTest exten
TextMessage msg = session.createTextMessage("Hellow World");
producer.send(msg);
- assertNotNull( consumer.receive( 5000 ) );
- Thread.sleep( 1000 );
+ assertNotNull(consumer.receive(5000));
+ Thread.sleep(1000);
- ActiveMQTopic amqTopic = (ActiveMQTopic)topic;
- assertTrue( destinationSource.getTopics().contains(amqTopic) );
+ ActiveMQTopic amqTopic = (ActiveMQTopic) topic;
+ assertTrue(destinationSource.getTopics().contains(amqTopic));
consumer.close();
producer.close();
session.close();
- Thread.sleep( 3000 );
-
- amqConnection.destroyDestination( (ActiveMQDestination)topic );
-
- Thread.sleep( 3000 );
-
- assertFalse( destinationSource.getTopics().contains(amqTopic) );
+ Thread.sleep(3000);
+ amqConnection.destroyDestination((ActiveMQDestination) topic);
+ Thread.sleep(3000);
+ assertFalse(destinationSource.getTopics().contains(amqTopic));
}
+ @Test
public void testRemoveDestinationWithSubscriber() throws Exception {
ActiveMQConnection amqConnection = (ActiveMQConnection) createConnection(true);
DestinationSource destinationSource = amqConnection.getDestinationSource();
-
+
Session session = amqConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic("TEST.FOO");
MessageProducer producer = session.createProducer(topic);
@@ -110,56 +113,53 @@ public class RemoveDestinationTest exten
TextMessage msg = session.createTextMessage("Hellow World");
producer.send(msg);
- assertNotNull( consumer.receive( 5000 ) );
- Thread.sleep( 1000 );
+ assertNotNull(consumer.receive(5000));
+ Thread.sleep(1000);
- ActiveMQTopic amqTopic = (ActiveMQTopic)topic;
+ ActiveMQTopic amqTopic = (ActiveMQTopic) topic;
assertTrue(destinationPresentInAdminView(broker, amqTopic));
-
- assertTrue( destinationSource.getTopics().contains(amqTopic) );
+ assertTrue(destinationSource.getTopics().contains(amqTopic));
// This line generates a broker error since the consumer is still active.
- try{
- amqConnection.destroyDestination( (ActiveMQDestination)topic );
+ try {
+ amqConnection.destroyDestination((ActiveMQDestination) topic);
fail("expect exception on destroy if comsumer present");
- } catch( JMSException expected ) {
+ } catch (JMSException expected) {
assertTrue(expected.getMessage().indexOf(amqTopic.getTopicName()) != -1);
}
- Thread.sleep( 3000 );
+ Thread.sleep(3000);
- assertTrue( destinationSource.getTopics().contains(amqTopic) );
+ assertTrue(destinationSource.getTopics().contains(amqTopic));
assertTrue(destinationPresentInAdminView(broker, amqTopic));
-
+
consumer.close();
producer.close();
session.close();
- Thread.sleep( 3000 );
-
- // The destination will not be removed with this call, but if you remove the call
- // above that generates the error it will.
- amqConnection.destroyDestination( amqTopic );
-
- Thread.sleep( 3000 );
+ Thread.sleep(3000);
- assertFalse( destinationSource.getTopics().contains(amqTopic) );
+ // The destination will not be removed with this call, but if you remove
+ // the call above that generates the error it will.
+ amqConnection.destroyDestination(amqTopic);
+ Thread.sleep(3000);
+ assertFalse(destinationSource.getTopics().contains(amqTopic));
assertFalse(destinationPresentInAdminView(broker, amqTopic));
-
}
- private boolean destinationPresentInAdminView(BrokerService broker2,
- ActiveMQTopic amqTopic) throws Exception {
+ private boolean destinationPresentInAdminView(BrokerService broker2, ActiveMQTopic amqTopic) throws Exception {
boolean found = false;
for (ObjectName name : broker.getAdminView().getTopics()) {
- if (name.getKeyProperty("Destination") != null &&
- name.getKeyProperty("Destination").equalsIgnoreCase(amqTopic.getTopicName())) {
+
+ DestinationViewMBean proxy = (DestinationViewMBean)
+ broker.getManagementContext().newProxyInstance(name, DestinationViewMBean.class, true);
+
+ if (proxy.getName().equals(amqTopic.getPhysicalName())) {
found = true;
break;
- }
+ }
}
return found;
}
}
-