[jboss-cvs] JBossAS SVN: r86465 - 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 05:44:17 EDT 2009


Author: jeff.zhang
Date: 2009-03-30 05:44:17 -0400 (Mon, 30 Mar 2009)
New Revision: 86465

Added:
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/BlockRunningWork.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/CallbackCount.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/MyWorkAdapter.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/NestCharWork.java
Modified:
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagerInterfaceTestCase.java
Log:
[JBJCA-33] refactor using CountDownLatch, add some testplan

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/BlockRunningWork.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/BlockRunningWork.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/BlockRunningWork.java	2009-03-30 09:44:17 UTC (rev 86465)
@@ -0,0 +1,143 @@
+/*
+ * 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 java.util.concurrent.CountDownLatch;
+
+import javax.resource.spi.work.Work;
+
+/**
+ * BlockRunningWork.
+
+ * @author <a href="mailto:jeff.zhang at jboss.org">Jeff Zhang</a>
+ * @version $Revision: $
+ */
+public class BlockRunningWork implements Work
+{
+   /**
+    * enter run method, hasn't executed
+    */
+   private boolean preRun;
+   
+   /**
+    * enter run method, has executed
+    */
+   private boolean postRun;
+   /**
+    * Latch when before run method
+    */
+   private CountDownLatch before;
+   /**
+    * Latch when before start block
+    */
+   private CountDownLatch hold;
+   /**
+    * Latch when enter run method
+    */
+   private CountDownLatch start;
+   /**
+    * Latch when leave run method
+    */
+   private CountDownLatch done;
+   /**
+    * current thread id
+    */
+   private long threadId;
+   
+  
+   /**
+    * Constructor.
+    * @param before Latch when before run method
+    * @param hold Latch when before start block
+    * @param start Latch when enter run method
+    * @param done Latch when leave run method
+    */
+   public BlockRunningWork(CountDownLatch before, CountDownLatch hold, CountDownLatch start, CountDownLatch done) 
+   {
+      this.before = before;
+      this.hold = hold;
+      this.start = start;
+      this.done = done;
+   }
+
+   /**
+    * release method
+    */
+   public void release()
+   {
+ 
+   }
+
+   /**
+    * run method
+    */
+   public void run()
+   {
+      try
+      {
+         before.await();
+      } 
+      catch (InterruptedException e)
+      {
+         e.printStackTrace();
+      }
+      preRun = true;
+      hold.countDown(); 
+      try
+      {
+         start.await();
+      } 
+      catch (InterruptedException e)
+      {
+         e.printStackTrace();
+      }
+      threadId = Thread.currentThread().getId();
+      postRun = true;
+      done.countDown(); 
+   }
+   
+   /**
+    * @return boolean if enter run method, hasn't executed
+    */
+   public boolean hasPreRun()
+   {
+      return preRun;
+      
+   }
+   
+   /**
+    * @return boolean if enter run method, has executed
+    */
+   public boolean hasPostRun()
+   {
+      return postRun;
+   }
+
+
+   /**
+    * @return long current thread id
+    */
+   public long getThreadId()
+   {
+      return threadId;
+   }
+}


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

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/CallbackCount.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/CallbackCount.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/CallbackCount.java	2009-03-30 09:44:17 UTC (rev 86465)
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+/**
+ * class for count called times
+ */
+public class CallbackCount
+{
+   /** count accept times */
+   private int acceptCount;
+   /** count start times */
+   private int startCount;
+   /** count completed times */
+   private int completedCount;
+   
+   /**
+    * set accept count
+    * @param acceptCount accept count
+    */
+   public void setAcceptCount(int acceptCount)
+   {
+      this.acceptCount = acceptCount;
+   }
+   /**
+    * get accept count
+    * @return int accept count
+    */
+   public int getAcceptCount()
+   {
+      return acceptCount;
+   }
+   /**
+    * set start count
+    * @param startCount start count
+    */
+   public void setStartCount(int startCount)
+   {
+      this.startCount = startCount;
+   }
+   /**
+    * get start count
+    * @return int start count
+    */
+   public int getStartCount()
+   {
+      return startCount;
+   }
+   /**
+    * set complete count
+    * @param completedCount complete count
+    */
+   public void setCompletedCount(int completedCount)
+   {
+      this.completedCount = completedCount;
+   }
+   /**
+    * get complete count
+    * @return int complete count
+    */
+   public int getCompletedCount()
+   {
+      return completedCount;
+   }
+}


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

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/MyWorkAdapter.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/MyWorkAdapter.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/MyWorkAdapter.java	2009-03-30 09:44:17 UTC (rev 86465)
@@ -0,0 +1,93 @@
+/*
+ * 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;
+import javax.resource.spi.work.WorkAdapter;
+import javax.resource.spi.work.WorkEvent;
+
+/**
+ * MyWorkAdapter
+ */
+public class MyWorkAdapter extends WorkAdapter
+{
+   /** event source */
+   private Object source;
+   /** event work */
+   private Work work;
+   /** start duration time */
+   private long startDuration;
+   
+   private CallbackCount callbackCount;
+   
+   /**
+    * accept work 
+    *
+    * @param e workEvent
+    */
+   public void workAccepted(WorkEvent e) 
+   {
+      source = e.getSource();
+      work = e.getWork();
+      startDuration = e.getStartDuration();
+      callbackCount.setAcceptCount(callbackCount.getAcceptCount() + 1);
+   }
+   
+   /**
+    * get event source
+    *
+    * @return Object source
+    */
+   public Object getSource()
+   {
+      return source;
+   }
+   
+   /**
+    * get event work
+    *
+    * @return Work work reference
+    */
+   public Work getWork()
+   {
+      return work;
+   }
+   
+   /**
+    * get start duration time
+    *
+    * @return long duration time
+    */
+   public long getStartDuration()
+   {
+      return startDuration;
+   }
+   
+   /**
+    * set callback reference
+    * @param callbackCount complete count
+    */
+   public void setCallbackCount(CallbackCount callbackCount)
+   {
+      this.callbackCount = callbackCount;
+   }
+}


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

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/NestCharWork.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/NestCharWork.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/NestCharWork.java	2009-03-30 09:44:17 UTC (rev 86465)
@@ -0,0 +1,146 @@
+/*
+ * 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 java.util.concurrent.CountDownLatch;
+
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkException;
+import javax.resource.spi.work.WorkManager;
+
+/**
+ * NestCharWork.
+
+ * @author <a href="mailto:jeff.zhang at jboss.org">Jeff Zhang</a>
+ * @version $Revision: $
+ */
+public class NestCharWork implements Work
+{
+   /**
+    * shared string buffer
+    */
+   private static StringBuffer buf = new StringBuffer();
+   /**
+    * Latch when enter run method
+    */
+   private CountDownLatch start;
+   /**
+    * Latch when leave run method
+    */
+   private CountDownLatch done;
+   /**
+    * current thread id
+    */
+   private String name;
+   private WorkManager workManager = null;
+   private Work nestWork = null;
+   private boolean nestDo = false;
+  
+   /**
+    * Constructor.
+    * @param name this class name
+    * @param start Latch when enter run method
+    * @param done Latch when leave run method
+    */
+   public NestCharWork(String name, CountDownLatch start, CountDownLatch done) 
+   {
+      this.name = name;
+      this.start = start;
+      this.done = done;
+   }
+
+   /**
+    * release method
+    */
+   public void release()
+   {
+ 
+   }
+
+   /**
+    * run method
+    */
+   public void run()
+   {
+      try
+      {
+         if (nestWork != null && workManager != null)
+         {
+            if (nestDo)
+            {
+               workManager.doWork(nestWork);
+            }
+         }
+         buf.append(name);
+         start.await();
+      } 
+      catch (InterruptedException e)
+      {
+         e.printStackTrace();
+      } 
+      catch (WorkException e)
+      {
+         e.printStackTrace();
+      }
+      done.countDown(); 
+   }
+   
+   /**
+    * empty string buffer
+    */
+   public void emptyBuffer()
+   {
+      buf = new StringBuffer();
+   }
+   
+   /**
+    * @return String get string buffer
+    */
+   public String getBuffer()
+   {
+      return buf.toString();
+   }
+   
+   /**
+    * @param wm workManager
+    */
+   public void setWorkManager(WorkManager wm)
+   {
+      workManager = wm;
+   }
+   
+   /**
+    * @param work work
+    */
+   public void setWorkManager(Work work)
+   {
+      nestWork = work;
+   }
+   
+   /**
+    * @param exec if nest execute doWork
+    */
+   public void setNestDo(boolean exec)
+   {
+      nestDo = exec;
+   }
+}


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

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagerInterfaceTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagerInterfaceTestCase.java	2009-03-30 09:28:45 UTC (rev 86464)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagerInterfaceTestCase.java	2009-03-30 09:44:17 UTC (rev 86465)
@@ -22,8 +22,13 @@
 package org.jboss.jca.test.core.spec.chapter10.section3;
 
 import org.jboss.jca.test.core.spec.chapter10.SimpleBootstrapContext;
-import org.jboss.jca.test.core.spec.chapter10.SimpleWork;
+import org.jboss.jca.test.core.spec.chapter10.common.BlockRunningWork;
+import org.jboss.jca.test.core.spec.chapter10.common.CallbackCount;
+import org.jboss.jca.test.core.spec.chapter10.common.MyWorkAdapter;
+import org.jboss.jca.test.core.spec.chapter10.common.NestCharWork;
 
+import java.util.concurrent.CountDownLatch;
+
 import javax.resource.spi.BootstrapContext;
 import javax.resource.spi.work.Work;
 import javax.resource.spi.work.WorkManager;
@@ -76,15 +81,155 @@
    public void testDoWorkMethod() throws Throwable
    {
       WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
-      SimpleWork work = new SimpleWork();
-      work.setBlockRun(true);
       
-      assertFalse(work.isCallRun());
-      workManager.doWork(work);
-      assertTrue(work.isCallRun());
+      final CountDownLatch before = new CountDownLatch(1);
+      final CountDownLatch hold = new CountDownLatch(1);
+      final CountDownLatch start = new CountDownLatch(1);
+      final CountDownLatch done = new CountDownLatch(1);
+
+      BlockRunningWork mw = new BlockRunningWork(before, hold, start, done);
+
+      assertFalse(mw.hasPreRun());
+      assertFalse(mw.hasPostRun());
+
+      before.countDown();
+      start.countDown();
+      workManager.doWork(mw);
+      hold.await();
+      done.await();
+
+      assertTrue(mw.hasPreRun());
+      assertTrue(mw.hasPostRun());
    }
    
    /**
+    * doWork method: throws WorkException Thrown if an error occurs
+    * @throws Throwable throwable exception 
+    */
+   @Ignore
+   public void testDoWorkMethodThrowWorkException() throws Throwable
+   {
+      //TODO
+   }
+   
+   /**
+    * doWork method: throws WorkCompletedException indicates that a Workinstance has completed 
+    * execution with an exception.
+    * @throws Throwable throwable exception 
+    */
+   @Ignore
+   public void testDoWorkMethodThrowWorkCompletedException() throws Throwable
+   {
+      //TODO
+   }
+   
+   /**
+    * doWork method: throws WorkRejectedException indicates that a Work instance has been 
+    * rejected from further processing.
+    * @throws Throwable throwable exception 
+    */
+   @Ignore
+   public void testDoWorkMethodThrowWorkRejectedException() throws Throwable
+   {
+      //TODO
+   }
+   
+   /**
+    * doWork method: This call blocks until the Work instance completes execution. test defalut 
+    * param A maximum timeout value indicates that an action be performed arbitrarily without any time constraint.
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testDoWorkMethodWithDefaultParams() throws Throwable
+   {
+      WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
+      
+      final CountDownLatch before = new CountDownLatch(1);
+      final CountDownLatch hold = new CountDownLatch(1);
+      final CountDownLatch start = new CountDownLatch(1);
+      final CountDownLatch done = new CountDownLatch(1);
+
+      BlockRunningWork mw = new BlockRunningWork(before, hold, start, done);
+
+      assertFalse(mw.hasPreRun());
+      assertFalse(mw.hasPostRun());
+
+      before.countDown();
+      start.countDown();
+      workManager.doWork(mw, WorkManager.INDEFINITE, null, null);
+      hold.await();
+      done.await();
+
+      assertTrue(mw.hasPreRun());
+      assertTrue(mw.hasPostRun());
+   }
+   
+   /**
+    * doWork method: This call blocks until the Work instance completes execution. test IMMEDIATE 
+    * param A zero timeout value indicates an action be performed immediately. The WorkManager implementation
+    *  must timeout the action as soon as possible.
+    * @throws Throwable throwable exception 
+    */
+   @Ignore
+   public void testDoWorkMethodWithImmediateStart() throws Throwable
+   {
+      //TODO
+   }
+   
+   /**
+    * doWork method: This call blocks until the Work instance completes execution. test UNKNOWN param A constant 
+    * to indicate an unknown start delay duration or other unknown values.
+    * @throws Throwable throwable exception 
+    */
+   @Ignore
+   public void testDoWorkMethodWithUnknowStart() throws Throwable
+   {
+      //TODO
+   }
+   /**
+    * doWork method: This call blocks until the Work instance completes execution. test ExecutionContext paraman. 
+    * object containing the execution context with which the submitted Work instance must be executed.
+    * @throws Throwable throwable exception 
+    */
+   @Ignore
+   public void testDoWorkMethodWithExecutionContextParams() throws Throwable
+   {
+      //TODO
+   }
+   /**
+    * doWork method: This call blocks until the Work instance completes execution. test WorkListener param 
+    * workListener an object which would be notified when the various Work processing events
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testDoWorkMethodWithWorkListenerParams() throws Throwable
+   {
+      WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
+      
+      final CountDownLatch before = new CountDownLatch(1);
+      final CountDownLatch hold = new CountDownLatch(1);
+      final CountDownLatch start = new CountDownLatch(1);
+      final CountDownLatch done = new CountDownLatch(1);
+
+      BlockRunningWork mw = new BlockRunningWork(before, hold, start, done);
+      MyWorkAdapter wa = new MyWorkAdapter();
+      CallbackCount callbackCount = new CallbackCount();
+      wa.setCallbackCount(callbackCount);
+
+      assertFalse(mw.hasPreRun());
+      assertFalse(mw.hasPostRun());
+
+      before.countDown();
+      start.countDown();
+      workManager.doWork(mw, WorkManager.INDEFINITE, null, wa);
+      hold.await();
+      done.await();
+
+      assertEquals(1, callbackCount.getAcceptCount());
+      assertTrue(mw.hasPreRun());
+      assertTrue(mw.hasPostRun());
+   }
+   /**
     * Test for paragraph 3
     * doWork method: this provides a first in, first out (FIFO) execution start 
     *      ordering and last in, first out (LIFO) execution completion ordering guarantee.
@@ -94,16 +239,26 @@
    public void testFifoStartLifoFinish() throws Throwable
    {
       WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
-      SimpleWork workA = new SimpleWork("A");
+      final CountDownLatch startA = new CountDownLatch(1);
+      final CountDownLatch doneA = new CountDownLatch(1);
+      NestCharWork workA = new NestCharWork("A", startA, doneA);
+      
+      final CountDownLatch startB = new CountDownLatch(1);
+      final CountDownLatch doneB = new CountDownLatch(1);
+      NestCharWork workB = new NestCharWork("B", startB, doneB);
+      
+      workA.emptyBuffer();
+      workA.setNestDo(true);
       workA.setWorkManager(workManager);
-      
-      assertFalse(workA.isCallRun());
-      workA.setNestDoWork(true);
-      workA.resetStringBuffer();
+      workA.setWorkManager(workB);
+      startA.countDown();
+      startB.countDown();
       workManager.doWork(workA);
-      assertTrue(workA.isCallRun());
-      assertEquals(workA.getStringBuffer(), "BA");
-      workA = null;
+
+      doneA.await();
+      doneB.await();
+
+      assertEquals(workA.getBuffer(), "BA");
    }
    
    /**
@@ -116,15 +271,28 @@
    public void testStartWorkMethod() throws Throwable
    {
       WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
-      SimpleWork work = new SimpleWork();
-      work.setBlockRun(true);
       
-      assertFalse(work.isCallRun());
-      workManager.startWork(work);
-      assertFalse(work.isCallRun());
-      Thread.currentThread().sleep(SimpleWork.BLOCK_TIME + SimpleWork.FOLLOW_TIME);
-      assertTrue(work.isCallRun());
-      work = null;
+      final CountDownLatch before = new CountDownLatch(1);
+      final CountDownLatch hold = new CountDownLatch(1);
+      final CountDownLatch start = new CountDownLatch(1);
+      final CountDownLatch done = new CountDownLatch(1);
+
+      BlockRunningWork mw = new BlockRunningWork(before, hold, start, done);
+
+      assertFalse(mw.hasPreRun());
+      assertFalse(mw.hasPostRun());
+
+      before.countDown();
+      workManager.startWork(mw);
+      hold.await();
+      assertTrue(mw.hasPreRun());
+      assertFalse(mw.hasPostRun());
+      
+      start.countDown();
+      done.await();
+
+      assertTrue(mw.hasPreRun());
+      assertTrue(mw.hasPostRun());      
    }
    
    /**
@@ -161,17 +329,26 @@
    public void testFifoStart() throws Throwable
    {
       WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
-      SimpleWork workA = new SimpleWork("A");
+      final CountDownLatch startA = new CountDownLatch(1);
+      final CountDownLatch doneA = new CountDownLatch(1);
+      NestCharWork workA = new NestCharWork("A", startA, doneA);
+      
+      final CountDownLatch startB = new CountDownLatch(1);
+      final CountDownLatch doneB = new CountDownLatch(1);
+      NestCharWork workB = new NestCharWork("B", startB, doneB);
+      
+      workA.emptyBuffer();
       workA.setWorkManager(workManager);
-      
-      assertFalse(workA.isCallRun());
-      workA.setNestStartWork(true);
-      workA.resetStringBuffer();
+      workA.setWorkManager(workB);
+      startA.countDown();
+      startB.countDown();
       workManager.startWork(workA);
+      workManager.startWork(workB);
 
-      Thread.currentThread().sleep(SimpleWork.BLOCK_TIME + SimpleWork.FOLLOW_TIME);
-      assertEquals(workA.getStringBuffer(), "AB");
-      workA = null;
+      doneA.await();
+      doneB.await();
+
+      assertEquals(workA.getBuffer(), "AB");
    }
    
    /**
@@ -184,15 +361,28 @@
    public void testScheduleWorkMethod() throws Throwable
    {
       WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
-      SimpleWork work = new SimpleWork();
-      work.setBlockRun(true);
       
-      assertFalse(work.isCallRun());
-      workManager.scheduleWork(work);
-      assertFalse(work.isCallRun());
-      Thread.currentThread().sleep(SimpleWork.BLOCK_TIME + SimpleWork.FOLLOW_TIME);
-      assertTrue(work.isCallRun());
-      work = null;
+      final CountDownLatch before = new CountDownLatch(1);
+      final CountDownLatch hold = new CountDownLatch(1);
+      final CountDownLatch start = new CountDownLatch(1);
+      final CountDownLatch done = new CountDownLatch(1);
+
+      BlockRunningWork mw = new BlockRunningWork(before, hold, start, done);
+
+      assertFalse(mw.hasPreRun());
+      assertFalse(mw.hasPostRun());
+
+      workManager.scheduleWork(mw);
+      before.countDown();
+      hold.await();
+      assertTrue(mw.hasPreRun());
+      assertFalse(mw.hasPostRun());
+      
+      start.countDown();
+      done.await();
+
+      assertTrue(mw.hasPreRun());
+      assertTrue(mw.hasPostRun()); 
    }
    
    /**
@@ -215,8 +405,8 @@
    @Test
    public void testAsImplementWorkManagerInterface() throws Throwable
    {
-      org.jboss.jca.core.workmanager.WorkManagerImpl wm = new org.jboss.jca.core.workmanager.WorkManagerImpl();
-      assertTrue(wm instanceof javax.resource.spi.work.WorkManager);
+      WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
+      assertNotNull(workManager);
    }   
    
    /**
@@ -228,14 +418,26 @@
    public void testAllowNestedWork() throws Throwable
    {
       WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
-      SimpleWork workA = new SimpleWork("A");
+      final CountDownLatch startA = new CountDownLatch(1);
+      final CountDownLatch doneA = new CountDownLatch(1);
+      NestCharWork workA = new NestCharWork("A", startA, doneA);
+      
+      final CountDownLatch startB = new CountDownLatch(1);
+      final CountDownLatch doneB = new CountDownLatch(1);
+      NestCharWork workB = new NestCharWork("B", startB, doneB);
+      
+      workA.emptyBuffer();
+      workA.setNestDo(true);
       workA.setWorkManager(workManager);
-      
-      assertFalse(workA.isCallRun());
-      workA.setNestDoWork(true);
+      workA.setWorkManager(workB);
+      startA.countDown();
+      startB.countDown();
       workManager.doWork(workA);
-      assertTrue(workA.isCallRun());
-      workA = null;
+
+      doneA.await();
+      doneB.await();
+
+      assertEquals(workA.getBuffer(), "BA");
    }
    
    /**




More information about the jboss-cvs-commits mailing list