Session session = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(deliveryMode);
final BrokerView brokerView = broker.getAdminView();
final TopicViewMBean topicView = getTopicView();
assertTrue("Should have one consumer on topic: ", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return topicView.getConsumerCount() == 1;
}
}));
consumer.close();
assertTrue("Durable consumer should now be inactive.", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return brokerView.getInactiveDurableTopicSubscribers().length == 1;
}
}));
try {
brokerView.removeTopic(destination.getTopicName());
} catch (Exception e1) {
fail("Unable to remove destination:" + destination.getPhysicalName());
}
assertTrue("Should have no topics on the broker", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return brokerView.getTopics().length == 0;
}
}));
try {
brokerView.destroyDurableSubscriber("subscriber1", "myTopic");
} catch(Exception e) {
fail("Exception not expected when attempting to delete Durable consumer.");
}
assertTrue("Should be no durable consumers active or inactive.", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return brokerView.getInactiveDurableTopicSubscribers().length == 0 &&
brokerView.getDurableTopicSubscribers().length == 0;
}
}));
consumer = consumerMQSession.createDurableSubscriber(destination, "myTopic");
consumer.close();
assertTrue("Should be one consumer on the Topic.", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
LOG.info("Number of inactive consumers: " + brokerView.getInactiveDurableTopicSubscribers().length);
return brokerView.getInactiveDurableTopicSubscribers().length == 1;
}
}));
final TopicViewMBean recreatedTopicView = getTopicView();