KickJava   Java API By Example, From Geeks To Geeks.

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


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.ResourceException JavaDoc;
25 import javax.resource.cci.ConnectionFactory JavaDoc;
26 import javax.resource.spi.ConnectionManager JavaDoc;
27 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
28 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
29 import javax.transaction.TransactionManager JavaDoc;
30
31 import org.jboss.logging.Logger;
32 import org.jboss.resource.connectionmanager.CachedConnectionManager;
33 import org.jboss.resource.connectionmanager.InternalManagedConnectionPool;
34 import org.jboss.resource.connectionmanager.JBossManagedConnectionPool;
35 import org.jboss.resource.connectionmanager.ManagedConnectionPool;
36 import org.jboss.resource.connectionmanager.TransactionSynchronizer;
37 import org.jboss.resource.connectionmanager.TxConnectionManager;
38 import org.jboss.test.jca.adapter.TestConnectionFactory;
39 import org.jboss.test.jca.adapter.TestConnectionRequestInfo;
40 import org.jboss.test.jca.adapter.TestManagedConnectionFactory;
41 import org.jboss.tm.TransactionManagerLocator;
42 import org.jboss.tm.usertx.client.ServerVMClientUserTransaction;
43
44 /**
45  * Abstract pooling stress test.
46  *
47  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
48  * @version $Revision: 43427 $
49  */

50 public class AbstractPoolingStressTest extends AbstractConcurrentStressTest
51 {
52    Logger log = Logger.getLogger(getClass());
53    Logger poolLog = Logger.getLogger(JBossManagedConnectionPool.class);
54
55    protected TransactionManager JavaDoc tm;
56    private ServerVMClientUserTransaction ut;
57    private CachedConnectionManager ccm;
58    private TestManagedConnectionFactory mcf;
59    private TxConnectionManager cm;
60    private ConnectionRequestInfo JavaDoc cri;
61    protected ConnectionFactory JavaDoc cf;
62
63    protected void setUp() throws Exception JavaDoc
64    {
65       log.debug("================> Start " + getName());
66       tm = TransactionManagerLocator.getInstance().locate();
67       TransactionSynchronizer.setTransactionManager(tm);
68       ut = new ServerVMClientUserTransaction(tm);
69       ccm = new CachedConnectionManager();
70       ut.registerTxStartedListener(ccm);
71
72       mcf = new TestManagedConnectionFactory();
73       InternalManagedConnectionPool.PoolParams pp = new InternalManagedConnectionPool.PoolParams();
74       pp.maxSize = getMaxPoolSize();
75       ManagedConnectionPool poolingStrategy = new JBossManagedConnectionPool.OnePool(mcf, pp, false, poolLog);
76       cri = new TestConnectionRequestInfo();
77       cm = new TxConnectionManager(ccm, poolingStrategy, tm);
78       if (isSticky())
79       {
80          cm.setTrackConnectionByTx(true);
81          mcf.setFailJoin(true);
82       }
83       else
84       {
85          cm.setTrackConnectionByTx(false);
86          mcf.setFailJoin(false);
87       }
88       mcf.setSleepInStart(200);
89       mcf.setSleepInEnd(200);
90       cm.setLocalTransactions(false);
91       poolingStrategy.setConnectionListenerFactory(cm);
92       cf = new TestConnectionFactory(new ConnectionManagerProxy(), mcf);
93    }
94
95    protected boolean isSticky()
96    {
97       return false;
98    }
99    
100    protected int getMaxPoolSize()
101    {
102       return 20;
103    }
104    
105    protected void tearDown() throws Exception JavaDoc
106    {
107       JBossManagedConnectionPool.OnePool pool = (JBossManagedConnectionPool.OnePool) cm.getPoolingStrategy();
108       pool.shutdown();
109       ut = null;
110       log.debug("================> End " + getName());
111    }
112    
113    protected class ConnectionManagerProxy implements ConnectionManager JavaDoc
114    {
115       /** The serialVersionUID */
116       private static final long serialVersionUID = 1L;
117
118       public Object JavaDoc allocateConnection(ManagedConnectionFactory JavaDoc mcf, ConnectionRequestInfo JavaDoc cxRequestInfo) throws ResourceException JavaDoc
119       {
120          return cm.allocateConnection(mcf, cri);
121       }
122    }
123    
124    public AbstractPoolingStressTest(String JavaDoc name)
125    {
126       super(name);
127    }
128 }
129
Popular Tags