Author: fjuma
Date: 2009-03-18 09:38:25 -0400 (Wed, 18 Mar 2009)
New Revision: 239
Added:
trunk/jsfunit/testdata/destinations/MetricsMultipleTopicSubscribersExistingTopic-service.xml
trunk/jsfunit/testdata/destinations/MetricsOneDurableTopicSubscriberExistingTopic-service.xml
trunk/jsfunit/testdata/destinations/MetricsOneNonDurableTopicSubscriberExistingTopic-service.xml
trunk/jsfunit/testdata/destinations/TopicMetricsMultipleMessagesExistingTopic-service.xml
trunk/jsfunit/testdata/destinations/TopicMetricsOneMessageExistingTopic-service.xml
Modified:
trunk/jsfunit/pom.xml
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JMSTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java
Log:
Adding metrics tests for topics.
Modified: trunk/jsfunit/pom.xml
===================================================================
--- trunk/jsfunit/pom.xml 2009-03-17 22:18:25 UTC (rev 238)
+++ trunk/jsfunit/pom.xml 2009-03-18 13:38:25 UTC (rev 239)
@@ -120,6 +120,18 @@
<version>2.1.0.CR3</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>jboss.messaging</groupId>
+ <artifactId>jboss-messaging-client</artifactId>
+ <version>1.4.3.GA</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.javaee</groupId>
+ <artifactId>jboss-javaee</artifactId>
+ <version>5.0.1.GA</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JMSTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JMSTest.java 2009-03-17
22:18:25 UTC (rev 238)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JMSTest.java 2009-03-18
13:38:25 UTC (rev 239)
@@ -27,8 +27,10 @@
import junit.framework.Test;
import java.util.Map;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Iterator;
import java.util.Set;
+import java.util.ArrayList;
import org.jboss.jopr.jsfunit.*;
import javax.management.MBeanServer;
import javax.management.ObjectName;
@@ -39,6 +41,20 @@
import org.jboss.metatype.api.values.MetaValue;
import org.jboss.managed.api.ComponentType;
import java.io.File;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSubscriber;
+import javax.jms.TopicSession;
+import javax.naming.InitialContext;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.ConnectionFactory;
+import javax.jms.TextMessage;
+import javax.jms.JMSException;
+import javax.naming.NamingException;
/**
* This class contains tests for managing JMS topics and queues
@@ -80,7 +96,32 @@
private static final ComponentType TOPIC_COMPONENT_TYPE =
KnownComponentTypes.JMSDestination.Topic.getType();
private static final String SERVICE_FILE_ROOT_ELEMENT = "server";
private static final String SERVICE_FILE_CHILD_ELEMENT = "mbean";
-
+ private static final String TOPIC_FACTORY = "/ConnectionFactory";
+ private static final String QUEUE_FACTORY = "/ConnectionFactory";
+ private static final String CLIENT_ID = "EmbjoprTest";
+
+ // Topic Metrics
+ private static final String ALL_MSG_COUNT = "All Message Count";
+ private static final String ALL_SUB_COUNT = "All Subscriptions Count";
+ private static final String DURABLE_MSG_COUNT = "Durable Message Count";
+ private static final String DURABLE_SUB_COUNT = "Durable Subscriptions
Count";
+ private static final String NON_DURABLE_MSG_COUNT = "Non Durable Message
Count";
+ private static final String NON_DURABLE_SUB_COUNT = "Non Durable Subscriptions
Count";
+
+ // Queue Metrics
+ private static final String CONSUMER_COUNT = "Consumer Count";
+ private static final String DELIVERING_COUNT = "Delivering Count";
+ private static final String MSG_COUNT = "Message Count";
+ private static final String SCHEDULED_MSG_COUNT = "Scheduled Message
Count";
+ private static final String COUNT = "Count";
+ private static final String COUNT_DELTA = "Count Delta";
+ private static final String DEPTH = "Depth";
+ private static final String DEPTH_DELTA = "Depth Delta";
+ private static final String TIME_LAST_UPDATE = "Time Last Update";
+
+ private TopicConnection topicConnection = null;
+ private QueueConnection queueConnection = null;
+
/**
* Create a new topic or queue using the given destination type and properties.
*/
@@ -109,7 +150,7 @@
*/
protected Map<String, MetaValue> createQueue(String queueName) throws
IOException, EmbJoprTestException {
- Map<String, MetaValue> propertiesMap = new HashMap<String,
MetaValue>();
+ Map<String, MetaValue> propertiesMap = new LinkedHashMap<String,
MetaValue>();
propertiesMap.put("JNDIName", SimpleValueSupport.wrap(queueName));
propertiesMap.put("clustered",
SimpleValueSupport.wrap(Boolean.FALSE));
propertiesMap.put("downCacheSize", SimpleValueSupport.wrap(new
Integer(1500)));
@@ -129,7 +170,7 @@
* values.
*/
protected Map<String, MetaValue> createTopic(String topicName) throws
IOException, EmbJoprTestException {
- Map<String, MetaValue> propertiesMap = new HashMap<String,
MetaValue>();
+ Map<String, MetaValue> propertiesMap = new LinkedHashMap<String,
MetaValue>();
propertiesMap.put("JNDIName", SimpleValueSupport.wrap(topicName));
propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.TRUE));
propertiesMap.put("fullSize", SimpleValueSupport.wrap(new
Integer(70000)));
@@ -162,6 +203,123 @@
return super.getSpecificComponentProperties(componentName, type,
specificProperties);
}
+ /**
+ * Create a topic session and return it.
+ */
+ protected TopicSession createTopicSession() throws Exception {
+ InitialContext context = new InitialContext();
+ Object tmp = context.lookup(TOPIC_FACTORY);
+
+ TopicConnectionFactory tcf = (TopicConnectionFactory)tmp;
+ topicConnection = tcf.createTopicConnection();
+ topicConnection.setClientID(CLIENT_ID);
+
+ TopicSession topicSession = topicConnection.createTopicSession(Boolean.FALSE,
+ TopicSession.AUTO_ACKNOWLEDGE);
+ topicConnection.start();
+
+ return topicSession;
+ }
+
+ /**
+ * Create a non-durable topic subscriber and return it.
+ */
+ protected TopicSubscriber createNonDurableTopicSubscriber(TopicSession session,
+ Topic topic) throws
JMSException {
+ return session.createSubscriber(topic);
+ }
+
+ /**
+ * Create a durable topic subscriber and return it.
+ */
+ protected TopicSubscriber createDurableTopicSubscriber(TopicSession session,
+ Topic topic,
+ String subscriptionName)
throws JMSException {
+ return session.createDurableSubscriber(topic, subscriptionName);
+ }
+
+ /**
+ * Create a TopicPublisher for the given topic and
+ * publish the given number of messages.
+ */
+ protected void publishMessages(TopicSession session,
+ Topic topic,
+ int numMessages) throws JMSException {
+ TopicPublisher publisher = session.createPublisher(topic);
+
+ for(int i = 0; i < numMessages; i++) {
+ TextMessage message = session.createTextMessage("Message " + i);
+ publisher.publish(message);
+ }
+
+ publisher.close();
+ }
+
+ /**
+ * Lookup and return the topic given by jndiName.
+ */
+ protected Topic getTopic(String jndiName) throws NamingException {
+ InitialContext context = new InitialContext();
+ Topic topic = (Topic)context.lookup(jndiName);
+
+ return topic;
+ }
+
+ /**
+ * Close all connections.
+ */
+ protected void disconnect() throws JMSException {
+
+ if(topicConnection != null) {
+ topicConnection.close();
+ topicConnection = null;
+ }
+
+ if(queueConnection != null) {
+ queueConnection.close();
+ queueConnection = null;
+ }
+ }
+
+ /**
+ * Get the list of metrics that appear on the summary
+ * page for topics.
+ */
+ protected ArrayList<String> getTopicSummaryMetrics() {
+ ArrayList<String> topicSummaryMetrics = new ArrayList<String>();
+
+ // The metrics we need to check on the summary tab
+ // TODO: add the summary page metrics that need to be checked -
+ // currently no summary metrics are displayed on the page (EMBJOPR-90)
+
+ return topicSummaryMetrics;
+ }
+
+ /**
+ * Get the list of metrics that appear on the summary
+ * page for queues.
+ */
+ protected ArrayList<String> getQueueSummaryMetrics() {
+ ArrayList<String> queueSummaryMetrics = new ArrayList<String>();
+
+ // The metrics we need to check on the summary tab
+ // TODO: add the summary page metrics that need to be checked -
+ // currently no summary metrics are displayed on the page (EMBJOPR-90)
+
+ return queueSummaryMetrics;
+ }
+
+ /**
+ * Make sure we close any topic or queue
+ * connections.
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ disconnect();
+ }
+
+
/*
* CREATION TESTS
*/
@@ -208,7 +366,7 @@
ComponentType componentType) throws Exception {
// The properties we want to configure
- Map<String, MetaValue> propertiesMap = new HashMap<String,
MetaValue>();
+ Map<String, MetaValue> propertiesMap = new LinkedHashMap<String,
MetaValue>();
propertiesMap.put("JNDIName", SimpleValueSupport.wrap(jndiName));
propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.TRUE));
propertiesMap.put("downCacheSize", SimpleValueSupport.wrap(new
Integer(2500)));
@@ -259,7 +417,7 @@
private void createDestinationMissingRequiredValue(DestinationType destinationType,
String destinationTemplate) throws
IOException, EmbJoprTestException {
// Leave the JNDI name unset
- Map<String, MetaValue> propertiesMap = new HashMap<String,
MetaValue>();
+ Map<String, MetaValue> propertiesMap = new LinkedHashMap<String,
MetaValue>();
propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.TRUE));
propertiesMap.put("fullSize", SimpleValueSupport.wrap(new
Integer(80000)));
@@ -303,7 +461,7 @@
String destinationTemplate,
String jndiName) throws IOException,
EmbJoprTestException {
// The properties we want to configure
- Map<String, MetaValue> propertiesMap = new HashMap<String,
MetaValue>();
+ Map<String, MetaValue> propertiesMap = new LinkedHashMap<String,
MetaValue>();
propertiesMap.put("JNDIName", SimpleValueSupport.wrap(jndiName));
propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.TRUE));
propertiesMap.put("downCacheSize", SimpleValueSupport.wrap(new
Integer(2500)));
@@ -351,7 +509,7 @@
String destinationTemplate,
String jndiName) throws
IOException, EmbJoprTestException {
// The properties we want to configure
- Map<String, MetaValue> propertiesMap = new HashMap<String,
MetaValue>();
+ Map<String, MetaValue> propertiesMap = new LinkedHashMap<String,
MetaValue>();
propertiesMap.put("JNDIName", SimpleValueSupport.wrap(jndiName));
propertiesMap.put("clustered",
SimpleValueSupport.wrap(Boolean.TRUE));
propertiesMap.put("messageCounterHistoryDayLimit",
SimpleValueSupport.wrap(new Integer(0)));
@@ -397,7 +555,7 @@
String destinationTemplate,
String jndiName) throws IOException,
EmbJoprTestException {
// The properties we want to configure
- Map<String, MetaValue> propertiesMap = new HashMap<String,
MetaValue>();
+ Map<String, MetaValue> propertiesMap = new LinkedHashMap<String,
MetaValue>();
propertiesMap.put("JNDIName", SimpleValueSupport.wrap(jndiName));
createDestination(destinationType, destinationTemplate, propertiesMap);
@@ -509,7 +667,7 @@
// The properties we are going to change
// (Before: messageCounterHistoryDayLimit=-1, redeliveryDelay=-1 )
- Map<String, MetaValue> propertiesMapChanges = new HashMap<String,
MetaValue>();
+ Map<String, MetaValue> propertiesMapChanges = new LinkedHashMap<String,
MetaValue>();
propertiesMapChanges.put("messageCounterHistoryDayLimit",
SimpleValueSupport.wrap(new Integer(0)));
propertiesMapChanges.put("redeliveryDelay",
SimpleValueSupport.wrap(new Long(40000)));
@@ -534,7 +692,7 @@
// The properties we are going to change
// (Before: maxDeliveryAttempts=-1, redeliveryDelay=-1 )
- Map<String, MetaValue> propertiesMapChanges = new HashMap<String,
MetaValue>();
+ Map<String, MetaValue> propertiesMapChanges = new LinkedHashMap<String,
MetaValue>();
propertiesMapChanges.put("maxDeliveryAttempts",
SimpleValueSupport.wrap(new Integer(15)));
propertiesMapChanges.put("redeliveryDelay",
SimpleValueSupport.wrap(new Long(40000)));
@@ -561,7 +719,7 @@
// The properties we are going to change
// (Before: messageCounterHistoryDayLimit=5, redeliveryDelay=-1 )
- Map<String, MetaValue> propertiesMapChanges = new HashMap<String,
MetaValue>();
+ Map<String, MetaValue> propertiesMapChanges = new LinkedHashMap<String,
MetaValue>();
propertiesMapChanges.put("messageCounterHistoryDayLimit",
SimpleValueSupport.wrap(new Integer(0)));
propertiesMapChanges.put("redeliveryDelay",
SimpleValueSupport.wrap(new Long(40000)));
@@ -586,7 +744,7 @@
// The properties we are going to change
// (Before: redeliveryDelay=60000, maxDeliveryAttempts=-1 )
- Map<String, MetaValue> propertiesMapChanges = new HashMap<String,
MetaValue>();
+ Map<String, MetaValue> propertiesMapChanges = new LinkedHashMap<String,
MetaValue>();
propertiesMapChanges.put("redeliveryDelay",
SimpleValueSupport.wrap(new Long(40000)));
propertiesMapChanges.put("maxDeliveryAttempts",
SimpleValueSupport.wrap(new Integer(15)));
@@ -732,4 +890,296 @@
// Clean up
deleteDestination(destinationType, jndiName);
}
+
+ /*
+ * METRICS TESTS
+ */
+
+ /**
+ * Test Name: testTopicMetricsAfterCreation
+ * Assertion: Verify that topic metrics are correct after topic
+ * creation.
+ */
+ public void testTopicMetricsAfterCreation() throws Exception {
+ String jndiName = "MetricsAfterTopicCreation";
+
+ // Create the topic first
+ createTopic(jndiName);
+
+ // Set up the expected values
+ Map<String, String> expectedMetrics = new LinkedHashMap<String,
String>();
+ expectedMetrics.put(ALL_MSG_COUNT, "0.0");
+ expectedMetrics.put(ALL_SUB_COUNT, "0.0");
+ expectedMetrics.put(DURABLE_MSG_COUNT, "0.0");
+ expectedMetrics.put(DURABLE_SUB_COUNT, "0.0");
+ expectedMetrics.put(NON_DURABLE_MSG_COUNT, "0.0");
+ expectedMetrics.put(NON_DURABLE_SUB_COUNT, "0.0");
+
+ checkDestinationMetrics(jndiName, expectedMetrics, getTopicSummaryMetrics(),
+ DestinationType.TOPIC);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterOneNonDurableSubscription
+ * Assertion: Verify that topic metrics are correct after creating
+ * a non-durable subscriber for the topic.
+ */
+ public void testTopicMetricsAfterOneNonDurableSubscription() throws Exception {
+ String jndiName = "MetricsAfterOneNonDurableTopicSubscriber";
+
+ // Create the topic first
+ createTopic(jndiName);
+
+ checkTopicMetricsAfterOneSubscription(jndiName, Boolean.FALSE);
+ }
+
+ /**
+ * Test Name:
testTopicMetricsAfterOneNonDurableSubscriptionUsingExistingServiceFile
+ * Assertion: Verify that topic metrics are correct after creating
+ * a non-durable subscriber for the topic. Use a topic that already exists.
+ */
+ public void testTopicMetricsAfterOneNonDurableSubscriptionUsingExistingServiceFile()
throws Exception {
+ String jndiName = "MetricsOneNonDurableTopicSubscriberExistingTopic";
+
+ expandNavTreeArrow(JMS_NAV_LABEL);
+ checkTopicMetricsAfterOneSubscription(jndiName, Boolean.FALSE);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterOneDurableSubscription
+ * Assertion: Verify that topic metrics are correct after creating
+ * a durable subscriber for the topic.
+ */
+ public void testTopicMetricsAfterOneDurableSubscription() throws Exception {
+ String jndiName = "MetricsAfterOneDurableTopicSubscriber";
+
+ // Create the topic first
+ createTopic(jndiName);
+
+ checkTopicMetricsAfterOneSubscription(jndiName, Boolean.TRUE);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterOneDurableSubscriptionUsingExistingServiceFile
+ * Assertion: Verify that topic metrics are correct after creating
+ * a durable subscriber for the topic. Use a topic that already exists.
+ */
+ public void testTopicMetricsAfterOneDurableSubscriptionUsingExistingServiceFile()
throws Exception {
+ String jndiName = "MetricsOneDurableTopicSubscriberExistingTopic";
+
+ expandNavTreeArrow(JMS_NAV_LABEL);
+ checkTopicMetricsAfterOneSubscription(jndiName, Boolean.TRUE);
+ }
+
+ /**
+ * Common code for the testTopicMetricsAfterOne*Subscription* tests.
+ */
+ private void checkTopicMetricsAfterOneSubscription(String jndiName,
+ Boolean isDurable) throws Exception {
+
+ // Create a subscriber
+ TopicSession session = createTopicSession();
+ Topic topic = getTopic(jndiName);
+
+ if(isDurable) {
+ createDurableTopicSubscriber(session, topic, jndiName +
"Subscriber1");
+ } else {
+ createNonDurableTopicSubscriber(session, topic);
+ }
+
+ // Set up the expected values
+ Map<String, String> expectedMetrics = new LinkedHashMap<String,
String>();
+ expectedMetrics.put(ALL_MSG_COUNT, "0.0");
+ expectedMetrics.put(ALL_SUB_COUNT, "1.0");
+ expectedMetrics.put(DURABLE_MSG_COUNT, "0.0");
+ expectedMetrics.put(NON_DURABLE_MSG_COUNT, "0.0");
+
+ if(isDurable) {
+ expectedMetrics.put(DURABLE_SUB_COUNT, "1.0");
+ expectedMetrics.put(NON_DURABLE_SUB_COUNT, "0.0");
+ } else {
+ expectedMetrics.put(DURABLE_SUB_COUNT, "0.0");
+ expectedMetrics.put(NON_DURABLE_SUB_COUNT, "1.0");
+ }
+
+ checkDestinationMetrics(jndiName, expectedMetrics, getTopicSummaryMetrics(),
+ DestinationType.TOPIC);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterMultipleSubscriptions()
+ * Assertion: Verify that topic metrics are correct after multiple subscribers
+ * for the topic are created.
+ */
+ public void testTopicMetricsAfterMultipleSubscriptions() throws Exception {
+ String jndiName = "MetricsAfterMultipleTopicSubscribers";
+
+ // Create the topic first
+ createTopic(jndiName);
+
+ checkTopicMetricsAfterMultipleSubscriptions(jndiName);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterMultipleSubscriptionsUsingExistingServiceFile()
+ * Assertion: Verify that topic metrics are correct after multiple subscribers
+ * for the topic are created. Use a topic that already exists.
+ */
+ public void testTopicMetricsAfterMultipleSubscriptionsUsingExistingServiceFile()
throws Exception {
+ String jndiName = "MetricsMultipleTopicSubscribersExistingTopic";
+
+ expandNavTreeArrow(JMS_NAV_LABEL);
+ checkTopicMetricsAfterMultipleSubscriptions(jndiName);
+ }
+
+ /**
+ * Common code for the testTopicMetricsAfterMultipleSubscriptions* tests.
+ */
+ private void checkTopicMetricsAfterMultipleSubscriptions(String jndiName) throws
Exception {
+
+ TopicSession session = createTopicSession();
+ Topic topic = getTopic(jndiName);
+
+ // Create multiple subscriptions (2 durable ones, 2 non-durable ones)
+ for(int i = 0; i < 2; i++) {
+ createDurableTopicSubscriber(session, topic, jndiName +
"Subscriber" + i);
+ createNonDurableTopicSubscriber(session, topic);
+ }
+
+ // Set up the expected values
+ Map<String, String> expectedMetrics = new LinkedHashMap<String,
String>();
+ expectedMetrics.put(ALL_MSG_COUNT, "0.0");
+ expectedMetrics.put(ALL_SUB_COUNT, "4.0");
+ expectedMetrics.put(DURABLE_MSG_COUNT, "0.0");
+ expectedMetrics.put(NON_DURABLE_MSG_COUNT, "0.0");
+ expectedMetrics.put(DURABLE_SUB_COUNT, "2.0");
+ expectedMetrics.put(NON_DURABLE_SUB_COUNT, "2.0");
+
+ checkDestinationMetrics(jndiName, expectedMetrics, getTopicSummaryMetrics(),
+ DestinationType.TOPIC);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterOneMessage()
+ * Assertion: Verify that topic metrics are correct after sending
+ * one message to the topic.
+ */
+ public void testTopicMetricsAfterOneMessage() throws Exception {
+ String jndiName = "TopicMetricsAfterOneMessage";
+
+ // Create the topic first
+ createTopic(jndiName);
+
+ checkTopicMetricsAfterOneMessage(jndiName);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterOneMessageUsingExistingServiceFile()
+ * Assertion: Verify that topic metrics are correct after sending
+ * one message to the topic. Use a topic that already exists.
+ */
+ public void testTopicMetricsAfterOneMessageUsingExistingServiceFile() throws
Exception {
+ String jndiName = "TopicMetricsOneMessageExistingTopic";
+
+ expandNavTreeArrow(JMS_NAV_LABEL);
+ checkTopicMetricsAfterOneMessage(jndiName);
+ }
+
+ /**
+ * Common code for the testTopicMetricsAfterOneMessage* tests.
+ */
+ private void checkTopicMetricsAfterOneMessage(String jndiName) throws Exception {
+
+ // Create a subscriber for the topic and then publish
+ // 1 message
+ TopicSession session = createTopicSession();
+ Topic topic = getTopic(jndiName);
+ createDurableTopicSubscriber(session, topic, jndiName +
"Subscriber1");
+
+ publishMessages(session, topic, 1);
+
+ // Set up the expected values
+ Map<String, String> expectedMetrics = new LinkedHashMap<String,
String>();
+ expectedMetrics.put(ALL_MSG_COUNT, "1.0");
+ expectedMetrics.put(ALL_SUB_COUNT, "1.0");
+ expectedMetrics.put(DURABLE_MSG_COUNT, "1.0");
+ expectedMetrics.put(NON_DURABLE_MSG_COUNT, "0.0");
+ expectedMetrics.put(DURABLE_SUB_COUNT, "1.0");
+ expectedMetrics.put(NON_DURABLE_SUB_COUNT, "0.0");
+
+ checkDestinationMetrics(jndiName, expectedMetrics, getTopicSummaryMetrics(),
+ DestinationType.TOPIC);
+
+
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterMultipleMessages()
+ * Assertion: Verify that topic metrics are correct after sending
+ * multiple message to the topic.
+ */
+ public void testTopicMetricsAfterMultipleMessages() throws Exception {
+ String jndiName = "TopicMetricsAfterMultipleMessages";
+
+ // Create the topic first
+ createTopic(jndiName);
+
+ checkTopicMetricsAfterMultipleMessages(jndiName);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterMultipleMessagesUsingExistingServiceFile()
+ * Assertion: Verify that topic metrics are correct after sending
+ * multiple message to the topic. Use a topic that already exists.
+ */
+ public void testTopicMetricsAfterMultipleMessagesUsingExistingServiceFile() throws
Exception {
+ String jndiName = "TopicMetricsMultipleMessagesExistingTopic";
+
+ expandNavTreeArrow(JMS_NAV_LABEL);
+ checkTopicMetricsAfterMultipleMessages(jndiName);
+ }
+
+ /**
+ * Common code for the testTopicMetricsAfterMultipleMessages* tests.
+ */
+ private void checkTopicMetricsAfterMultipleMessages(String jndiName) throws
Exception {
+
+ TopicSession session = createTopicSession();
+ Topic topic = getTopic(jndiName);
+
+ // Create 1 durable subscriber, 1 non-durable subscriber
+ // and then publish 3 messages
+ createDurableTopicSubscriber(session, topic, jndiName +
"Subscriber");
+ createNonDurableTopicSubscriber(session, topic);
+
+ publishMessages(session, topic, 3);
+
+ // Set up the expected values
+ Map<String, String> expectedMetrics = new LinkedHashMap<String,
String>();
+ expectedMetrics.put(ALL_MSG_COUNT, "6.0");
+ expectedMetrics.put(ALL_SUB_COUNT, "2.0");
+ expectedMetrics.put(DURABLE_MSG_COUNT, "3.0");
+ expectedMetrics.put(NON_DURABLE_MSG_COUNT, "3.0");
+ expectedMetrics.put(DURABLE_SUB_COUNT, "1.0");
+ expectedMetrics.put(NON_DURABLE_SUB_COUNT, "1.0");
+
+ checkDestinationMetrics(jndiName, expectedMetrics, getTopicSummaryMetrics(),
+ DestinationType.TOPIC);
+ }
+
+ /**
+ * Common code for the metrics tests.
+ */
+ private void checkDestinationMetrics(String jndiName,
+ Map<String, String> expectedMetrics,
+ ArrayList<String> summaryMetrics,
+ DestinationType destinationType) throws
Exception {
+
+ checkResourceMetrics(JMS_NAV_LABEL, destinationType.getNavLabel(),
+ jndiName, expectedMetrics, summaryMetrics);
+
+ // Clean up
+ disconnect();
+ deleteDestination(destinationType, jndiName);
+ }
}
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java
===================================================================
---
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java 2009-03-17
22:18:25 UTC (rev 238)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java 2009-03-18
13:38:25 UTC (rev 239)
@@ -34,6 +34,8 @@
import java.io.File;
import org.jboss.managed.api.ComponentType;
import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+import java.util.ArrayList;
+import java.util.Iterator;
/**
* This class contains basic methods for creating, configuring, and deleting
@@ -48,11 +50,11 @@
private final String MAX_ITEMS_PER_PAGE="20";
// Error messages
- public static final String INVALID_VALUE_MESSAGE="An invalid value was specified
for one or more properties";
- public static final String MISSING_VALUE_MESSAGE="Value is required";
- public static final String OUT_OF_RANGE_MESSAGE="Specified attribute is not
between the expected values";
- public static final String INVALID_INTEGER_MESSAGE="Value is not a valid
integer";
-
+ public static final String INVALID_VALUE_MESSAGE = "An invalid value was
specified for one or more properties";
+ public static final String MISSING_VALUE_MESSAGE = "Value is required";
+ public static final String OUT_OF_RANGE_MESSAGE = "Specified attribute is not
between the expected values";
+ public static final String INVALID_INTEGER_MESSAGE = "Value is not a valid
integer";
+
// Success messages
public static final String ADD_MESSAGE = "Successfully added new ";
public static final String DELETE_MESSAGE = "Successfully deleted ";
@@ -208,15 +210,67 @@
protected void navigateToPage(String resourceCategory,
String resourceSubCategory,
String resourceName,
- String tabName) throws IOException,
EmbJoprTestException {
+ String tabName) throws Exception {
//refreshTreeNode(resourceCategory);
- ClickableElement datasourceTypeArrow = getNavTreeArrow(resourceSubCategory);
- datasourceTypeArrow.click();
+ ClickableElement resourceTypeArrow = getNavTreeArrow(resourceSubCategory);
+ resourceTypeArrow.click();
- HtmlAnchor datasource = getNavTreeLink(resourceName);
- datasource.click();
+ HtmlAnchor resource = getNavTreeLink(resourceName);
+ resource.click();
HtmlAnchor tabLink = (HtmlAnchor)client.getElement(tabName);
tabLink.click();
}
+
+ /**
+ * Make sure that the metrics corresponding to the given resource
+ * are correct.
+ *
+ * @param metricsMap maps metric names to the expected metric values.
+ *
+ * Assumes the resource tree node (eg. "JMS Destinations",
"Datasources",
+ * etc.) is already expanded.
+ */
+ protected void checkResourceMetrics(String resourceCategory,
+ String resourceSubCategory,
+ String resourceName,
+ Map<String, String> metricsMap,
+ ArrayList<String> summaryMetrics) throws
Exception {
+
+ // Navigate to the metrics page for the resource
+ navigateToPage(resourceCategory, resourceSubCategory,
+ resourceName, METRICS_TAB);
+
+ checkMetricValues(metricsMap.keySet().iterator(), metricsMap,
+ "Incorrect metric value for ");
+
+ if(summaryMetrics.size() > 0) {
+
+ // Check values under the "Summary" tab
+ HtmlAnchor summaryLink = (HtmlAnchor)client.getElement(SUMMARY_TAB);
+ summaryLink.click();
+
+ checkMetricValues(summaryMetrics.iterator(), metricsMap,
+ "Incorrect summary metric value for ");
+ }
+ }
+
+ /**
+ * Compare the actual metric values for this resource to
+ * the expected values.
+ *
+ * @param i is an Iterator over the metrics we want to check
+ * @param metricsMap maps metric names to their expected values
+ */
+ protected void checkMetricValues(Iterator i, Map<String, String> metricsMap,
String errorMessage) {
+
+ while(i.hasNext()) {
+ String metricName = (String)i.next();
+
+ String expected = metricsMap.get(metricName);
+ String actual = getMetricValueFromTable(metricName, "dataTable");
+ actual = normalizeIfDoubleExpected(expected, actual);
+ assertEquals(errorMessage + " '"+ metricName + "'",
expected, actual);
+ }
+ }
}
Added:
trunk/jsfunit/testdata/destinations/MetricsMultipleTopicSubscribersExistingTopic-service.xml
===================================================================
---
trunk/jsfunit/testdata/destinations/MetricsMultipleTopicSubscribersExistingTopic-service.xml
(rev 0)
+++
trunk/jsfunit/testdata/destinations/MetricsMultipleTopicSubscribersExistingTopic-service.xml 2009-03-18
13:38:25 UTC (rev 239)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
+<server>
+ <mbean xmbean-dd="xmdesc/Topic-xmbean.xml"
name="jboss.messaging.destination:service=Topic,name=MetricsMultipleTopicSubscribersExistingTopic"
code="org.jboss.jms.server.destination.TopicService">
+
<annotation>(a)org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
+ <attribute
name="JNDIName">MetricsMultipleTopicSubscribersExistingTopic</attribute>
+ <depends
optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+</server>
Added:
trunk/jsfunit/testdata/destinations/MetricsOneDurableTopicSubscriberExistingTopic-service.xml
===================================================================
---
trunk/jsfunit/testdata/destinations/MetricsOneDurableTopicSubscriberExistingTopic-service.xml
(rev 0)
+++
trunk/jsfunit/testdata/destinations/MetricsOneDurableTopicSubscriberExistingTopic-service.xml 2009-03-18
13:38:25 UTC (rev 239)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
+<server>
+ <mbean xmbean-dd="xmdesc/Topic-xmbean.xml"
name="jboss.messaging.destination:service=Topic,name=MetricsOneDurableTopicSubscriberExistingTopic"
code="org.jboss.jms.server.destination.TopicService">
+
<annotation>(a)org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
+ <attribute
name="JNDIName">MetricsOneDurableTopicSubscriberExistingTopic</attribute>
+ <depends
optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+</server>
Added:
trunk/jsfunit/testdata/destinations/MetricsOneNonDurableTopicSubscriberExistingTopic-service.xml
===================================================================
---
trunk/jsfunit/testdata/destinations/MetricsOneNonDurableTopicSubscriberExistingTopic-service.xml
(rev 0)
+++
trunk/jsfunit/testdata/destinations/MetricsOneNonDurableTopicSubscriberExistingTopic-service.xml 2009-03-18
13:38:25 UTC (rev 239)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
+<server>
+ <mbean xmbean-dd="xmdesc/Topic-xmbean.xml"
name="jboss.messaging.destination:service=Topic,name=MetricsOneNonDurableTopicSubscriberExistingTopic"
code="org.jboss.jms.server.destination.TopicService">
+
<annotation>(a)org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
+ <attribute
name="JNDIName">MetricsOneNonDurableTopicSubscriberExistingTopic</attribute>
+ <depends
optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+</server>
Added:
trunk/jsfunit/testdata/destinations/TopicMetricsMultipleMessagesExistingTopic-service.xml
===================================================================
---
trunk/jsfunit/testdata/destinations/TopicMetricsMultipleMessagesExistingTopic-service.xml
(rev 0)
+++
trunk/jsfunit/testdata/destinations/TopicMetricsMultipleMessagesExistingTopic-service.xml 2009-03-18
13:38:25 UTC (rev 239)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
+<server>
+ <mbean xmbean-dd="xmdesc/Topic-xmbean.xml"
name="jboss.messaging.destination:service=Topic,name=TopicMetricsMultipleMessagesExistingTopic"
code="org.jboss.jms.server.destination.TopicService">
+
<annotation>(a)org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
+ <attribute
name="JNDIName">TopicMetricsMultipleMessagesExistingTopic</attribute>
+ <depends
optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+</server>
Added:
trunk/jsfunit/testdata/destinations/TopicMetricsOneMessageExistingTopic-service.xml
===================================================================
--- trunk/jsfunit/testdata/destinations/TopicMetricsOneMessageExistingTopic-service.xml
(rev 0)
+++
trunk/jsfunit/testdata/destinations/TopicMetricsOneMessageExistingTopic-service.xml 2009-03-18
13:38:25 UTC (rev 239)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
+<server>
+ <mbean xmbean-dd="xmdesc/Topic-xmbean.xml"
name="jboss.messaging.destination:service=Topic,name=TopicMetricsOneMessageExistingTopic"
code="org.jboss.jms.server.destination.TopicService">
+
<annotation>(a)org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
+ <attribute
name="JNDIName">TopicMetricsOneMessageExistingTopic</attribute>
+ <depends
optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+</server>