[jboss-cvs] JBossAS SVN: r83359 - in branches/JBPAPP_4_2_0_GA_CP: testsuite/src/main/org/jboss/test/jca/inflow and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 23 11:51:26 EST 2009


Author: jhowell at redhat.com
Date: 2009-01-23 11:51:26 -0500 (Fri, 23 Jan 2009)
New Revision: 83359

Added:
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeout.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeoutResults.java
Modified:
   branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/work/WorkWrapper.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapter.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterMBean.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/test/WorkManagerUnitTestCase.java
Log:
[JBPAPP-1636] - added unit test case and fixed the difference in timing between the Execution Context and the thread pool

Modified: branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/work/WorkWrapper.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/work/WorkWrapper.java	2009-01-23 16:42:55 UTC (rev 83358)
+++ branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/work/WorkWrapper.java	2009-01-23 16:51:26 UTC (rev 83359)
@@ -181,9 +181,18 @@
       return startTimeout;
    }
 
+   /**
+    * Get the completion time in milliseconds
+    */
    public long getCompletionTimeout()
    {
-      return executionContext.getTransactionTimeout();
+       long timeout = executionContext.getTransactionTimeout();
+       //JBAS-6400 - The timeout in the executionContext is in seconds, so we must convert
+       //to milliseconds.  The exeception case is if it's unknown(-1l), then we just need to leave
+       //it alone.
+       if(timeout!=WorkManager.UNKNOWN)
+    	   timeout=timeout*1000;
+	   return timeout;
    }
 
    public void execute()

Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapter.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapter.java	2009-01-23 16:42:55 UTC (rev 83358)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapter.java	2009-01-23 16:51:26 UTC (rev 83359)
@@ -66,6 +66,12 @@
       return test.run();
    }
    
+   public TestResourceAdapterWorkManagerTxTimeoutResults testWorkManagerTxTimeout() throws Exception
+   {
+	   TestResourceAdapterWorkManagerTxTimeout test = new TestResourceAdapterWorkManagerTxTimeout(this);
+      return test.run();
+   }
+   
    public TestResourceAdapterTimerResults testTimer() throws Exception
    {
       TestResourceAdapterTimer test = new TestResourceAdapterTimer(this);

Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterMBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterMBean.java	2009-01-23 16:42:55 UTC (rev 83358)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterMBean.java	2009-01-23 16:51:26 UTC (rev 83359)
@@ -33,4 +33,5 @@
    TestResourceAdapterTimerResults testTimer() throws Exception;
    TestResourceAdapterTxInflowResults testTxInflow() throws Exception;
    TestResourceAdapterWorkManagerResults testWorkManager() throws Exception;
+   TestResourceAdapterWorkManagerTxTimeoutResults testWorkManagerTxTimeout() throws Exception;
 }

Added: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeout.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeout.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeout.java	2009-01-23 16:51:26 UTC (rev 83359)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.inflow;
+
+import javax.resource.spi.endpoint.MessageEndpoint;
+import javax.resource.spi.work.ExecutionContext;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkManager;
+
+/**
+ * Management interface of TestResourceAdapter.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 57211 $
+ */
+public class TestResourceAdapterWorkManagerTxTimeout
+{
+   TestResourceAdapter adapter;
+   public TestResourceAdapterWorkManagerTxTimeout(TestResourceAdapter adapter)
+   {
+      this.adapter = adapter;
+   }
+   
+   public TestResourceAdapterWorkManagerTxTimeoutResults run() throws Exception
+   {
+      TestResourceAdapterWorkManagerTxTimeoutResults results = new TestResourceAdapterWorkManagerTxTimeoutResults();
+      try
+      {
+         basicTest();
+         results.basicTest.pass();
+      }
+      catch (Throwable t)
+      {
+         results.basicTest.fail(t);
+      }
+
+      return results;
+   }
+   
+   public void basicTest() throws Exception
+   {
+      WorkManager wm = adapter.ctx.getWorkManager();
+      TestWork work = new TestWork(); 
+      ExecutionContext ctx = new ExecutionContext();
+      long timeoutSeconds=3;
+      long expectedTimeoutMillis=3*1000;
+      ctx.setTransactionTimeout(timeoutSeconds);
+      
+      long startTime=System.currentTimeMillis();
+      wm.doWork(work, 0l, ctx, null);
+      long totaltime = work.completionTime - startTime;
+      if (work.complete == false)
+      {
+    	  throw new Exception("The work was not inturrupted properly.  The worker thread was supposed to be inturrupted within 3000(ms) and was not after waiting 5000(ms)"); 
+      }
+      else
+      {
+    	  if(totaltime<expectedTimeoutMillis)
+    		  throw new Exception("The work was inturrupted too soon.  TotalTime(ms)="+totaltime+" expected time(ms)="+expectedTimeoutMillis);
+      }
+      
+      
+   }
+   
+   public class TestWork implements Work
+   {
+      public boolean complete = false;
+      public long completionTime;
+      public Object lockObject = new Object();
+      public void run()
+      {
+          
+    	  System.out.println("Curent thread is "+Thread.currentThread());
+          synchronized(lockObject)
+          {
+        	  try 
+        	  {
+				//wait for 5 seconds.  If the thread pool doesn't inturrupt us, then we have a problem
+        		  lockObject.wait(5000);
+			  } 
+        	  catch (InterruptedException e) 
+			  {
+				//We SHOULD be interrupted in this test.  If we are not interrupted, we didn't complete properly.
+				complete=true;
+			  }
+          }
+          completionTime = System.currentTimeMillis();
+      }
+
+      public void release()
+      {
+
+      }
+   }
+}

Added: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeoutResults.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeoutResults.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeoutResults.java	2009-01-23 16:51:26 UTC (rev 83359)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.inflow;
+
+import java.io.Serializable;
+
+/**
+ * Management interface of TestResourceAdapter.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 57211 $
+ */
+public class TestResourceAdapterWorkManagerTxTimeoutResults implements Serializable
+{
+   static final long serialVersionUID = -4954503231405489296L;
+   public Result basicTest = new Result();
+   
+   public void check() throws Throwable
+   {
+      basicTest.check();
+   }
+}

Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/test/WorkManagerUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/test/WorkManagerUnitTestCase.java	2009-01-23 16:42:55 UTC (rev 83358)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/jca/test/WorkManagerUnitTestCase.java	2009-01-23 16:51:26 UTC (rev 83359)
@@ -25,6 +25,7 @@
 import org.jboss.test.JBossTestCase;
 import org.jboss.test.jca.inflow.TestResourceAdapter;
 import org.jboss.test.jca.inflow.TestResourceAdapterWorkManagerResults;
+import org.jboss.test.jca.inflow.TestResourceAdapterWorkManagerTxTimeoutResults;
 
 /**
  * Inflow Unit Tests
@@ -58,4 +59,18 @@
       
       results.check(); 
    }
+   
+   public void testWorkManagerTimeout() throws Throwable
+   {
+	   TestResourceAdapterWorkManagerTxTimeoutResults results = (TestResourceAdapterWorkManagerTxTimeoutResults) getServer().invoke
+	      (
+	          TestResourceAdapter.mbean,
+	          "testWorkManagerTxTimeout",
+	          new Object[0],
+	          new String[0]
+	      );
+	      
+	      results.check(); 
+   }
+   
 }




More information about the jboss-cvs-commits mailing list