[jboss-cvs] JBossAS SVN: r69818 - branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 13 04:55:05 EST 2008
Author: vicky.kak at jboss.com
Date: 2008-02-13 04:55:04 -0500 (Wed, 13 Feb 2008)
New Revision: 69818
Added:
branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/StatisticsFormatterUnitTestCase.java
branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/StatisticsReporterUnitTestCase.java
Log:
JBAS-5210 changes.
Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/StatisticsFormatterUnitTestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/StatisticsFormatterUnitTestCase.java (rev 0)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/StatisticsFormatterUnitTestCase.java 2008-02-13 09:55:04 UTC (rev 69818)
@@ -0,0 +1,203 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.jca.test;
+
+import java.io.Serializable;
+import java.io.StringReader;
+import java.net.URL;
+import java.sql.Connection;
+
+import javax.management.Attribute;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.Test;
+
+import org.jboss.logging.Logger;
+import org.jboss.mx.util.ObjectNameFactory;
+import org.jboss.resource.statistic.JBossStatistics;
+import org.jboss.resource.statistic.formatter.StatisticsFormatter;
+import org.jboss.resource.statistic.pool.JBossDefaultSubPoolStatisticFormatter;
+import org.jboss.resource.statistic.pool.JBossXmlSubPoolStatisticFormatter;
+import org.jboss.resource.statistic.pool.ManagedConnectionPoolStatistics;
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.jca.statistics.StatisticsHelper;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+/**
+ * A StatisticsReporterUnitTestCase.
+ *
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision: 44973 $
+ */
+public class StatisticsFormatterUnitTestCase extends JBossTestCase
+{
+ private static final Logger log = Logger.getLogger(StatisticsFormatterUnitTestCase.class);
+
+ private static final String DEFAULT_FORMATTER = "org.jboss.resource.statistic.pool.JBossDefaultSubPoolStatisticFormatter";
+ private static final String XML_FORMATTER = "org.jboss.resource.statistic.pool.JBossXmlSubPoolStatisticFormatter";
+
+ private static final ObjectName POOL_NAME = ObjectNameFactory.create("jboss.jca:service=ManagedConnectionPool,name=StatsDS");
+ private static final String ATTRIBUTE_NAME = "StatisticsFormatter";
+ private static final String RAW_STATS_METHOD = "listStatistics";
+ private static final String FORMATTED_STATS_METHOD = "listFormattedSubPoolStatistics";
+
+ public StatisticsFormatterUnitTestCase(String name){
+
+ super(name);
+
+ }
+
+ /**
+ * Test basic formatter MBean.
+ *
+ * @throws Exception
+ */
+ public void testDefaultFormatterSetting() throws Exception{
+
+ String formatter = StatisticsHelper.getStatisticsFormatter(getServer());
+ log.debug("Found default statistics formatter " + formatter);
+ super.assertEquals(formatter, DEFAULT_FORMATTER);
+
+ }
+
+ /**
+ * FIXME Comment this
+ *
+ * @throws Exception
+ */
+ public void testRawStatistics() throws Exception{
+
+ Object result = StatisticsHelper.listRawStatistics(getServer());
+
+ assertTrue(result instanceof Serializable);
+ assertTrue(result instanceof ManagedConnectionPoolStatistics);
+
+ }
+
+ public void testDefaultFormattedStatistics() throws Exception{
+
+ InitialContext initCtx = super.getInitialContext();
+ DataSource ds = (DataSource)initCtx.lookup("StatsDS");
+ Connection conn = ds.getConnection("sa", "");
+
+ Object formattedStats = StatisticsHelper.listFormattedStatistics(getServer());
+
+ assertTrue(formattedStats instanceof String);
+
+ //Do a diff
+ Object rawStatistics = StatisticsHelper.listRawStatistics(getServer());
+
+ StatisticsFormatter defaultFormatter = StatisticsHelper.getDefaultFormatter();
+
+ ManagedConnectionPoolStatistics stats = (ManagedConnectionPoolStatistics)rawStatistics;
+
+ String rawFormat = (String)defaultFormatter.formatStatistics((JBossStatistics)stats);
+
+ assertEquals(formattedStats, rawFormat);
+
+ conn.close();
+
+
+ }
+
+ public void testXmlFormatterStatistics() throws Exception{
+
+ InitialContext initCtx = super.getInitialContext();
+ DataSource ds = (DataSource)initCtx.lookup("StatsDS");
+ Connection conn = ds.getConnection("sa", "");
+
+ setStatisticsFormatter(XML_FORMATTER);
+ Object formattedStats = (String)getServer().invoke(POOL_NAME, FORMATTED_STATS_METHOD, new Object[0], new String[0]);
+
+ assertTrue(formattedStats instanceof String);
+
+ String xml = (String)formattedStats;
+
+ StringReader reader = new StringReader(xml);
+ InputSource source = new InputSource(reader);
+
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(source);
+
+ ManagedConnectionPoolStatistics rawStatistics = (ManagedConnectionPoolStatistics)getServer().invoke(POOL_NAME, RAW_STATS_METHOD, new Object[0], new String[0]);
+ JBossXmlSubPoolStatisticFormatter xmlFormatter = new JBossXmlSubPoolStatisticFormatter();
+ String xml2 = (String)xmlFormatter.formatSubPoolStatistics(rawStatistics);
+ assertEquals(xml, xml2);
+
+ conn.close();
+
+ }
+
+ public void testInvalidFormatter() throws Exception{
+
+ ObjectName name = new ObjectName("jboss.jca:service=ManagedConnectionPool,name=StatsDS");
+
+ InitialContext initCtx = super.getInitialContext();
+ DataSource ds = (DataSource)initCtx.lookup("StatsDS");
+ Connection conn = ds.getConnection("sa", "");
+ setStatisticsFormatter("Invalid");
+
+ Object formattedStats = (String)getServer().invoke(POOL_NAME, FORMATTED_STATS_METHOD, new Object[0], new String[0]);
+
+ assertTrue(formattedStats instanceof String);
+
+ JBossDefaultSubPoolStatisticFormatter defaultFormatter = new JBossDefaultSubPoolStatisticFormatter();
+
+ Object rawStatistics = listRawStatistics();
+ ManagedConnectionPoolStatistics stats = (ManagedConnectionPoolStatistics)rawStatistics;
+
+ String rawFormat = (String)defaultFormatter.formatSubPoolStatistics(stats);
+
+ assertEquals(formattedStats, rawFormat);
+
+ }
+
+
+
+ private Object listRawStatistics() throws Exception{
+
+ return getServer().invoke(POOL_NAME, RAW_STATS_METHOD, new Object[0], new String[0]);
+
+ }
+
+ private void setStatisticsFormatter(String formatter) throws Exception{
+
+ getServer().setAttribute(POOL_NAME, new Attribute(ATTRIBUTE_NAME, formatter));
+
+ }
+
+ private String getStatisticsFormatter() throws Exception{
+
+ return (String)getServer().getAttribute(POOL_NAME, ATTRIBUTE_NAME);
+
+ }
+
+ public static Test suite() throws Exception
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ URL resURL = loader.getResource("jca/stats/default-stats-ds.xml");
+ return getDeploySetup(StatisticsFormatterUnitTestCase.class, resURL.toString());
+ }
+}
Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/StatisticsReporterUnitTestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/StatisticsReporterUnitTestCase.java (rev 0)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/StatisticsReporterUnitTestCase.java 2008-02-13 09:55:04 UTC (rev 69818)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.jca.test;
+
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnectionFactory;
+
+import org.jboss.logging.Logger;
+import org.jboss.resource.connectionmanager.BaseConnectionManager2;
+import org.jboss.resource.connectionmanager.CachedConnectionManager;
+import org.jboss.resource.connectionmanager.InternalManagedConnectionPool;
+import org.jboss.resource.connectionmanager.JBossManagedConnectionPool;
+import org.jboss.resource.connectionmanager.ManagedConnectionPool;
+import org.jboss.resource.connectionmanager.NoTxConnectionManager;
+import org.jboss.resource.connectionmanager.InternalManagedConnectionPool.PoolParams;
+import org.jboss.resource.connectionmanager.JBossManagedConnectionPool.PoolByCri;
+import org.jboss.resource.statistic.StatisticsReporter;
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.jca.adapter.TestConnectionRequestInfo;
+import org.jboss.test.jca.adapter.TestManagedConnectionFactory;
+
+/**
+ * A StatisticsReporterUnitTestCase.
+ *
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision: 44973 $
+ */
+public class StatisticsReporterUnitTestCase extends JBossTestCase
+{
+
+ Logger log = Logger.getLogger(getClass());
+
+ ConnectionRequestInfo cri = new TestConnectionRequestInfo();
+
+ CachedConnectionManager ccm = new CachedConnectionManager();
+
+ public StatisticsReporterUnitTestCase(String name)
+ {
+
+ super(name);
+
+ }
+
+ private BaseConnectionManager2 getCM(InternalManagedConnectionPool.PoolParams pp) throws Exception
+ {
+ ManagedConnectionFactory mcf = new TestManagedConnectionFactory();
+ ManagedConnectionPool poolingStrategy = new JBossManagedConnectionPool.OnePool(mcf, pp, false, log);
+ BaseConnectionManager2 cm = new NoTxConnectionManager(ccm, poolingStrategy);
+ poolingStrategy.setConnectionListenerFactory(cm);
+
+ return cm;
+ }
+
+ private BaseConnectionManager2 getCriCM(InternalManagedConnectionPool.PoolParams pp){
+
+ ManagedConnectionFactory mcf = new TestManagedConnectionFactory();
+ ManagedConnectionPool poolingStrategy = new JBossManagedConnectionPool.PoolByCri(mcf, pp, true, log);
+ BaseConnectionManager2 cm = new NoTxConnectionManager(ccm, poolingStrategy);
+ poolingStrategy.setConnectionListenerFactory(cm);
+ return cm;
+ }
+
+ public void testSimpleStatistics() throws Exception
+ {
+
+ InternalManagedConnectionPool.PoolParams pp = new InternalManagedConnectionPool.PoolParams();
+ pp.minSize = 5;
+ pp.maxSize = 10;
+ pp.blockingTimeout = 1000;
+ pp.idleTimeout = 500;
+ BaseConnectionManager2 cm = getCriCM(pp);
+
+ cm.getManagedConnection(null, null);
+ StatisticsReporter reporter = (StatisticsReporter) cm.getPoolingStrategy();
+ Object stats = reporter.listStatistics();
+ System.out.println("stats "+stats);
+ Thread.sleep(10000);
+ stats = reporter.listStatistics();
+
+
+
+ }
+
+ /*
+ public static Test suite() throws Exception
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ URL resURL = loader.getResource("jca/stats/stats-ds.xml");
+ return getDeploySetup(StatisticsReporterUnitTestCase.class, resURL.toString());
+ }
+ */
+}
More information about the jboss-cvs-commits
mailing list