[jboss-cvs] JBossAS SVN: r86468 - in projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10: section3 and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 30 07:02:19 EDT 2009


Author: jeff.zhang
Date: 2009-03-30 07:02:19 -0400 (Mon, 30 Mar 2009)
New Revision: 86468

Added:
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/LongRunningWork.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/ShortRunningWork.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/TestWorkException.java
Modified:
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkInterfaceTestCase.java
Log:
[JBJCA-33] refactor tests

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/LongRunningWork.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/LongRunningWork.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/LongRunningWork.java	2009-03-30 11:02:19 UTC (rev 86468)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.jca.test.core.spec.chapter10.common;
+
+import javax.resource.spi.work.Work;
+
+/**
+ * LongRunningWork
+ * @version $Revision: $
+ */
+public class LongRunningWork implements Work
+{
+   private boolean wasReleased;
+   private long releaseThread;
+   
+   /**
+    * Constructor.
+    */
+   public LongRunningWork()
+   {
+   }
+   
+   /**
+    * release method
+    */
+   public void release()
+   {
+      wasReleased = true;
+      releaseThread = Thread.currentThread().getId();
+   }
+
+   /**
+    * run method
+    */
+   public void run()
+   {
+   }
+   
+   /**
+    * run method
+    * @return boolean wasReleased
+    */
+   public boolean getWasReleased()
+   {
+      return wasReleased;
+   }
+   
+   /**
+    * get releasing thread
+    * @return long thread
+    */
+   public long getReleaseThread()
+   {
+      return releaseThread;
+   }
+}
+


Property changes on: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/LongRunningWork.java
___________________________________________________________________
Name: svn:keywords
   + Id Reversion Date

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/ShortRunningWork.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/ShortRunningWork.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/ShortRunningWork.java	2009-03-30 11:02:19 UTC (rev 86468)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.jca.test.core.spec.chapter10.common;
+
+import javax.resource.spi.work.Work;
+
+/**
+ * ShortRunningWork
+ * @version $Revision: $
+ */
+public class ShortRunningWork implements Work
+{
+   private boolean wasReleased;
+   private boolean callRun;
+   private boolean throwTestWorkException;
+   /**
+    * Constructor.
+    */
+   public ShortRunningWork()
+   {
+   }
+   
+   /**
+    * release method
+    */
+   public void release()
+   {
+      wasReleased = true;
+   }
+
+   /**
+    * run method
+    */
+   public void run()
+   {
+      if (throwTestWorkException)
+         throw new TestWorkException();
+      callRun = true;
+   }
+   
+   /**
+    * run method
+    * @return boolean wasReleased
+    */
+   public boolean getWasReleased()
+   {
+      return wasReleased;
+   }
+   
+   /**
+    * call run.
+    * @return boolean
+    */   
+   public boolean hasCallRun()
+   {
+      return callRun;
+   }
+   
+   /**
+    * setWorkManager.
+    * @param throwWorkException if throw TestWorkException
+    */
+   public void setThrowWorkException(boolean throwWorkException)
+   {
+      this.throwTestWorkException = throwWorkException;
+   }
+}
+


Property changes on: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/ShortRunningWork.java
___________________________________________________________________
Name: svn:keywords
   + Id Reversion Date

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/TestWorkException.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/TestWorkException.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/TestWorkException.java	2009-03-30 11:02:19 UTC (rev 86468)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.jca.test.core.spec.chapter10.common;
+
+/**
+ * TestWorkException
+ */ 
+public class TestWorkException extends RuntimeException
+{
+   private static final long serialVersionUID = 1L;
+}


Property changes on: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/TestWorkException.java
___________________________________________________________________
Name: svn:keywords
   + Id Reversion Date

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkInterfaceTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkInterfaceTestCase.java	2009-03-30 10:15:07 UTC (rev 86467)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkInterfaceTestCase.java	2009-03-30 11:02:19 UTC (rev 86468)
@@ -24,7 +24,8 @@
 import org.jboss.jca.common.api.ThreadPool;
 import org.jboss.jca.common.threadpool.ThreadPoolImpl;
 
-import org.jboss.jca.test.core.spec.chapter10.SimpleWork;
+import org.jboss.jca.test.core.spec.chapter10.common.LongRunningWork;
+import org.jboss.jca.test.core.spec.chapter10.common.ShortRunningWork;
 import org.jboss.jca.test.core.spec.chapter10.common.SynchronizedWork;
 import org.jboss.jca.test.core.spec.chapter10.common.UnsynchronizedWork;
 
@@ -66,11 +67,11 @@
    public void testCallRunMethod() throws Throwable
    {
       WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
-      SimpleWork work = new SimpleWork();
+      ShortRunningWork work = new ShortRunningWork();
       
-      assertFalse(work.isCallRun());
+      assertFalse(work.hasCallRun());
       workManager.doWork(work);
-      assertTrue(work.isCallRun());
+      assertTrue(work.hasCallRun());
    }
 
    /**
@@ -86,8 +87,8 @@
    {
       WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
 
-      SimpleWork work = new SimpleWork();
-      work.setThrowWorkAException(true);
+      ShortRunningWork work = new ShortRunningWork();
+      work.setThrowWorkException(true);
       
       try
       {
@@ -98,7 +99,7 @@
       {
          assertNotNull(e);
          assertTrue(e instanceof WorkCompletedException);
-         assertTrue(e.getMessage().indexOf("WorkAException") > 0);
+         assertTrue(e.getMessage().indexOf("TestWorkException") > 0);
       }
    }
    
@@ -108,21 +109,18 @@
     *            instance to complete execution as soon as possible. 
     * @throws Throwable throwable exception 
     */
-   @Ignore
-   public void testReleaseMethod() throws Throwable
+   @Test
+   public void testCallReleaseMethod() throws Throwable
    {
       WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
-      ThreadPool tp = bootstrap.lookup("WorkManagerThreadPool", ThreadPoolImpl.class);
-
-      SimpleWork work = new SimpleWork();
-      work.setBlockRun(true);
-      assertFalse(work.isCallRelease());
       
-      workManager.startWork(work, WorkManager.IMMEDIATE, null, null);
-      tp.stop(false);
-      Thread.currentThread().sleep(3000);
-      //assertTrue(work.isCallRelease());
-      //TODO test fail here
+      ShortRunningWork shortWork = new ShortRunningWork();
+      workManager.startWork(shortWork);
+      assertFalse(shortWork.getWasReleased());
+      ShortRunningWork longWork = new ShortRunningWork();
+      workManager.startWork(longWork);
+      //TODO we should impl call release()
+      //assertTrue(longWork.getWasReleased();
 
    }
    
@@ -131,9 +129,16 @@
     * This would be called on a separate thread than the one currently executing the Work instance.
     * @throws Throwable throwable exception 
     */
-   @Ignore
-   public void testCalledBySeparateThread() throws Throwable
+   @Test
+   public void testCallReleaseWithOtherThread() throws Throwable
    {
+      WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
+      
+      LongRunningWork longWork = new LongRunningWork();
+      workManager.startWork(longWork);
+      long currentThread = Thread.currentThread().getId();
+      //TODO we should impl call release()
+      //assertNotSame(currentThread, longWork.getReleaseThread())
    }
    
    /**




More information about the jboss-cvs-commits mailing list