[jboss-cvs] JBossAS SVN: r85644 - in projects/jboss-jca/trunk/core/src/test: resources/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 9 09:13:36 EDT 2009


Author: jeff.zhang
Date: 2009-03-09 09:13:36 -0400 (Mon, 09 Mar 2009)
New Revision: 85644

Added:
   projects/jboss-jca/trunk/core/src/test/resources/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagementModelTestCase-jboss-beans.xml
Modified:
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagementModelTestCase.java
   projects/jboss-jca/trunk/core/src/test/resources/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagerInterfaceTestCase-jboss-beans.xml
Log:
[JBJCA-33] add some tests about thread pool

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagementModelTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagementModelTestCase.java	2009-03-09 13:12:46 UTC (rev 85643)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagementModelTestCase.java	2009-03-09 13:13:36 UTC (rev 85644)
@@ -21,8 +21,20 @@
  */
 package org.jboss.jca.test.core.spec.chapter10.section3;
 
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkManager;
+
+import org.jboss.ejb3.test.mc.bootstrap.EmbeddedTestMcBootstrap;
+import org.jboss.jca.common.api.ThreadPool;
+import org.jboss.jca.common.threadpool.ThreadPoolImpl;
+
+import org.jboss.jca.test.core.spec.chapter10.SimpleBootstrapContext;
+import org.jboss.jca.test.core.spec.chapter10.SimpleWork;
+
 import org.junit.AfterClass;
 import static org.junit.Assert.* ;
+
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -37,8 +49,11 @@
  */
 public class WorkManagementModelTestCase
 {
-
-   
+   /*
+    * Bootstrap (MC Facade)
+    */
+   private static EmbeddedTestMcBootstrap bootstrap;
+      
    /**
     * Test for paragraph 1
     * A resource adapter obtains a WorkManager instance from the BootstrapContext
@@ -47,7 +62,10 @@
    @Test
    public void testGetWorkManagerFromBootstrapConext() throws Throwable
    {
-      
+      BootstrapContext bootstrapContext = bootstrap.lookup("SimpleBootstrapContext", SimpleBootstrapContext.class);
+      assertTrue(bootstrapContext instanceof SimpleBootstrapContext);
+
+      assertNotNull(bootstrapContext.getWorkManager());
    }
 
    /**
@@ -56,9 +74,22 @@
     *            Work instance, sets up an appropriate execution context and 
     *            calls the run method on the Work instance. 
     */
-   @Ignore
+   @Test
    public void testOneThreadPickWorkInstance() throws Throwable
    {
+      WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
+      ThreadPoolImpl tpImpl = (ThreadPoolImpl)bootstrap.lookup("WorkManagerThreadPool", ThreadPool.class);
+      int poolNum = tpImpl.getPoolNumber();
+      int poolSize = tpImpl.getPoolSize();
+
+      SimpleWork work = new SimpleWork();
+      work.setBlockRun(true);
+      
+      assertFalse(work.isCallRun());
+      workManager.scheduleWork(work);
+      
+      assertEquals(poolNum, tpImpl.getPoolNumber());
+      assertEquals(poolSize + 1, tpImpl.getPoolSize());
    }
    
    /**
@@ -66,9 +97,30 @@
     * There is no restriction on the NUMBER of Work instances submitted by a 
     *            resource adapter or when Work instances may be submitted.
     */
-   @Ignore
+   @Test
    public void testManyWorkInstancesSubmitted() throws Throwable
    {
+      WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
+      SimpleWork work1 = new SimpleWork();
+      work1.setBlockRun(true);
+      SimpleWork work2 = new SimpleWork();
+      work2.setBlockRun(true);
+      SimpleWork work3 = new SimpleWork();
+      work3.setBlockRun(true);
+      
+      assertFalse(work1.isCallRun());
+      assertFalse(work2.isCallRun());
+      assertFalse(work3.isCallRun());
+      workManager.startWork(work1);
+      workManager.startWork(work2);
+      workManager.startWork(work3);
+      Thread.currentThread().sleep(SimpleWork.BLOCK_TIME + SimpleWork.Follow_TIME);
+      assertTrue(work1.isCallRun());
+      assertTrue(work2.isCallRun());
+      assertTrue(work3.isCallRun());
+      work1 = null;
+      work2 = null;
+      work3 = null;
    }
    
    /**
@@ -76,9 +128,28 @@
     * There is no restriction on the number of Work instances submitted by a 
     *            resource adapter or WHEN Work instances may be submitted.
     */
-   @Ignore
+   @Test
    public void testAnytimeWorkInstanceSubmitted() throws Throwable
    {
+      WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
+      SimpleWork work1 = new SimpleWork();
+      work1.setBlockRun(true);
+      SimpleWork work2 = new SimpleWork();
+      work2.setBlockRun(true);
+      
+      assertFalse(work1.isCallRun());
+      assertFalse(work2.isCallRun());
+
+      workManager.startWork(work1);
+      Thread.currentThread().sleep(SimpleWork.Follow_TIME);
+      workManager.startWork(work2);
+
+      Thread.currentThread().sleep(SimpleWork.BLOCK_TIME + SimpleWork.Follow_TIME);
+      assertTrue(work1.isCallRun());
+      assertTrue(work2.isCallRun());
+
+      work1 = null;
+      work2 = null;
    }
    
    /**
@@ -86,9 +157,23 @@
     * When the run method on the Work instance completes, the application 
     *            server reuses the thread.
     */
-   @Ignore
+   @Test
    public void testThreadBackPoolWhenWorkDone() throws Throwable
    {
+      WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
+      ThreadPoolImpl tpImpl = (ThreadPoolImpl)bootstrap.lookup("WorkManagerThreadPool", ThreadPool.class);
+      int poolNum = tpImpl.getPoolNumber();
+      int poolSize = tpImpl.getPoolSize();
+
+
+      SimpleWork work = new SimpleWork();
+      
+      assertFalse(work.isCallRun());
+      workManager.doWork(work);
+      assertTrue(work.isCallRun());
+      
+      assertEquals(poolNum, tpImpl.getPoolNumber());
+      assertEquals(poolSize, tpImpl.getPoolSize());
    }
    
    /**
@@ -121,5 +206,44 @@
    public void testAsUseThreadSamePriorityLevel() throws Throwable
    {
    }   
+   
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+   /**
+    * Lifecycle start, before the suite is executed
+    */
+   @BeforeClass
+   public static void beforeClass() throws Throwable
+   {
+      // Create and set a new MC Bootstrap
+      bootstrap = EmbeddedTestMcBootstrap.createEmbeddedMcBootstrap();
 
+      // Deploy Naming and Transaction
+      bootstrap.deploy(WorkManagerInterfaceTestCase.class.getClassLoader(), "naming-jboss-beans.xml");
+      bootstrap.deploy(WorkManagerInterfaceTestCase.class.getClassLoader(), "transaction-jboss-beans.xml");
+      
+      // Deploy Beans
+      bootstrap.deploy(WorkManagerInterfaceTestCase.class);
+   }
+
+   /**
+    * Lifecycle stop, after the suite is executed
+    */
+   @AfterClass
+   public static void afterClass() throws Throwable
+   {
+      // Undeploy Transaction and Naming
+      bootstrap.undeploy(WorkManagerInterfaceTestCase.class.getClassLoader(), "transaction-jboss-beans.xml");
+      bootstrap.undeploy(WorkManagerInterfaceTestCase.class.getClassLoader(), "naming-jboss-beans.xml");
+
+      // Undeploy Beans
+      bootstrap.undeploy(WorkManagerInterfaceTestCase.class);
+
+      // Shutdown MC
+      bootstrap.shutdown();
+
+      // Set Bootstrap to null
+      bootstrap = null;
+   }
 }

Added: projects/jboss-jca/trunk/core/src/test/resources/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagementModelTestCase-jboss-beans.xml
===================================================================
--- projects/jboss-jca/trunk/core/src/test/resources/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagementModelTestCase-jboss-beans.xml	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/resources/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagementModelTestCase-jboss-beans.xml	2009-03-09 13:13:36 UTC (rev 85644)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+    JBoss JCA
+-->
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+  <bean name="WorkManagerThreadPool" interface="org.jboss.jca.common.threadpool.ThreadPool" class="org.jboss.jca.common.threadpool.ThreadPoolImpl">
+    <!-- The name that appears in thread names -->
+    <property name="name">WorkManager</property>
+
+    <!-- The maximum amount of work in the queue -->
+    <property name="maximumQueueSize">1024</property>
+    
+    <!-- The maximum number of active threads -->
+    <property name="maximumPoolSize">100</property>
+    
+    <!-- How long to keep threads alive after their last work (default one minute) -->
+    <property name="keepAliveTime">60000</property>
+  </bean>
+
+  <bean name="WorkManager" interface="org.jboss.jca.core.api.WorkManager" class="org.jboss.jca.core.workmanager.WorkManagerImpl">
+    <!-- The thread pool -->
+    <property name="threadPool"><inject bean="WorkManagerThreadPool"/></property>
+
+    <!-- The XA terminator -->
+    <property name="XATerminator"><inject bean="TransactionManager" property="XATerminator"/></property>
+  </bean>
+  
+  <bean name="SimpleBootstrapContext" interface="javax.resource.spi.BootstrapContext" class="org.jboss.jca.test.core.spec.chapter10.SimpleBootstrapContext">
+    <!-- The work manager -->
+    <property name="workManager"><inject bean="WorkManager"/></property>
+
+    <!-- The XA terminator -->
+    <property name="XATerminator"><inject bean="TransactionManager" property="XATerminator"/></property>
+  </bean>
+</deployment>


Property changes on: projects/jboss-jca/trunk/core/src/test/resources/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagementModelTestCase-jboss-beans.xml
___________________________________________________________________
Name: svn:keywords
   + Id Reversion Date

Modified: projects/jboss-jca/trunk/core/src/test/resources/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagerInterfaceTestCase-jboss-beans.xml
===================================================================
--- projects/jboss-jca/trunk/core/src/test/resources/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagerInterfaceTestCase-jboss-beans.xml	2009-03-09 13:12:46 UTC (rev 85643)
+++ projects/jboss-jca/trunk/core/src/test/resources/org/jboss/jca/test/core/spec/chapter10/section3/WorkManagerInterfaceTestCase-jboss-beans.xml	2009-03-09 13:13:36 UTC (rev 85644)
@@ -5,7 +5,7 @@
 -->
 <deployment xmlns="urn:jboss:bean-deployer:2.0">
 
-  <bean name="WorkManagerThreadPool" interface="org.jboss.jca.common.threadpool.ThreadPool" class="org.jboss.jca.common.threadpool.ThreadPoolImpl">
+  <bean name="WorkManagerThreadPool" interface="org.jboss.jca.common.api.ThreadPool" class="org.jboss.jca.common.threadpool.ThreadPoolImpl">
     <!-- The name that appears in thread names -->
     <property name="name">WorkManager</property>
 




More information about the jboss-cvs-commits mailing list