[Jboss-cvs] JBossAS SVN: r56249 - branches/JBoss_4_0_3_SP1_JBAS_3453/testsuite/src/main/org/jboss/test/jca/test

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 25 04:59:57 EDT 2006


Author: weston.price at jboss.com
Date: 2006-08-25 04:59:56 -0400 (Fri, 25 Aug 2006)
New Revision: 56249

Modified:
   branches/JBoss_4_0_3_SP1_JBAS_3453/testsuite/src/main/org/jboss/test/jca/test/PurgePolicyUnitTestCase.java
Log:
[JBAS-3453] Unit test cases for both purge policy, as well as external
code support.

Modified: branches/JBoss_4_0_3_SP1_JBAS_3453/testsuite/src/main/org/jboss/test/jca/test/PurgePolicyUnitTestCase.java
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS_3453/testsuite/src/main/org/jboss/test/jca/test/PurgePolicyUnitTestCase.java	2006-08-25 08:59:32 UTC (rev 56248)
+++ branches/JBoss_4_0_3_SP1_JBAS_3453/testsuite/src/main/org/jboss/test/jca/test/PurgePolicyUnitTestCase.java	2006-08-25 08:59:56 UTC (rev 56249)
@@ -11,100 +11,275 @@
 import org.jboss.resource.connectionmanager.JBossManagedConnectionPool;
 import org.jboss.resource.connectionmanager.ManagedConnectionPool;
 import org.jboss.resource.connectionmanager.NoTxConnectionManager;
+import org.jboss.resource.connectionmanager.PoolPurgeSupport;
 import org.jboss.resource.connectionmanager.PurgePolicy;
 import org.jboss.test.JBossTestCase;
 import org.jboss.test.jca.jdbc.TestConnection;
 
-public class PurgePolicyUnitTestCase extends JBossTestCase {
+public class PurgePolicyUnitTestCase extends JBossTestCase
+{
 
-	Logger log = Logger.getLogger(PurgePolicyUnitTestCase.class);
-	public PurgePolicyUnitTestCase(String name) 
-	{
-		super(name);
-	
-	}
-	
-	public void testByPoolPurgePolicy() throws Exception
-	{
-		 LocalManagedConnectionFactory mcf = new LocalManagedConnectionFactory();
-	      
-	      mcf.setDriverClass("org.jboss.test.jca.jdbc.TestDriver");
-	      mcf.setConnectionURL("jdbc:jboss-test-adapter");
-	      mcf.setStaleConnectionCheckerClassName("org.jboss.test.jca.support.MockStaleConnectionCheckerTrue");
-	      mcf.setSupportCodeUrl("jca/support-code/support-only-stale.xml");
-	      
-	      InternalManagedConnectionPool.PoolParams pp = new InternalManagedConnectionPool.PoolParams();
-	      pp.minSize = 5;
-	      pp.maxSize = 20;
-	      pp.blockingTimeout = 10000;
-	      pp.purgePolilcy = PurgePolicy.POOL;
+   Logger log = Logger.getLogger(PurgePolicyUnitTestCase.class);
 
-	      ManagedConnectionPool mcp = new JBossManagedConnectionPool.OnePool(mcf, pp, false, log);
-	      NoTxConnectionManager noTxn = new NoTxConnectionManager(null, mcp);
-	      mcp.setConnectionListenerFactory(noTxn);
-	      Connection conn = (Connection)noTxn.allocateConnection(mcf, null);
-	      TestConnection uc = (TestConnection)((WrappedConnection)conn).getUnderlyingConnection();
-	      uc.setFail(true);
-	      SQLException stale = new StaleConnectionException("no reason", "no state", 1);
-	      uc.setUnderlyingException(stale);
-	      uc.setUseException(true);
-	      Connection conn2 = (Connection)noTxn.allocateConnection(mcf, null);
-	      conn2.close();
-	      
-	      try
-	      {
-	         conn.createStatement().execute("blah");
-	         
-	      }catch(SQLException e)
-	      {
-	         //Normal 
-	         assertTrue("Should be StaleConnectionException", e instanceof StaleConnectionException);
-	         
-	      }
+   public PurgePolicyUnitTestCase(String name)
+   {
+      super(name);
 
-	      assertTrue("Purge should destroy pooled connections", mcp.getConnectionDestroyedCount() == pp.minSize - 1);      
+   }
+   
+   public void testPurgePolicyFatalConnection() throws Exception
+   {
+      LocalManagedConnectionFactory mcf = new LocalManagedConnectionFactory();
 
-		
-	}
-	
-	public void testByConnectionPurgePolicy() throws Exception
-	{
-		
-		 LocalManagedConnectionFactory mcf = new LocalManagedConnectionFactory();
-	      
-	      mcf.setDriverClass("org.jboss.test.jca.jdbc.TestDriver");
-	      mcf.setConnectionURL("jdbc:jboss-test-adapter");
-	      mcf.setStaleConnectionCheckerClassName("org.jboss.test.jca.support.MockStaleConnectionCheckerTrue");
-	      mcf.setSupportCodeUrl("jca/support-code/support-only-stale.xml");
-	      
-	      InternalManagedConnectionPool.PoolParams pp = new InternalManagedConnectionPool.PoolParams();
-	      pp.minSize = 1;
-	      pp.maxSize = 10;
-	      pp.blockingTimeout = 10000;
-	      pp.purgePolilcy = PurgePolicy.CONNECTION;
-	      
-	      ManagedConnectionPool mcp = new JBossManagedConnectionPool.OnePool(mcf, pp, false, log);
-	      NoTxConnectionManager noTxn = new NoTxConnectionManager(null, mcp);
-	      mcp.setConnectionListenerFactory(noTxn);
-	      Connection conn = (Connection)noTxn.allocateConnection(mcf, null);
-	      TestConnection uc = (TestConnection)((WrappedConnection)conn).getUnderlyingConnection();
-	      uc.setFail(true);
-	      SQLException stale = new StaleConnectionException("no reason", "no state", 1);
-	      uc.setUnderlyingException(stale);
-	      uc.setUseException(true);
-	      try
-	      {
-	         conn.createStatement().execute("blah");
-	         
-	      }catch(SQLException e)
-	      {
-	         //Normal 
-	         assertTrue("Should be StaleConnectionException", e instanceof StaleConnectionException);
-	         
-	      }
-	      
-	      assertTrue("StaleConnectionException should not destroy connection", mcp.getConnectionDestroyedCount() == 1);      
+      mcf.setDriverClass("org.jboss.test.jca.jdbc.TestDriver");
+      mcf.setConnectionURL("jdbc:jboss-test-adapter");
+      mcf.setStaleConnectionCheckerClassName("org.jboss.test.jca.support.MockStaleConnectionCheckerFalse");
+      mcf.setExceptionSorterClassName("org.jboss.test.jca.support.MockExceptionSorter");
+      mcf.setSupportCodeUrl("jca/support-code/support-only-stale.xml");
 
-	}
-	
+      InternalManagedConnectionPool.PoolParams pp = new InternalManagedConnectionPool.PoolParams();
+      pp.minSize = 5;
+      pp.maxSize = 20;
+      pp.blockingTimeout = 10000;
+      pp.purgePolilcy = PurgePolicy.CONNECTION;
+
+      ManagedConnectionPool mcp = new JBossManagedConnectionPool.OnePool(mcf, pp, false, log);
+      NoTxConnectionManager noTxn = new NoTxConnectionManager(null, mcp);
+      mcp.setConnectionListenerFactory(noTxn);
+      Connection conn = (Connection) noTxn.allocateConnection(mcf, null);
+      TestConnection uc = (TestConnection) ((WrappedConnection) conn).getUnderlyingConnection();
+      uc.setFail(true);
+      uc.setUseException(false);
+      
+      try
+      {
+         conn.createStatement().execute("blah");
+         fail("Connection should fail!");
+         
+      }
+      catch(SQLException e)
+      {
+         assertFalse(e instanceof StaleConnectionException);
+         
+      }
+   
+      PoolPurgeSupport support = (PoolPurgeSupport) mcp;
+      //Should not be flagged as stale
+      assertTrue("Fatal connection should not be stale " + support.getStaleConnectionCount(), support.getStaleConnectionCount() == 0);
+      assertTrue("Fatal connection should be purged " + support.getConnectionPurgeCount(), support.getConnectionPurgeCount() == 1);
+      assertTrue("Pool should not be purged " + support.getPoolPurgeCount(), support.getPoolPurgeCount() == 0);
+      
+      
+      conn.close();
+   }
+
+   public void testResetPurgePolicy() throws Exception
+   {
+      LocalManagedConnectionFactory mcf = new LocalManagedConnectionFactory();
+
+      mcf.setDriverClass("org.jboss.test.jca.jdbc.TestDriver");
+      mcf.setConnectionURL("jdbc:jboss-test-adapter");
+      mcf.setStaleConnectionCheckerClassName("org.jboss.test.jca.support.MockStaleConnectionCheckerTrue");
+      mcf.setSupportCodeUrl("jca/support-code/support-only-stale.xml");
+
+      InternalManagedConnectionPool.PoolParams pp = new InternalManagedConnectionPool.PoolParams();
+      pp.minSize = 5;
+      pp.maxSize = 20;
+      pp.blockingTimeout = 10000;
+      pp.purgePolilcy = PurgePolicy.POOL;
+
+      ManagedConnectionPool mcp = new JBossManagedConnectionPool.OnePool(mcf, pp, false, log);
+      NoTxConnectionManager noTxn = new NoTxConnectionManager(null, mcp);
+      mcp.setConnectionListenerFactory(noTxn);
+      Connection conn = (Connection) noTxn.allocateConnection(mcf, null);
+      TestConnection uc = (TestConnection) ((WrappedConnection) conn).getUnderlyingConnection();
+      uc.setFail(true);
+      SQLException stale = new StaleConnectionException("no reason", "no state", 1);
+      uc.setUnderlyingException(stale);
+      uc.setUseException(true);
+      Connection conn2 = (Connection) noTxn.allocateConnection(mcf, null);
+      conn2.close();
+
+      try
+      {
+         conn.createStatement().execute("blah");
+
+      }
+      catch (SQLException e)
+      {
+
+         assertTrue("Should be StaleConnectionException", e instanceof StaleConnectionException);
+
+      }
+
+      PoolPurgeSupport support = (PoolPurgeSupport) mcp;
+      assertTrue("Purge should destroy connections in pool" + support.getConnectionPurgeCount(), support
+            .getConnectionPurgeCount() >= pp.minSize - 1);
+      assertTrue("Purge should destroy entire pool for policy", support.getPoolPurgeCount() == 1);
+      assertTrue("Purge should destroy pool" + support.getStaleConnectionCount(),
+            support.getStaleConnectionCount() >= pp.minSize - 1);
+
+      pp.purgePolilcy = PurgePolicy.NONE;
+      mcp.flush();
+
+      conn = (Connection) noTxn.allocateConnection(mcf, null);
+      uc = (TestConnection) ((WrappedConnection) conn).getUnderlyingConnection();
+      uc.setFail(true);
+      uc.setUnderlyingException(stale);
+      uc.setUseException(true);
+      try
+      {
+         conn.createStatement().execute("blah");
+
+      }
+      catch (SQLException e)
+      {
+         //Normal 
+         assertTrue("Should be StaleConnectionException", e instanceof StaleConnectionException);
+
+      }
+
+      support = (PoolPurgeSupport) mcp;
+      assertTrue("No Purge Policy should only destroy connection and not flag as purge"
+            + support.getConnectionPurgeCount(), support.getConnectionPurgeCount() == 0);
+      assertTrue("No Purge Policy should not destroy pool " + support.getPoolPurgeCount(),
+            support.getPoolPurgeCount() == 0);
+      assertTrue("Stale connections should only equal one", support.getStaleConnectionCount() == 1);
+
+   }
+
+   public void testByPoolPurgePolicy() throws Exception
+   {
+      LocalManagedConnectionFactory mcf = new LocalManagedConnectionFactory();
+
+      mcf.setDriverClass("org.jboss.test.jca.jdbc.TestDriver");
+      mcf.setConnectionURL("jdbc:jboss-test-adapter");
+      mcf.setStaleConnectionCheckerClassName("org.jboss.test.jca.support.MockStaleConnectionCheckerTrue");
+      mcf.setSupportCodeUrl("jca/support-code/support-only-stale.xml");
+
+      InternalManagedConnectionPool.PoolParams pp = new InternalManagedConnectionPool.PoolParams();
+      pp.minSize = 5;
+      pp.maxSize = 20;
+      pp.blockingTimeout = 10000;
+      pp.purgePolilcy = PurgePolicy.POOL;
+
+      ManagedConnectionPool mcp = new JBossManagedConnectionPool.OnePool(mcf, pp, false, log);
+      NoTxConnectionManager noTxn = new NoTxConnectionManager(null, mcp);
+      mcp.setConnectionListenerFactory(noTxn);
+      Connection conn = (Connection) noTxn.allocateConnection(mcf, null);
+      TestConnection uc = (TestConnection) ((WrappedConnection) conn).getUnderlyingConnection();
+      uc.setFail(true);
+      SQLException stale = new StaleConnectionException("no reason", "no state", 1);
+      uc.setUnderlyingException(stale);
+      uc.setUseException(true);
+      Connection conn2 = (Connection) noTxn.allocateConnection(mcf, null);
+      conn2.close();
+
+      try
+      {
+         conn.createStatement().execute("blah");
+
+      }
+      catch (SQLException e)
+      {
+
+         assertTrue("Should be StaleConnectionException", e instanceof StaleConnectionException);
+
+      }
+
+      PoolPurgeSupport support = (PoolPurgeSupport) mcp;
+      assertTrue("Purge should destroy connections in pool" + support.getConnectionPurgeCount(), support
+            .getConnectionPurgeCount() >= pp.minSize - 1);
+      assertTrue("Purge should destroy entire pool for policy", support.getPoolPurgeCount() == 1);
+      assertTrue("Purge should destroy pool" + support.getStaleConnectionCount(),
+            support.getStaleConnectionCount() >= pp.minSize - 1);
+
+   }
+
+   public void testByConnectionPurgePolicy() throws Exception
+   {
+
+      LocalManagedConnectionFactory mcf = new LocalManagedConnectionFactory();
+
+      mcf.setDriverClass("org.jboss.test.jca.jdbc.TestDriver");
+      mcf.setConnectionURL("jdbc:jboss-test-adapter");
+      mcf.setStaleConnectionCheckerClassName("org.jboss.test.jca.support.MockStaleConnectionCheckerTrue");
+      mcf.setSupportCodeUrl("jca/support-code/support-only-stale.xml");
+
+      InternalManagedConnectionPool.PoolParams pp = new InternalManagedConnectionPool.PoolParams();
+      pp.minSize = 1;
+      pp.maxSize = 10;
+      pp.blockingTimeout = 10000;
+      pp.purgePolilcy = PurgePolicy.CONNECTION;
+
+      ManagedConnectionPool mcp = new JBossManagedConnectionPool.OnePool(mcf, pp, false, log);
+      NoTxConnectionManager noTxn = new NoTxConnectionManager(null, mcp);
+      mcp.setConnectionListenerFactory(noTxn);
+      Connection conn = (Connection) noTxn.allocateConnection(mcf, null);
+      TestConnection uc = (TestConnection) ((WrappedConnection) conn).getUnderlyingConnection();
+      uc.setFail(true);
+      SQLException stale = new StaleConnectionException("no reason", "no state", 1);
+      uc.setUnderlyingException(stale);
+      uc.setUseException(true);
+      try
+      {
+         conn.createStatement().execute("blah");
+
+      }
+      catch (SQLException e)
+      {
+         //Normal 
+         assertTrue("Should be StaleConnectionException", e instanceof StaleConnectionException);
+
+      }
+
+      assertTrue("StaleConnectionException should not destroy connection", mcp.getConnectionDestroyedCount() == 1);
+
+   }
+
+   public void testNoPurgePolicy() throws Exception
+   {
+      LocalManagedConnectionFactory mcf = new LocalManagedConnectionFactory();
+
+      mcf.setDriverClass("org.jboss.test.jca.jdbc.TestDriver");
+      mcf.setConnectionURL("jdbc:jboss-test-adapter");
+      mcf.setStaleConnectionCheckerClassName("org.jboss.test.jca.support.MockStaleConnectionCheckerTrue");
+      mcf.setSupportCodeUrl("jca/support-code/support-only-stale.xml");
+
+      InternalManagedConnectionPool.PoolParams pp = new InternalManagedConnectionPool.PoolParams();
+      pp.minSize = 1;
+      pp.maxSize = 10;
+      pp.blockingTimeout = 10000;
+      pp.purgePolilcy = PurgePolicy.NONE;
+
+      ManagedConnectionPool mcp = new JBossManagedConnectionPool.OnePool(mcf, pp, false, log);
+      NoTxConnectionManager noTxn = new NoTxConnectionManager(null, mcp);
+      mcp.setConnectionListenerFactory(noTxn);
+      Connection conn = (Connection) noTxn.allocateConnection(mcf, null);
+      TestConnection uc = (TestConnection) ((WrappedConnection) conn).getUnderlyingConnection();
+      uc.setFail(true);
+      SQLException stale = new StaleConnectionException("no reason", "no state", 1);
+      uc.setUnderlyingException(stale);
+      uc.setUseException(true);
+      try
+      {
+         conn.createStatement().execute("blah");
+
+      }
+      catch (SQLException e)
+      {
+         //Normal 
+         assertTrue("Should be StaleConnectionException", e instanceof StaleConnectionException);
+
+      }
+
+      PoolPurgeSupport support = (PoolPurgeSupport) mcp;
+      assertTrue("No Purge Policy should only destroy connection and not flag as purge"
+            + support.getConnectionPurgeCount(), support.getConnectionPurgeCount() == 0);
+      assertTrue("No Purge Policy should not destroy pool " + support.getPoolPurgeCount(),
+            support.getPoolPurgeCount() == 0);
+      assertTrue("Stale connections should only equal one", support.getStaleConnectionCount() == 1);
+
+   }
+
 }




More information about the jboss-cvs-commits mailing list