felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1605954 - /felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/
Date Fri, 27 Jun 2014 05:31:57 GMT
Author: pderop
Date: Fri Jun 27 05:31:56 2014
New Revision: 1605954

URL: http://svn.apache.org/r1605954
Log:
Modified the TestBase class, which is now providing a getDM() method which can be called by
subclasses when 
needing to instantiate a Dependency Manager. Tests supporting parallelism can then call the
setParallel(true)
method, and the getDM() method will then set a thread pool in the returned DM.
So, An exesting synchronous test can be played in parallel by just subclassing it and calling
the setParallel(true) method.
Notice that currently, not all tests can be played in parallel (only tests ending with an
"Ensure.waitForStep()" call can be
played in parallel).

Added:
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AdapterWithInstanceBoundDependencyParallelTest.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AspectDynamicsParallelTest.java
Modified:
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AdapterWithInstanceBoundDependencyTest.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AspectDynamicsTest.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AspectWithPropagationTest.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/TestBase.java

Added: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AdapterWithInstanceBoundDependencyParallelTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AdapterWithInstanceBoundDependencyParallelTest.java?rev=1605954&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AdapterWithInstanceBoundDependencyParallelTest.java
(added)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AdapterWithInstanceBoundDependencyParallelTest.java
Fri Jun 27 05:31:56 2014
@@ -0,0 +1,7 @@
+package org.apache.felix.dm.itest;
+
+public class AdapterWithInstanceBoundDependencyParallelTest extends AdapterWithInstanceBoundDependencyTest
{
+    public AdapterWithInstanceBoundDependencyParallelTest() {
+        setParallel(true);
+    }
+}

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AdapterWithInstanceBoundDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AdapterWithInstanceBoundDependencyTest.java?rev=1605954&r1=1605953&r2=1605954&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AdapterWithInstanceBoundDependencyTest.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AdapterWithInstanceBoundDependencyTest.java
Fri Jun 27 05:31:56 2014
@@ -24,7 +24,7 @@ import org.apache.felix.dm.DependencyMan
 
 public class AdapterWithInstanceBoundDependencyTest extends TestBase {
     public void testInstanceBoundDependency() {
-        DependencyManager m = new DependencyManager(context);
+        DependencyManager m = getDM();
         // helper class that ensures certain steps get executed in sequence
         Ensure e = new Ensure();
         // create a service provider and consumer

Added: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AspectDynamicsParallelTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AspectDynamicsParallelTest.java?rev=1605954&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AspectDynamicsParallelTest.java
(added)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AspectDynamicsParallelTest.java
Fri Jun 27 05:31:56 2014
@@ -0,0 +1,7 @@
+package org.apache.felix.dm.itest;
+
+public class AspectDynamicsParallelTest extends AspectDynamicsTest {
+    public AspectDynamicsParallelTest() {
+        setParallel(true);
+    }
+}

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AspectDynamicsTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AspectDynamicsTest.java?rev=1605954&r1=1605953&r2=1605954&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AspectDynamicsTest.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AspectDynamicsTest.java
Fri Jun 27 05:31:56 2014
@@ -5,7 +5,7 @@ import org.apache.felix.dm.DependencyMan
 public class AspectDynamicsTest extends TestBase {
 
 	public void testDynamicallyAddAndRemoveAspect() {
-        DependencyManager m = new DependencyManager(context);
+        DependencyManager m = getDM();
         // helper class that ensures certain steps get executed in sequence
         Ensure e = new Ensure();
         // create a service provider and consumer

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AspectWithPropagationTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AspectWithPropagationTest.java?rev=1605954&r1=1605953&r2=1605954&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AspectWithPropagationTest.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AspectWithPropagationTest.java
Fri Jun 27 05:31:56 2014
@@ -25,7 +25,7 @@ public class AspectWithPropagationTest e
     private final Random _rnd = new Random();
     private static Ensure m_invokeStep;
     private static Ensure m_changeStep;
-    
+        
     /**
      * This test does the following:
      * 
@@ -39,7 +39,7 @@ public class AspectWithPropagationTest e
      */
     public void testAspectsWithPropagation() {
         System.out.println("----------- Running testAspectsWithPropagation ...");
-        DependencyManager m = new DependencyManager(context);
+        DependencyManager m = getDM();
         // helper class that ensures certain steps get executed in sequence
         m_invokeStep = new Ensure(); 
         
@@ -157,7 +157,7 @@ public class AspectWithPropagationTest e
      */
     public void testAspectsWithPropagationAndNoCallbacks() {
         System.out.println("----------- Running testAspectsWithPropagation ...");
-        DependencyManager m = new DependencyManager(context);
+        DependencyManager m = getDM();
         // helper class that ensures certain steps get executed in sequence
         m_invokeStep = new Ensure(); 
         
@@ -258,7 +258,7 @@ public class AspectWithPropagationTest e
     public void testAdapterWithAspectsAndPropagation() {
         System.out.println("----------- Running testAdapterWithAspectsAndPropagation ...");
 
-        DependencyManager m = new DependencyManager(context);
+        DependencyManager m = getDM();
         m_invokeStep = new Ensure(); 
         
         // Create our original "S" service.
@@ -354,7 +354,7 @@ public class AspectWithPropagationTest e
     public void testAdapterWithAspectsAndPropagationNoCallbacks() {
         System.out.println("----------- Running testAdapterWithAspectsAndPropagationNoCallbacks
...");
 
-        DependencyManager m = new DependencyManager(context);
+        DependencyManager m = getDM();
         m_invokeStep = new Ensure(); 
         
         // Create our original "S" service.

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/TestBase.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/TestBase.java?rev=1605954&r1=1605953&r2=1605954&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/TestBase.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/TestBase.java
Fri Jun 27 05:31:56 2014
@@ -4,6 +4,9 @@ import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 import junit.framework.TestCase;
 
@@ -25,6 +28,10 @@ public abstract class TestBase extends T
     // Default OSGI log service level.
     protected final static int LOG_LEVEL = LogService.LOG_WARNING;
     
+    // optional thread pool used by parallel dependency managers
+    private final static ExecutorService m_threadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
+    private boolean m_useThreadPool = false;
+    
     // By default, we clear all dependendency managers when a test is done. Overriden by
runtime tests, 
     // where we must not clear managers created by the runtime itself.
     protected final boolean m_autoClearDependencyManagers;
@@ -45,6 +52,10 @@ public abstract class TestBase extends T
         m_autoClearDependencyManagers = autoClearDependencyManagers;
     }
     
+    protected void setParallel(boolean parallel) {
+        m_useThreadPool = parallel;
+    }
+    
     public void setUp() throws Exception {
     	warn("Setting up test " + getClass().getName());
     	context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
@@ -61,6 +72,14 @@ public abstract class TestBase extends T
     	}
     }
     
+    protected DependencyManager getDM() {
+        DependencyManager dm = new DependencyManager(context);
+        if (m_useThreadPool) {        
+            dm.setThreadPool(m_threadPool);
+        }
+        return dm;
+    }
+    
     protected void clearAllManagers() {
         // clear all dependency managers
         List<DependencyManager> list = DependencyManager.getDependencyManagers();



Mime
View raw message