felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r884346 - /felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/MultipleServiceDependencyTest.java
Date Thu, 26 Nov 2009 00:35:23 GMT
Author: marrs
Date: Thu Nov 26 00:35:23 2009
New Revision: 884346

URL: http://svn.apache.org/viewvc?rev=884346&view=rev
Log:
Added tests for auto configuration and callbacks with multiple services.

Modified:
    felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/MultipleServiceDependencyTest.java

Modified: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/MultipleServiceDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/MultipleServiceDependencyTest.java?rev=884346&r1=884345&r2=884346&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/MultipleServiceDependencyTest.java
(original)
+++ felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/MultipleServiceDependencyTest.java
Thu Nov 26 00:35:23 2009
@@ -19,84 +19,130 @@
 
 @RunWith(JUnit4TestRunner.class)
 public class MultipleServiceDependencyTest {
-    @Configuration
-    public static Option[] configuration() {
-        return options(
-            provision(
-                mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").version("4.2.0"),
-                mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager").versionAsInProject()
-            )
-        );
-    }    
-
-    @Test
-    public void testMultipleServiceRegistrationAndConsumption(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
-        Service provider = m.createService().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(),
null);
-        Service providerWithHighRank = m.createService().setImplementation(new ServiceProvider2(e)).setInterface(ServiceInterface.class.getName(),
new Properties() {{ put(Constants.SERVICE_RANKING, Integer.valueOf(5)); }});
-        Service consumer = m.createService().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
-        m.add(provider);
-        m.add(providerWithHighRank);
-        m.add(consumer);
-        e.waitForStep(3, 1000);
-        m.remove(providerWithHighRank);
-        e.step(4);
-        e.waitForStep(5, 1000);
-        m.remove(provider);
-        m.remove(consumer);
-        e.waitForStep(6, 1000);
-    }
-    
-    static interface ServiceInterface {
-        public void invoke();
-    }
-
-    static class ServiceProvider implements ServiceInterface {
-        private final Ensure m_ensure;
-        public ServiceProvider(Ensure e) {
-            m_ensure = e;
-        }
-        public void invoke() {
-            m_ensure.step(5);
-        }
-    }
-
-    static class ServiceProvider2 implements ServiceInterface {
-        private final Ensure m_ensure;
-        public ServiceProvider2(Ensure e) {
-            m_ensure = e;
-        }
-        public void invoke() {
-            m_ensure.step(2);
-        }
-    }
-
-    static class ServiceConsumer implements Runnable {
-        private volatile ServiceInterface m_service;
-        private final Ensure m_ensure;
-
-        public ServiceConsumer(Ensure e) {
-            m_ensure = e;
-        }
-        
-        public void init() {
-            Thread t = new Thread(this);
-            t.start();
-        }
-        
-        public void run() {
-            m_ensure.step(1);
-            m_service.invoke();
-            m_ensure.step(3);
-            m_ensure.waitForStep(4, 1000);
-            m_service.invoke();
-        }
-        
-        public void destroy() {
-            m_ensure.step(6);
-        }
-    }
-}
+   @Configuration
+   public static Option[] configuration() {
+       return options(
+           provision(
+               mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").version("4.2.0"),
+               mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager").versionAsInProject()
+           )
+       );
+   }    
+
+   @Test
+   public void testMultipleServiceRegistrationAndConsumption(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
+       Service provider = m.createService().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(),
null);
+       Service providerWithHighRank = m.createService().setImplementation(new ServiceProvider2(e)).setInterface(ServiceInterface.class.getName(),
new Properties() {{ put(Constants.SERVICE_RANKING, Integer.valueOf(5)); }});
+       Service consumer = m.createService().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
+       m.add(provider);
+       m.add(providerWithHighRank);
+       m.add(consumer);
+       e.waitForStep(3, 1000);
+       m.remove(providerWithHighRank);
+       e.step(4);
+       e.waitForStep(5, 1000);
+       m.remove(provider);
+       m.remove(consumer);
+       e.waitForStep(6, 1000);
+   }
+
+   @Test
+   public void testReplacementAutoConfig(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
+       Service provider = m.createService().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(),
null);
+       Service provider2 = m.createService().setImplementation(new ServiceProvider2(e)).setInterface(ServiceInterface.class.getName(),
null);
+       Service consumer = m.createService().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
+       m.add(provider2);
+       m.add(consumer);
+       e.waitForStep(3, 1000);
+       m.add(provider);
+       m.remove(provider2);
+       e.step(4);
+       e.waitForStep(5, 1000);
+       m.remove(provider);
+       m.remove(consumer);
+       e.waitForStep(6, 1000);
+   }
+
+   @Test
+   public void testReplacementCallbacks(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
+       Service provider = m.createService().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(),
null);
+       Service provider2 = m.createService().setImplementation(new ServiceProvider2(e)).setInterface(ServiceInterface.class.getName(),
null);
+       Service consumer = m.createService().setImplementation(new ServiceConsumer(e))
+         .add(m.createServiceDependency()
+              .setService(ServiceInterface.class)
+              .setRequired(true)
+              .setCallbacks("add", "remove"));
+       m.add(provider2);
+       m.add(consumer);
+       e.waitForStep(3, 1000);
+       m.add(provider);
+       m.remove(provider2);
+       e.step(4);
+       e.waitForStep(5, 1000);
+       m.remove(provider);
+       m.remove(consumer);
+       e.waitForStep(6, 1000);
+   }
+
+   static interface ServiceInterface {
+       public void invoke();
+   }
+
+   static class ServiceProvider implements ServiceInterface {
+       private final Ensure m_ensure;
+       public ServiceProvider(Ensure e) {
+           m_ensure = e;
+       }
+       public void invoke() {
+           m_ensure.step(5);
+       }
+   }
+
+   static class ServiceProvider2 implements ServiceInterface {
+       private final Ensure m_ensure;
+       public ServiceProvider2(Ensure e) {
+           m_ensure = e;
+       }
+       public void invoke() {
+           m_ensure.step(2);
+       }
+   }
+
+   static class ServiceConsumer implements Runnable {
+       private volatile ServiceInterface m_service;
+       private final Ensure m_ensure;
+
+       private void add(ServiceInterface service) { m_service = service; }
+       private void remove(ServiceInterface service) { if (m_service == service) { m_service
= null; }};
+       public ServiceConsumer(Ensure e) { m_ensure = e; }
+
+       public void start() {
+           Thread t = new Thread(this);
+           t.start();
+       }
+
+       public void run() {
+           m_ensure.step(1);
+           m_service.invoke();
+           m_ensure.step(3);
+           m_ensure.waitForStep(4, 1000);
+           m_service.invoke();
+       }
+
+       public void stop() {
+           m_ensure.step(6);
+       }
+   }
+}
\ No newline at end of file



Mime
View raw message