[jboss-cvs] JBossAS SVN: r83450 - in branches/Branch_5_0: 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
Tue Jan 27 00:13:29 EST 2009
Author: jhowell at redhat.com
Date: 2009-01-27 00:13:29 -0500 (Tue, 27 Jan 2009)
New Revision: 83450
Added:
branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeout.java
branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeoutResults.java
Modified:
branches/Branch_5_0/connector/src/main/org/jboss/resource/work/WorkWrapper.java
branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapter.java
branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterMBean.java
branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/test/WorkManagerUnitTestCase.java
Log:
[JBAS-6400] Add test cases and also add condition for timeout as unknown. It's possible that the timeout could be -1, in which case we will have a large negative number passed to the thread pool.
Modified: branches/Branch_5_0/connector/src/main/org/jboss/resource/work/WorkWrapper.java
===================================================================
--- branches/Branch_5_0/connector/src/main/org/jboss/resource/work/WorkWrapper.java 2009-01-27 05:11:30 UTC (rev 83449)
+++ branches/Branch_5_0/connector/src/main/org/jboss/resource/work/WorkWrapper.java 2009-01-27 05:13:29 UTC (rev 83450)
@@ -181,10 +181,18 @@
return startTimeout;
}
+ /**
+ * Get the completion time in milliseconds
+ */
public long getCompletionTimeout()
{
- // [JBAS-6400] Conversion of seconds to milliseconds
- return executionContext.getTransactionTimeout() * 1000L;
+ 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/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapter.java
===================================================================
--- branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapter.java 2009-01-27 05:11:30 UTC (rev 83449)
+++ branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapter.java 2009-01-27 05:13:29 UTC (rev 83450)
@@ -65,6 +65,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/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterMBean.java
===================================================================
--- branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterMBean.java 2009-01-27 05:11:30 UTC (rev 83449)
+++ branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterMBean.java 2009-01-27 05:13:29 UTC (rev 83450)
@@ -33,4 +33,5 @@
TestResourceAdapterTimerResults testTimer() throws Exception;
TestResourceAdapterTxInflowResults testTxInflow() throws Exception;
TestResourceAdapterWorkManagerResults testWorkManager() throws Exception;
+ TestResourceAdapterWorkManagerTxTimeoutResults testWorkManagerTxTimeout() throws Exception;
}
Added: branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeout.java
===================================================================
--- branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeout.java (rev 0)
+++ branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeout.java 2009-01-27 05:13:29 UTC (rev 83450)
@@ -0,0 +1,115 @@
+/*
+ * 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/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeoutResults.java
===================================================================
--- branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeoutResults.java (rev 0)
+++ branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/inflow/TestResourceAdapterWorkManagerTxTimeoutResults.java 2009-01-27 05:13:29 UTC (rev 83450)
@@ -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/Branch_5_0/testsuite/src/main/org/jboss/test/jca/test/WorkManagerUnitTestCase.java
===================================================================
--- branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/test/WorkManagerUnitTestCase.java 2009-01-27 05:11:30 UTC (rev 83449)
+++ branches/Branch_5_0/testsuite/src/main/org/jboss/test/jca/test/WorkManagerUnitTestCase.java 2009-01-27 05:13:29 UTC (rev 83450)
@@ -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