assertFalse( destinationSource.getTopics().contains(amqTopic) );
}
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);
MessageConsumer consumer = session.createConsumer(topic);
TextMessage msg = session.createTextMessage("Hellow World");
producer.send(msg);
assertNotNull( consumer.receive( 5000 ) );
Thread.sleep( 1000 );
ActiveMQTopic amqTopic = (ActiveMQTopic)topic;
assertTrue(destinationPresentInAdminView(broker, amqTopic));
assertTrue( destinationSource.getTopics().contains(amqTopic) );
// This line generates a broker error since the consumer is still active.
try{
amqConnection.destroyDestination( (ActiveMQDestination)topic );
fail("expect exception on destroy if comsumer present");
} catch( JMSException expected ) {
assertTrue(expected.getMessage().indexOf(amqTopic.getTopicName()) != -1);
}
Thread.sleep( 3000 );
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 );
assertFalse( destinationSource.getTopics().contains(amqTopic) );
assertFalse(destinationPresentInAdminView(broker, amqTopic));
}