[embjopr-commits] EMBJOPR SVN: r121 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit.

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Wed Jan 21 16:56:52 EST 2009


Author: fjuma
Date: 2009-01-21 16:56:52 -0500 (Wed, 21 Jan 2009)
New Revision: 121

Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
Log:
Reapplying my modifications to the datasource metrics tests from r112 that were lost after r118.


Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java	2009-01-21 17:26:27 UTC (rev 120)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java	2009-01-21 21:56:52 UTC (rev 121)
@@ -62,7 +62,7 @@
 
 			// Some of these values are specific for AS 5.  TODO: Think up some way to split nicely.
 			LOCAL_TX_DATASOURCE("Local TX Datasources", "LocalTxCM", "local-tx-datasource", "default__Local TX Datasource"),
-			NO_TX_DATASOURCE(   "No TX Datasources",    "NoTxCM",    "no-tx-datasource",    "default__No TX Datasource"),  // TODO: Fill the value.
+			NO_TX_DATASOURCE(   "No TX Datasources",    "NoTxCM",    "no-tx-datasource",    "default__No TX Datasource"),  
 			XA_DATASOURCE(      "XA Datasources",       "XATxCM",    "xa-datasource",       "default__XA Datasource");
 
 			protected String label;
@@ -554,7 +554,7 @@
     }
 
     /*
-     * PRELIMINARY METRICS TESTS
+     * METRICS TESTS
      */
 
     /**
@@ -592,7 +592,9 @@
         Map<String, String> propertiesMap = createLocalTXDatasource("MetricsInitalConnectionDS");
 
         // Create the first connection
-        Connection con = connectDB(propertiesMap.get("jndi-name"), "sa", "");
+        Connection con = connectDB(propertiesMap.get("jndi-name"),  
+                                   propertiesMap.get("user-name"), 
+                                   propertiesMap.get("password"));
         assertNotNull(con);
 
         // Set up the expected values
@@ -625,7 +627,9 @@
         // Establish multiple connections
         ArrayList<Connection> connections = new ArrayList<Connection>();
         for(int i = 0; i <= 5; i++) {
-            Connection con = connectDB(propertiesMap.get("jndi-name"), "sa", "");
+            Connection con = connectDB(propertiesMap.get("jndi-name"),
+                                       propertiesMap.get("user-name"), 
+                                       propertiesMap.get("password")); 
             assertNotNull(con);
             connections.add(con);
         }
@@ -651,8 +655,53 @@
         deleteDatasource(propertiesMap.get("jndi-name"));
     }
 
+    /**
+     * Make sure the metrics are updated appropriately after
+     * closing some connections.
+     */
+    public void testMetricsAfterClosingConnections() throws Exception {
+        
+        // Min pool size will be 5, max pool size will be 20
+        Map<String, String> propertiesMap = createNoTXDatasource("MetricsCloseConnectionsDS");
+        
+        // Establish some connections
+        ArrayList<Connection> connections = new ArrayList<Connection>();
+        for(int i = 0; i <= 4; i++) {
+            Connection con = connectDB(propertiesMap.get("jndi-name"), 
+                                       propertiesMap.get("user-name"), 
+                                       propertiesMap.get("password"));
+            assertNotNull(con);
+            connections.add(con);
+        }
 
+        // Close some connections
+        disconnectDB(connections.get(0));
+        disconnectDB(connections.get(1));
 
+        // Set up the expected values
+        Map<String, String> expectedMetrics = new HashMap<String, String>();
+        expectedMetrics.put("Available Connection Count", "17.0"); 
+        expectedMetrics.put("Connection Count", "3.0");          
+        expectedMetrics.put("Connection Created Count", "5.0");    
+        expectedMetrics.put("Connection Destroyed Count", "0.0");   
+        expectedMetrics.put("In Use Connection Count", "3.0");     
+        expectedMetrics.put("Max Connections In Use Count", "5.0");
+        expectedMetrics.put("Max Size", "20.0");
+        expectedMetrics.put("Min Size", "5.0");
+
+        checkMetrics(propertiesMap.get("jndi-name"), DatasourceType.NO_TX_DATASOURCE, expectedMetrics); 
+        
+        // Clean up
+        for(int i = 2; i <= 4; i++) {
+            disconnectDB(connections.get(i));
+        }
+        
+        deleteDatasource(propertiesMap.get("jndi-name"));
+    }
+
+
+
+
 		
 
 
@@ -854,8 +903,8 @@
      * @param metricsMap maps metric names to the expected metric values.
      */
     protected void checkMetrics(String datasourceName,
-                              DatasourceType datasourceType,
-                              Map<String, String> metricsMap) throws IOException {
+                                DatasourceType datasourceType,
+                                Map<String, String> metricsMap) throws IOException {
 
         refreshTreeNode("Datasources");
         ClickableElement datasourceTypeArrow = getNavTreeArrow(datasourceType.getLabel());
@@ -870,7 +919,8 @@
 
         for(Iterator i = metricsMap.keySet().iterator(); i.hasNext();) {
             String metricName = (String)i.next();
-            assertEquals(metricsMap.get(metricName),
+            assertEquals("Incorrect metric value for: " + metricName,
+                         metricsMap.get(metricName),
                          getMetricValueFromTable(metricName, "dataTable"));
         }
 
@@ -878,10 +928,16 @@
         HtmlAnchor summaryLink = (HtmlAnchor)client.getElement("summaryTab");
         summaryLink.click();
 
-        assertEquals(metricsMap.get("Available Connection Count"),
-                     getMetricValueFromTable("Available Connection Count", "dataTable"));
-        assertEquals(metricsMap.get("Connection Count"),
-                     getMetricValueFromTable("Connection Count", "dataTable"));
+        ArrayList<String> summaryMetrics = new ArrayList<String>();
+        summaryMetrics.add("Available Connection Count");
+        summaryMetrics.add("Connection Count");
+        
+        for(Iterator i = summaryMetrics.iterator(); i.hasNext();) {
+            String metricName = (String)i.next();
+            assertEquals("Incorrect metric value for: " + metricName,
+                         metricsMap.get(metricName), 
+                         getMetricValueFromTable(metricName, "dataTable"));
+        }
     }
 
 




More information about the embjopr-commits mailing list