* by monitoring message count while sending new messages to the topic and then
* consuming them.
*/
public void testSelectorDurability() throws Exception
{
JMXTestUtils jmxUtils = null;
try
{
jmxUtils = new JMXTestUtils(this, "guest", "guest");
jmxUtils.open();
}
catch (Exception e)
{
fail("Unable to establish JMX connection, test cannot proceed");
}
try
{
ManagedQueue dursubQueue = jmxUtils.getManagedQueue("clientid" + ":" + SELECTOR_SUB_NAME);
assertEquals("DurableSubscription backing queue should have 1 message on it initially",
new Integer(1), dursubQueue.getMessageCount());
// Create a connection and start it
TopicConnection connection = (TopicConnection) getConnection();
connection.start();
// Send messages which don't match and do match the selector, checking message count
TopicSession pubSession = connection.createTopicSession(true, Session.SESSION_TRANSACTED);
Topic topic = pubSession.createTopic(SELECTOR_TOPIC_NAME);
TopicPublisher publisher = pubSession.createPublisher(topic);
publishMessages(pubSession, publisher, topic, DeliveryMode.PERSISTENT, 1*1024, 1, "false");
pubSession.commit();
assertEquals("DurableSubscription backing queue should still have 1 message on it",
Integer.valueOf(1), dursubQueue.getMessageCount());
publishMessages(pubSession, publisher, topic, DeliveryMode.PERSISTENT, 1*1024, 1, "true");
pubSession.commit();
assertEquals("DurableSubscription backing queue should now have 2 messages on it",
Integer.valueOf(2), dursubQueue.getMessageCount());
TopicSubscriber durSub = pubSession.createDurableSubscriber(topic, SELECTOR_SUB_NAME,"testprop='true'", false);
Message m = durSub.receive(2000);
assertNotNull("Failed to receive an expected message", m);
m = durSub.receive(2000);
assertNotNull("Failed to receive an expected message", m);
pubSession.commit();
pubSession.close();
}
finally
{
jmxUtils.close();
}
}