public void simpleDurableTopicTest() throws Exception {
String TOPIC_NAME = "topic://AMQ4696Test" + System.currentTimeMillis();
String durableClientId = "AMQPDurableTopicTestClient";
String durableSubscriberName = "durableSubscriberName";
BrokerView adminView = this.brokerService.getAdminView();
int durableSubscribersAtStart = adminView.getDurableTopicSubscribers().length;
int inactiveSubscribersAtStart = adminView.getInactiveDurableTopicSubscribers().length;
LOG.debug(">>>> At Start, durable Subscribers {} inactiveDurableSubscribers {}", durableSubscribersAtStart, inactiveSubscribersAtStart);
TopicConnectionFactory factory = new ConnectionFactoryImpl("localhost", port, "admin", "password");
Topic topic = new TopicImpl("topic://" + TOPIC_NAME);
TopicConnection subscriberConnection = factory.createTopicConnection();
subscriberConnection.setClientID(durableClientId);
TopicSession subscriberSession = subscriberConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber messageConsumer = subscriberSession.createDurableSubscriber(topic, durableSubscriberName);
assertNotNull(messageConsumer);
int durableSubscribers = adminView.getDurableTopicSubscribers().length;
int inactiveSubscribers = adminView.getInactiveDurableTopicSubscribers().length;
LOG.debug(">>>> durable Subscribers after creation {} inactiveDurableSubscribers {}", durableSubscribers, inactiveSubscribers);
assertEquals("Wrong number of durable subscribers after first subscription", 1, (durableSubscribers - durableSubscribersAtStart));
assertEquals("Wrong number of inactive durable subscribers after first subscription", 0, (inactiveSubscribers - inactiveSubscribersAtStart));
subscriberConnection.close();
subscriberConnection = null;
durableSubscribers = adminView.getDurableTopicSubscribers().length;
inactiveSubscribers = adminView.getInactiveDurableTopicSubscribers().length;
LOG.debug(">>>> durable Subscribers after close {} inactiveDurableSubscribers {}", durableSubscribers, inactiveSubscribers);
assertEquals("Wrong number of durable subscribers after close", 0, (durableSubscribersAtStart));
assertEquals("Wrong number of inactive durable subscribers after close", 1, (inactiveSubscribers - inactiveSubscribersAtStart));
}