felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1722844 - /felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELI5155_AdapterCallbackInstanceCalledTwice.java
Date Mon, 04 Jan 2016 11:10:49 GMT
Author: pderop
Date: Mon Jan  4 11:10:49 2016
New Revision: 1722844

URL: http://svn.apache.org/viewvc?rev=1722844&view=rev
Log:
FELI-5155: added test case for 5155 issue.

Added:
    felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELI5155_AdapterCallbackInstanceCalledTwice.java

Added: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELI5155_AdapterCallbackInstanceCalledTwice.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELI5155_AdapterCallbackInstanceCalledTwice.java?rev=1722844&view=auto
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELI5155_AdapterCallbackInstanceCalledTwice.java
(added)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELI5155_AdapterCallbackInstanceCalledTwice.java
Mon Jan  4 11:10:49 2016
@@ -0,0 +1,77 @@
+package org.apache.felix.dm.itest.api;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.itest.util.Ensure;
+import org.apache.felix.dm.itest.util.TestBase;
+import org.junit.Assert;
+
+public class FELI5155_AdapterCallbackInstanceCalledTwice extends TestBase {
+    static Ensure m_e;
+    
+    public void testAdapterCallbackInstanceCalledTwice() {
+        DependencyManager m = getDM();
+        m_e = new Ensure();
+        
+        S1AdapterImpl adapterImpl = new S1AdapterImpl();
+        S2DependencyCallbackInstance cb = new S2DependencyCallbackInstance(adapterImpl);
           
+        
+        Component s1 = m.createComponent().setImplementation(S1Impl.class).setInterface(S1.class.getName(),
null);
+        Component s2 = m.createComponent().setImplementation(S2Impl.class).setInterface(S2.class.getName(),
null);
+
+        Component s1Adapter = m.createAdapterService(S1.class, null, "setS1", null, null,
null)
+            .setImplementation(adapterImpl)
+            .add(m.createServiceDependency().setService(S2.class).setRequired(true).setCallbacks(cb,
"setS2", null, null, null));
+        
+        m.add(s1);
+        m.add(s1Adapter);
+        m.add(s2);
+        
+        m_e.waitForStep(2, 5000);
+        clearComponents();
+    }
+    
+    
+    public interface S1 {
+    }
+    
+    public static class S1Impl implements S1 {
+    }
+    
+    public interface S2 {
+    }
+    
+    public static class S2Impl implements S2 {
+    }
+
+    public static class S1AdapterImpl {
+        volatile S1 m_s1;
+        volatile S2 m_s2;
+        
+        void setS1(S1 s1) {
+            m_s1 = s1;
+        }
+        
+        void setS2(S2 s2) {
+            Assert.assertNull("service already injected: ", m_s2);
+            m_s2 = s2;
+            m_e.step(1);
+        }
+        
+        void start() {
+            Assert.assertNotNull("service s1 not injected", m_s1);
+            m_e.step(2);
+        }
+    }
+    
+    public static class S2DependencyCallbackInstance {
+        final S1AdapterImpl m_adapter;
+        
+        S2DependencyCallbackInstance(S1AdapterImpl adapter) {
+            m_adapter = adapter;
+        }
+        
+        void setS2(S2 s2) {
+            m_adapter.setS2(s2);
+        }
+    }
+}



Mime
View raw message