[jboss-cvs] JBossAS SVN: r111229 - in projects/jboss-jca/trunk/rhq/src/test: resources and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Apr 21 02:59:16 EDT 2011
Author: gaol
Date: 2011-04-21 02:59:16 -0400 (Thu, 21 Apr 2011)
New Revision: 111229
Modified:
projects/jboss-jca/trunk/rhq/src/test/java/org/jboss/jca/rhq/test/DsTestCase.java
projects/jboss-jca/trunk/rhq/src/test/resources/h2-ds.xml
Log:
[JBJCA-544] test DataSource JDBC Statistics
Modified: projects/jboss-jca/trunk/rhq/src/test/java/org/jboss/jca/rhq/test/DsTestCase.java
===================================================================
--- projects/jboss-jca/trunk/rhq/src/test/java/org/jboss/jca/rhq/test/DsTestCase.java 2011-04-21 06:57:03 UTC (rev 111228)
+++ projects/jboss-jca/trunk/rhq/src/test/java/org/jboss/jca/rhq/test/DsTestCase.java 2011-04-21 06:59:16 UTC (rev 111229)
@@ -23,15 +23,21 @@
import org.jboss.jca.core.api.connectionmanager.pool.Pool;
import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration;
+import org.jboss.jca.core.api.connectionmanager.pool.PoolStatistics;
import org.jboss.jca.core.api.management.DataSource;
import org.jboss.jca.core.api.management.ManagementRepository;
+import org.jboss.jca.core.spi.statistics.StatisticsPlugin;
import org.jboss.jca.rhq.core.ManagementRepositoryManager;
import org.jboss.jca.rhq.embed.core.EmbeddedJcaDiscover;
import java.io.File;
import java.net.URL;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
import java.util.List;
+import javax.naming.InitialContext;
+
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -237,7 +243,87 @@
// just not thrown exception for now.
}
+
/**
+ * Tests DataSource Statistics
+ *
+ * @throws Throwable exception
+ */
+ @Test
+ public void testDsStatistics() throws Throwable
+ {
+ DataSource ds = getDataSource();
+ StatisticsPlugin statistics = ds.getStatistics();
+ assertNotNull(statistics);
+ assertTrue(statistics.isEnabled());
+
+ PoolStatistics poolStatistics = ds.getPool().getStatistics();
+ assertNotNull(poolStatistics);
+ boolean oldEnable = poolStatistics.isEnabled();
+ poolStatistics.setEnabled(false);
+ assertFalse(poolStatistics.isEnabled());
+
+ // ds statistics
+ assertEquals(0L, statistics.getValue("PreparedStatementCacheAccessCount"));
+ assertEquals(0L, statistics.getValue("PreparedStatementCacheAddCount"));
+ assertEquals(0, statistics.getValue("PreparedStatementCacheCurrentSize"));
+ assertEquals(0L, statistics.getValue("PreparedStatementCacheDeleteCount"));
+ assertEquals(0, statistics.getValue("PreparedStatementCacheHitCount"));
+ assertEquals(0, statistics.getValue("PreparedStatementCacheMissCount"));
+
+ InitialContext context = new InitialContext();
+ javax.sql.DataSource sqlDS = (javax.sql.DataSource)context.lookup("java:/H2DS");
+ Connection sqlConn = sqlDS.getConnection();
+
+ assertEquals(0, poolStatistics.getCreatedCount());
+
+ String sql = "SHOW TABLES";
+ PreparedStatement pstmt = sqlConn.prepareStatement(sql);
+
+ long accessCount = 1L;
+ // ds statistics
+ assertEquals(accessCount, statistics.getValue("PreparedStatementCacheAccessCount"));
+ assertEquals(1L, statistics.getValue("PreparedStatementCacheAddCount"));
+ assertEquals(1, statistics.getValue("PreparedStatementCacheCurrentSize"));
+ assertEquals(0L, statistics.getValue("PreparedStatementCacheDeleteCount"));
+ assertEquals(0, statistics.getValue("PreparedStatementCacheHitCount"));
+ assertEquals(0, statistics.getValue("PreparedStatementCacheMissCount"));
+
+ pstmt.close();
+ // same SQL again
+ pstmt = sqlConn.prepareStatement(sql);
+
+ // ds statistics
+ assertEquals(accessCount + 1, statistics.getValue("PreparedStatementCacheAccessCount"));
+ assertEquals(1L, statistics.getValue("PreparedStatementCacheAddCount"));
+ assertEquals(1, statistics.getValue("PreparedStatementCacheCurrentSize"));
+ assertEquals(0L, statistics.getValue("PreparedStatementCacheDeleteCount"));
+ assertEquals(1, statistics.getValue("PreparedStatementCacheHitCount"));
+ assertEquals(0, statistics.getValue("PreparedStatementCacheMissCount"));
+
+ String sql2 = "SHOW SCHEMAS";
+ PreparedStatement pstmt2 = sqlConn.prepareStatement(sql2);
+
+ // ds statistics
+ assertEquals(accessCount + 2, statistics.getValue("PreparedStatementCacheAccessCount"));
+ assertEquals(2L, statistics.getValue("PreparedStatementCacheAddCount"));
+ assertEquals(2, statistics.getValue("PreparedStatementCacheCurrentSize"));
+ assertEquals(0L, statistics.getValue("PreparedStatementCacheDeleteCount"));
+ assertEquals(1, statistics.getValue("PreparedStatementCacheHitCount"));
+ assertEquals(0, statistics.getValue("PreparedStatementCacheMissCount"));
+
+ pstmt.close();
+ pstmt2.close();
+ sqlConn.close();
+
+ // clear all values at last
+ statistics.clear();
+ poolStatistics.setEnabled(oldEnable);
+ assertTrue(poolStatistics.isEnabled());
+ }
+
+
+ /**
* Lifecycle start, before the suite is executed
* @throws Throwable throwable exception
*/
Modified: projects/jboss-jca/trunk/rhq/src/test/resources/h2-ds.xml
===================================================================
--- projects/jboss-jca/trunk/rhq/src/test/resources/h2-ds.xml 2011-04-21 06:57:03 UTC (rev 111228)
+++ projects/jboss-jca/trunk/rhq/src/test/resources/h2-ds.xml 2011-04-21 06:59:16 UTC (rev 111229)
@@ -9,6 +9,9 @@
<user-name>sa</user-name>
<password>sa</password>
</security>
+ <statement>
+ <prepared-statement-cache-size>5</prepared-statement-cache-size>
+ </statement>
</datasource>
</datasources>
More information about the jboss-cvs-commits
mailing list