felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1629411 - in /felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest: AspectRaceTest.java ServiceRaceTest.java
Date Sat, 04 Oct 2014 16:36:22 GMT
Author: pderop
Date: Sat Oct  4 16:36:21 2014
New Revision: 1629411

URL: http://svn.apache.org/r1629411
Log:
code cleanup

Modified:
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/AspectRaceTest.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/ServiceRaceTest.java

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/AspectRaceTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/AspectRaceTest.java?rev=1629411&r1=1629410&r2=1629411&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/AspectRaceTest.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/AspectRaceTest.java
Sat Oct  4 16:36:21 2014
@@ -25,8 +25,8 @@ import org.osgi.framework.ServiceReferen
  */
 public class AspectRaceTest extends TestBase {
     final static int SERVICES = 3;
-    final static int ASPECTS_PER_SERVICE = 3;
-    final static int ITERATIONS = 3000;
+    final static int ASPECTS_PER_SERVICE = 10;
+    final static int ITERATIONS = 1000;
     final AtomicInteger m_IDGenerator = new AtomicInteger();
     ExecutorService m_threadpool;
 
@@ -40,12 +40,11 @@ public class AspectRaceTest extends Test
                 debug("Iteration: " + loop);
                 
                 // Use a helper class to wait for components to be started/stopped.
-                int count = SERVICES + (SERVICES * ASPECTS_PER_SERVICE);
+                int count = 1 /* for controller */ + SERVICES + (SERVICES * ASPECTS_PER_SERVICE);
                 ComponentTracker tracker = new ComponentTracker(count, count);
                 
                 // Create the components (controller / services / aspects)
-                Ensure e = new Ensure(false);
-                Controller controller = new Controller(e);
+                Controller controller = new Controller();
                 Factory f = new Factory();
                 f.createComponents(controller, tracker);
                 
@@ -56,22 +55,19 @@ public class AspectRaceTest extends Test
                 if (!tracker.awaitStarted(5000)) {
                     throw new IllegalStateException("Could not start components timely.");
                 }
-
-                // Make sure the controller.start() method has been called.
-                e.waitForStep(1, 5000);
                 
                 // Check aspect chains consistency.
                 controller.checkConsistency();
                 
                 // unregister all services and aspects.
-                f.unregister();
+                f.unregisterComponents();
                 
                 // use component tracker to wait for all components to be stopped.
                 if (!tracker.awaitStopped(5000)) {
                     throw new IllegalStateException("Could not stop components timely.");
                 }
 
-                if ((loop) % 100 == 0) {
+                if ((loop) % 50 == 0) {
                     warn("Performed " + loop + " tests.");
                 }
 
@@ -185,12 +181,11 @@ public class AspectRaceTest extends Test
         
         private void createComponents(Controller controller, ComponentTracker tracker) {
             // create the controller
-            
             int controllerID = m_IDGenerator.incrementAndGet();
-            
             m_controller = m_dm.createComponent()
                 .setImplementation(controller)
-                .setComposition("getComposition");        
+                .setComposition("getComposition")
+                .add(tracker);
             for (int i = 0; i < SERVICES; i ++) {
                 m_controller.add(m_dm.createServiceDependency()
                     .setService(S.class, "(controller.id=" + controllerID + ")")
@@ -256,7 +251,7 @@ public class AspectRaceTest extends Test
             }
         }
 
-        public void unregister() throws InterruptedException, InvalidSyntaxException {  
     
+        public void unregisterComponents() throws InterruptedException, InvalidSyntaxException
{        
             m_dm.remove(m_controller);
             for (final Component s : m_services) {
                 m_dm.remove(s);
@@ -270,11 +265,6 @@ public class AspectRaceTest extends Test
     public class Controller {
         final Composition m_compo = new Composition();
         final HashSet<S> m_services = new HashSet<S>();
-        final Ensure m_ensure;
-
-        public Controller(Ensure e) {
-            m_ensure = e;
-        }
 
         Object[] getComposition() {
             return new Object[] { this, m_compo };
@@ -300,19 +290,11 @@ public class AspectRaceTest extends Test
             debug("unbind " + a);
             m_services.remove(a);
         }
-
-        /**
-         * Checks if the aspect chain is consstent. The chain may not have all the aspects,
but at least, the list must be in consistent order, meaning that we 
-         * should never see an aspect with a lower rank of the its immediate next aspect
in the chain.
-         */
-        void start() {
-            m_ensure.step(1);
-        }
         
         synchronized void checkConsistency() {
             debug("service count: %d", m_services.size());
             for (S s : m_services) {
-                debug("checking service: %s", s);
+                info("checking service: %s", s);
                 Ensure ensure = new Ensure(false);
                 s.invoke(ensure);
             }

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/ServiceRaceTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/ServiceRaceTest.java?rev=1629411&r1=1629410&r2=1629411&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/ServiceRaceTest.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/ServiceRaceTest.java
Sat Oct  4 16:36:21 2014
@@ -63,13 +63,7 @@ public class ServiceRaceTest extends Tes
     
     void doStart() {
         info("Starting createParallelComponentRegistgrationUnregistration test");
-        int cores = Math.max(16, Runtime.getRuntime().availableProcessors());
-        info("using " + cores + " cores.");
-
-        if (! m_parallel) { 
-            // We are not using a parallel DM, so we create a custom threadpool in order
to add components concurrently.
-            m_threadpool = Executors.newFixedThreadPool(Math.max(cores, DEPENDENCIES + 3
/* start/stop/configure */));
-        }
+        initThreadPool(); // only if setParallel() has not been called (only if a parallel
DM is not used).
 
         try {
             m_timeStamp = System.currentTimeMillis();
@@ -81,16 +75,25 @@ public class ServiceRaceTest extends Tes
             error("got unexpected exception", t);
         }
         finally {
-            shutdown(m_threadpool);
+            shutdownThreadPool();
             m_done.step(1);
         }
     }
 
-    void shutdown(ExecutorService exec) {
-        if (! m_parallel && exec != null) {
-            exec.shutdown();
+    private void initThreadPool() {
+        if (! m_parallel) { 
+            // We are not using a parallel DM, so we create a custom threadpool in order
to add components concurrently.
+            int cores = Math.max(16, Runtime.getRuntime().availableProcessors());
+            info("using " + cores + " cores.");
+            m_threadpool = Executors.newFixedThreadPool(Math.max(cores, DEPENDENCIES + 3
/* start/stop/configure */));
+        }
+    }
+
+    void shutdownThreadPool() {
+        if (! m_parallel && m_threadpool != null) {
+            m_threadpool.shutdown();
             try {
-                exec.awaitTermination(5, TimeUnit.SECONDS);
+                m_threadpool.awaitTermination(5, TimeUnit.SECONDS);
             } catch (InterruptedException e) {
             }
         }
@@ -233,11 +236,15 @@ public class ServiceRaceTest extends Tes
 
         public void updated(Dictionary conf) throws ConfigurationException {
             m_conf = conf;
-            if (conf != null) {
-                Assert.assertEquals("bar", conf.get("foo"));
-                m_step.step(1);
-            } else {
-                m_step.step();
+            try {
+                if (conf != null) {
+                    Assert.assertEquals("bar", conf.get("foo"));
+                    m_step.step(1);
+                } else {
+                    m_step.step();
+                }
+            } catch (Throwable t) {
+                m_step.throwable(t);
             }
         }
         



Mime
View raw message