[jboss-cvs] JBossAS SVN: r97537 - trunk/testsuite/src/main/org/jboss/test/jca/test.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Dec 8 09:05:24 EST 2009


Author: jesper.pedersen
Date: 2009-12-08 09:05:24 -0500 (Tue, 08 Dec 2009)
New Revision: 97537

Modified:
   trunk/testsuite/src/main/org/jboss/test/jca/test/StatisticsFormatterUnitTestCase.java
Log:
[JBAS-7500] Sync with 6.0.0.M1

Modified: trunk/testsuite/src/main/org/jboss/test/jca/test/StatisticsFormatterUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jca/test/StatisticsFormatterUnitTestCase.java	2009-12-08 14:05:07 UTC (rev 97536)
+++ trunk/testsuite/src/main/org/jboss/test/jca/test/StatisticsFormatterUnitTestCase.java	2009-12-08 14:05:24 UTC (rev 97537)
@@ -26,6 +26,8 @@
 import java.io.StringWriter;
 import java.net.URL;
 import java.sql.Connection;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.management.Attribute;
 import javax.management.ObjectName;
@@ -69,6 +71,7 @@
    private static final String ATTRIBUTE_NAME = "StatisticsFormatter";
    private static final String RAW_STATS_METHOD = "listStatistics";
    private static final String FORMATTED_STATS_METHOD = "listFormattedSubPoolStatistics";
+   private static final String FLUSH_METHOD = "flush";
    
    public StatisticsFormatterUnitTestCase(String name){
     
@@ -110,7 +113,7 @@
       Connection conn = ds.getConnection("sa", "");
       
       Object formattedStats = StatisticsHelper.listFormattedStatistics(getServer());
-      
+
       assertTrue(formattedStats instanceof String);
       
       //Do a diff
@@ -125,10 +128,107 @@
       assertEquals(formattedStats, rawFormat);
       
       conn.close();
+   }
+
+   public void testConnectionInUse() throws Exception
+   {
+      String POOL_SEPERATOR = "------------------------------------------------------";
+
+      StringBuffer expectedBeforeBuffer = new StringBuffer();
+      expectedBeforeBuffer.append("Sub Pool Statistics: \n");
+      expectedBeforeBuffer.append("Sub Pool Count: 0\n");
+      expectedBeforeBuffer.append(POOL_SEPERATOR);
+      expectedBeforeBuffer.append("\n\n");
+
+      StringBuffer expectedAfterBuffer = new StringBuffer();
+      expectedAfterBuffer.append("Sub Pool Statistics: \n");
+      expectedAfterBuffer.append("Sub Pool Count: 0\n");
+      expectedAfterBuffer.append(POOL_SEPERATOR);
+      expectedAfterBuffer.append("\n\n");
+
+      StringBuffer expectedConn1Buffer = new StringBuffer();
+      expectedConn1Buffer.append("Sub Pool Statistics: \n");
+      expectedConn1Buffer.append("Sub Pool Count: 1\n");
+      expectedConn1Buffer.append(POOL_SEPERATOR);
+      expectedConn1Buffer.append("\n\n");
+      expectedConn1Buffer.append("Available Connections Count: 9\n");
+      expectedConn1Buffer.append("Max Connections In Use Count:1\n");
+      expectedConn1Buffer.append("Connections Destroyed Count:0\n");
+      expectedConn1Buffer.append("Connections In Use Count:1\n");
+      expectedConn1Buffer.append("Total Block Time:\\d+\n");
+      expectedConn1Buffer.append("Average Block Time For Sub Pool:\\d+\n");
+      expectedConn1Buffer.append("Maximum Wait Time For Sub Pool:\\d+\n");
+      expectedConn1Buffer.append("Total Timed Out:\\d+\n");
+      expectedConn1Buffer.append("\n");
+      expectedConn1Buffer.append(POOL_SEPERATOR);
+      expectedConn1Buffer.append("\n\n");
+
+      StringBuffer expectedConn2Buffer = new StringBuffer();
+      expectedConn2Buffer.append("Sub Pool Statistics: \n");
+      expectedConn2Buffer.append("Sub Pool Count: 1\n");
+      expectedConn2Buffer.append(POOL_SEPERATOR);
+      expectedConn2Buffer.append("\n\n");
+      expectedConn2Buffer.append("Available Connections Count: 8\n");
+      expectedConn2Buffer.append("Max Connections In Use Count:2\n");
+      expectedConn2Buffer.append("Connections Destroyed Count:0\n");
+      expectedConn2Buffer.append("Connections In Use Count:2\n");
+      expectedConn2Buffer.append("Total Block Time:\\d+\n");
+      expectedConn2Buffer.append("Average Block Time For Sub Pool:\\d+\n");
+      expectedConn2Buffer.append("Maximum Wait Time For Sub Pool:\\d+\n");
+      expectedConn2Buffer.append("Total Timed Out:\\d+\n");
+      expectedConn2Buffer.append("\n");
+      expectedConn2Buffer.append(POOL_SEPERATOR);
+      expectedConn2Buffer.append("\n\n");
+
+      InitialContext initCtx = super.getInitialContext();
+
+      // Flush
+      Object o = getServer().invoke(POOL_NAME, FLUSH_METHOD, new Object[0], new String[0]);
+
+      // Before obtaining connections
+      Object beforeStats = StatisticsHelper.listFormattedStatistics(getServer());
+
+      assertTrue(beforeStats instanceof String);
+      assertEquals(beforeStats, expectedBeforeBuffer.toString());
+
+      // Obtaining connections
+      DataSource ds = (DataSource)initCtx.lookup("StatsDS");
+      Connection conn1 = ds.getConnection("sa", "");
       
+      Object conn1Stats = StatisticsHelper.listFormattedStatistics(getServer());
+
+      assertTrue(conn1Stats instanceof String);
+
+      Pattern p1 = Pattern.compile(expectedConn1Buffer.toString());
+      Matcher m1 = p1.matcher((String)conn1Stats);
+
+      assertTrue(m1.matches());
+
+      Connection conn2 = ds.getConnection("sa", "");
       
+      Object conn2Stats = StatisticsHelper.listFormattedStatistics(getServer());
+
+      assertTrue(conn2Stats instanceof String);
+
+      Pattern p2 = Pattern.compile(expectedConn2Buffer.toString());
+      Matcher m2 = p2.matcher((String)conn2Stats);
+
+      assertTrue(m2.matches());
+
+      conn1.close();
+      conn2.close();
+
+      // Flush
+      o = getServer().invoke(POOL_NAME, FLUSH_METHOD, new Object[0], new String[0]);
+
+      // After obtaining connections
+      Object afterStats = StatisticsHelper.listFormattedStatistics(getServer());
+
+      assertTrue(afterStats instanceof String);
+      assertEquals(afterStats, expectedAfterBuffer.toString());
    }
    
+
    public void testXmlFormatterStatistics() throws Exception{
 
       InitialContext initCtx = super.getInitialContext();
@@ -195,7 +295,6 @@
       assertEquals(formattedStats, rawFormat);
       
    }
-   
   
    
    private Object listRawStatistics() throws Exception{




More information about the jboss-cvs-commits mailing list