KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jca > test > StatisticsReporterUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.jca.test;
23
24 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
25 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
26
27 import org.jboss.logging.Logger;
28 import org.jboss.resource.connectionmanager.BaseConnectionManager2;
29 import org.jboss.resource.connectionmanager.CachedConnectionManager;
30 import org.jboss.resource.connectionmanager.InternalManagedConnectionPool;
31 import org.jboss.resource.connectionmanager.JBossManagedConnectionPool;
32 import org.jboss.resource.connectionmanager.ManagedConnectionPool;
33 import org.jboss.resource.connectionmanager.NoTxConnectionManager;
34 import org.jboss.resource.connectionmanager.InternalManagedConnectionPool.PoolParams;
35 import org.jboss.resource.connectionmanager.JBossManagedConnectionPool.PoolByCri;
36 import org.jboss.resource.statistic.StatisticsReporter;
37 import org.jboss.test.JBossTestCase;
38 import org.jboss.test.jca.adapter.TestConnectionRequestInfo;
39 import org.jboss.test.jca.adapter.TestManagedConnectionFactory;
40
41 /**
42  * A StatisticsReporterUnitTestCase.
43  *
44  * @author <a HREF="weston.price@jboss.com">Weston Price</a>
45  * @version $Revision: 44973 $
46  */

47 public class StatisticsReporterUnitTestCase extends JBossTestCase
48 {
49
50    Logger log = Logger.getLogger(getClass());
51
52    ConnectionRequestInfo JavaDoc cri = new TestConnectionRequestInfo();
53
54    CachedConnectionManager ccm = new CachedConnectionManager();
55
56    public StatisticsReporterUnitTestCase(String JavaDoc name)
57    {
58
59       super(name);
60
61    }
62
63    private BaseConnectionManager2 getCM(InternalManagedConnectionPool.PoolParams pp) throws Exception JavaDoc
64    {
65       ManagedConnectionFactory JavaDoc mcf = new TestManagedConnectionFactory();
66       ManagedConnectionPool poolingStrategy = new JBossManagedConnectionPool.OnePool(mcf, pp, false, log);
67       BaseConnectionManager2 cm = new NoTxConnectionManager(ccm, poolingStrategy);
68       poolingStrategy.setConnectionListenerFactory(cm);
69
70       return cm;
71    }
72    
73    private BaseConnectionManager2 getCriCM(InternalManagedConnectionPool.PoolParams pp){
74       
75       ManagedConnectionFactory JavaDoc mcf = new TestManagedConnectionFactory();
76       ManagedConnectionPool poolingStrategy = new JBossManagedConnectionPool.PoolByCri(mcf, pp, true, log);
77       BaseConnectionManager2 cm = new NoTxConnectionManager(ccm, poolingStrategy);
78       poolingStrategy.setConnectionListenerFactory(cm);
79       return cm;
80    }
81
82    public void testSimpleStatistics() throws Exception JavaDoc
83    {
84
85       InternalManagedConnectionPool.PoolParams pp = new InternalManagedConnectionPool.PoolParams();
86       pp.minSize = 5;
87       pp.maxSize = 10;
88       pp.blockingTimeout = 1000;
89       pp.idleTimeout = 500;
90       BaseConnectionManager2 cm = getCriCM(pp);
91   
92       cm.getManagedConnection(null, null);
93       StatisticsReporter reporter = (StatisticsReporter) cm.getPoolingStrategy();
94       Object JavaDoc stats = reporter.listStatistics();
95
96       Thread.sleep(10000);
97       stats = reporter.listStatistics();
98       
99       
100
101    }
102
103 // public static Test suite() throws Exception
104
// {
105
// ClassLoader loader = Thread.currentThread().getContextClassLoader();
106
// URL resURL = loader.getResource("jca/stats/stats-ds.xml");
107
// return getDeploySetup(StatisticsReporterUnitTestCase.class, resURL.toString());
108
// }
109
}
110
Popular Tags