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

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Mon Jan 19 20:02:39 EST 2009


Author: fjuma
Date: 2009-01-19 20:02:39 -0500 (Mon, 19 Jan 2009)
New Revision: 112

Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java
Log:
Made some modifications to the datasource metrics tests.


Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java	2009-01-19 19:19:33 UTC (rev 111)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java	2009-01-20 01:02:39 UTC (rev 112)
@@ -135,7 +135,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"));
         }
 
@@ -143,10 +144,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"));
+        }
     }
         
     /**
@@ -664,7 +671,7 @@
     }
     
     /*
-     * PRELIMINARY METRICS TESTS
+     * METRICS TESTS
      */
 
     /**
@@ -702,7 +709,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
@@ -735,7 +744,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);
         }
@@ -760,5 +771,49 @@
         
         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"), NO_TX_DATASOURCE, expectedMetrics); 
+        
+        // Clean up
+        for(int i = 2; i <= 4; i++) {
+            disconnectDB(connections.get(i));
+        }
+        
+        deleteDatasource(propertiesMap.get("jndi-name"));
+    } 
 }
 




More information about the embjopr-commits mailing list