felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r884524 - in /felix/trunk/dependencymanager: core/src/main/java/org/apache/felix/dependencymanager/dependencies/ test/src/test/java/org/apache/felix/dependencymanager/test/
Date Thu, 26 Nov 2009 11:17:36 GMT
Author: marrs
Date: Thu Nov 26 11:17:36 2009
New Revision: 884524

URL: http://svn.apache.org/viewvc?rev=884524&view=rev
Log:
extended the bundle dependency test to check filtering, added debug output to the Ensure class,
fixed the BundleDependency

Modified:
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/dependencies/BundleDependency.java
    felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/BundleDependencyTest.java
    felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/Ensure.java

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/dependencies/BundleDependency.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/dependencies/BundleDependency.java?rev=884524&r1=884523&r2=884524&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/dependencies/BundleDependency.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/dependencies/BundleDependency.java
Thu Nov 26 11:17:36 2009
@@ -122,7 +122,9 @@
 		Filter filter = m_filter;
 		if (filter != null) {
 			Dictionary headers = bundle.getHeaders();
+//			System.out.println("HEADERS: " + headers);
 			if (!m_filter.match(headers)) {
+			    System.out.println("NO MATCH: " + bundle);
 				return null;
 			}
 		}
@@ -133,13 +135,12 @@
 		System.out.println("ADDED " + bundle + " " + event);
         if (makeAvailable()) {
             m_service.dependencyAvailable(this);
+            if (!isRequired()) {
+                invokeAdded(bundle);
+            }
         }
         else {
             m_service.dependencyChanged(this);
-        }
-        // try to invoke callback, if specified, but only for optional dependencies
-        // because callbacks for required dependencies are handled differently
-        if (!isRequired()) {
             invokeAdded(bundle);
         }
 	}
@@ -148,7 +149,7 @@
 		System.out.println("MODIFIED " + bundle + " " + event);
         m_service.dependencyChanged(this);
         // only invoke the changed callback if the service itself is "active"
-        if (((ServiceImpl) m_service).isRegistered()) {
+        if (m_service.isRegistered()) {
             invokeChanged(bundle);
         }
 	}
@@ -157,10 +158,12 @@
 		System.out.println("REMOVED " + bundle + " " + event);
         if (makeUnavailable()) {
             m_service.dependencyUnavailable(this);
+            if (!isRequired()) {
+                invokeRemoved(bundle);
+            }
         }
-        // try to invoke callback, if specified, but only for optional dependencies
-        // because callbacks for required dependencies are handled differently
-        if (!isRequired()) {
+        else {
+            m_service.dependencyChanged(this);
             invokeRemoved(bundle);
         }
 	}
@@ -188,20 +191,16 @@
     public void invokeAdded(Bundle serviceInstance) {
         Object[] callbackInstances = getCallbackInstances();
         if ((callbackInstances != null) && (m_callbackAdded != null)) {
-                invokeCallbackMethod(callbackInstances, m_callbackAdded, serviceInstance);
+            invokeCallbackMethod(callbackInstances, m_callbackAdded, serviceInstance);
         }
     }
 
     public void invokeChanged(Bundle serviceInstance) {
         Object[] callbackInstances = getCallbackInstances();
         if ((callbackInstances != null) && (m_callbackChanged != null)) {
-//                if (m_reference == null) {
-//                    Thread.dumpStack();
-//                }
-                invokeCallbackMethod(callbackInstances, m_callbackChanged, serviceInstance);
+            invokeCallbackMethod(callbackInstances, m_callbackChanged, serviceInstance);
         }
     }
-
     
     public void invokeRemoved() {
         invokeRemoved(m_bundleInstance);
@@ -210,16 +209,10 @@
     public void invokeRemoved(Bundle serviceInstance) {
         Object[] callbackInstances = getCallbackInstances();
         if ((callbackInstances != null) && (m_callbackRemoved != null)) {
-//                if (m_reference == null) {
-//                    Thread.dumpStack();
-//                }
-                invokeCallbackMethod(callbackInstances, m_callbackRemoved, serviceInstance);
+            invokeCallbackMethod(callbackInstances, m_callbackRemoved, serviceInstance);
         }
     }
     
-
-    
-    
     private void invokeCallbackMethod(Object[] instances, String methodName, Object service)
{
         for (int i = 0; i < instances.length; i++) {
             try {

Modified: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/BundleDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/BundleDependencyTest.java?rev=884524&r1=884523&r2=884524&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/BundleDependencyTest.java
(original)
+++ felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/BundleDependencyTest.java
Thu Nov 26 11:17:36 2009
@@ -31,13 +31,9 @@
     @Test
     public void testBundleDependencies(BundleContext context) {
         DependencyManager m = new DependencyManager(context, new Logger(context));
-        // helper class that ensures certain steps get executed in sequence
-        Ensure e = new Ensure();
         // create a service provider and consumer
-        Consumer c = new Consumer(e);
+        Consumer c = new Consumer();
         Service consumer = m.createService().setImplementation(c).add(m.createBundleDependency().setCallbacks("add",
"remove"));
-//        Service consumerWithFilter = m.createService().setImplementation(new Consumer(e)).add(m.createBundleDependency().setFilter(""));
-//        Service consumerWithStateMask = m.createService().setImplementation(new Consumer(e)).add(m.createBundleDependency().setStateMask(0));
         // add the service consumer
         m.add(consumer);
         // check if at least one bundle was found
@@ -46,16 +42,21 @@
         m.remove(consumer);
         // check if all bundles were removed correctly
         c.doubleCheck();
+        
+        // helper class that ensures certain steps get executed in sequence
+        Ensure e = new Ensure();
+        Service consumerWithFilter = m.createService().setImplementation(new FilteredConsumer(e)).add(m.createBundleDependency().setFilter("(Bundle-SymbolicName=org.apache.felix.dependencymanager)").setCallbacks("add",
"remove"));
+        // add a consumer with a filter
+        m.add(consumerWithFilter);
+        e.step(2);
+        // remove the consumer again
+        m.remove(consumerWithFilter);
+        e.step(4);
     }
     
     static class Consumer {
-        private final Ensure m_ensure;
         private int m_count = 0;
 
-        public Consumer(Ensure e) {
-            m_ensure = e;
-        }
-        
         public void add(Bundle b) {
             Assert.assertNotNull("bundle instance must not be null", b);
             m_count++;
@@ -73,4 +74,20 @@
             Assert.assertTrue("all bundles we found should have been removed again", m_count
== 0);
         }
     }
+    
+    static class FilteredConsumer {
+        private final Ensure m_ensure;
+
+        public FilteredConsumer(Ensure e) {
+            m_ensure = e;
+        }
+        
+        public void add(Bundle b) {
+            m_ensure.step(1);
+        }
+        
+        public void remove(Bundle b) {
+            m_ensure.step(3);
+        }
+    }
 }

Modified: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/Ensure.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/Ensure.java?rev=884524&r1=884523&r2=884524&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/Ensure.java
(original)
+++ felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/Ensure.java
Thu Nov 26 11:17:36 2009
@@ -26,8 +26,16 @@
  * can also have threads wait until you arrive at a certain step.
  */
 public class Ensure {
+    private static final boolean DEBUG = true;
+    private static long INSTANCE = 0;
     private static final int RESOLUTION = 100;
-    int step = 1;
+    int step = 0;
+    
+    public Ensure() {
+        if (DEBUG) {
+            INSTANCE++;
+        }
+    }
 
     /**
      * Mark this point as step <code>nr</code>.
@@ -35,8 +43,11 @@
      * @param nr the step we are in
      */
     public synchronized void step(int nr) {
-        Assert.assertEquals(nr, step);
         step++;
+        Assert.assertEquals(nr, step);
+        if (DEBUG) {
+            System.out.println("[Ensure " + INSTANCE + "] step " + step);
+        }
         notifyAll();
     }
 
@@ -51,15 +62,21 @@
      */
     public synchronized void waitForStep(int nr, int timeout) {
         final int initialTimeout = timeout;
-        while (step <= nr && timeout > 0) {
+        if (DEBUG) {
+            System.out.println("[Ensure " + INSTANCE + "] waiting for step " + nr);
+        }
+        while (step < nr && timeout > 0) {
             try {
                 wait(RESOLUTION);
                 timeout -= RESOLUTION;
             }
             catch (InterruptedException e) {}
         }
-        if (step <= nr) {
+        if (step < nr) {
             throw new IllegalStateException("Timed out waiting for " + initialTimeout + "
ms for step " + nr + ", we are still at step " + step);
         }
+        if (DEBUG) {
+            System.out.println("[Ensure " + INSTANCE + "] arrived at step " + nr);
+        }
     }
 }



Mime
View raw message