You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pd...@apache.org on 2014/03/07 22:38:49 UTC
svn commit: r1575421 - in
/felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it:
AdapterWithModifiedInstanceBoundDependencyTest.java
AdapterWithPropagationTest.java
Author: pderop
Date: Fri Mar 7 21:38:49 2014
New Revision: 1575421
URL: http://svn.apache.org/r1575421
Log:
added more integration tests for adapters
Added:
felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/AdapterWithModifiedInstanceBoundDependencyTest.java
felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/AdapterWithPropagationTest.java
Added: felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/AdapterWithModifiedInstanceBoundDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/AdapterWithModifiedInstanceBoundDependencyTest.java?rev=1575421&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/AdapterWithModifiedInstanceBoundDependencyTest.java (added)
+++ felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/AdapterWithModifiedInstanceBoundDependencyTest.java Fri Mar 7 21:38:49 2014
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package dm.it;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
+
+import dm.Component;
+import dm.DependencyManager;
+import junit.framework.Assert;
+
+/**
+ * Test for FELIX-4334 issue.
+ *
+ * Three components: A, B and C
+ *
+ * - A provided with property foo=bar
+ * - B adapts A, B has no filters on A, and B.init() method adds an instance bound required dependency to C.
+ * - C depends on A(foo=bar)
+ * - Now someone modifies the service properties of A: foo=bar2
+ * - As a result of that, C becomes unavailable and is unbound from B.
+ * - Since B has an instance bound required dependency to C: B should not be destroyed: it should be called in B.stop(), B.remove(C), B.change(A, "foo=bar2))
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class AdapterWithModifiedInstanceBoundDependencyTest extends TestBase {
+ public static interface A {
+ }
+
+ static class AImpl implements A {
+ final Ensure m_e;
+ AImpl(Ensure e) {
+ m_e = e;
+ }
+ }
+
+ public static interface C {
+ }
+
+ static class CImpl implements C {
+ volatile A m_a;
+ }
+
+ public static interface B {
+ }
+
+ static class BImpl implements B {
+ final Ensure m_e;
+ volatile A m_a;
+ volatile C m_c;
+
+ BImpl(Ensure e) {
+ m_e = e;
+ }
+
+ public void add(A a) {
+ m_e.step(1);
+ }
+
+ void init(Component c) {
+ m_e.step(2);
+ DependencyManager dm = c.getDependencyManager();
+ c.add(dm.createServiceDependency().setService(C.class).setRequired(true).setCallbacks("add", "remove"));
+ }
+
+ public void add(C c) {
+ m_e.step(3);
+ }
+
+ public void start() {
+ m_e.step(4);
+ }
+
+ public void stop() { // C becomes unsatisfied when A properties are changed to foo=bar2
+ m_e.step(5);
+ }
+
+ public void remove(C c) {
+ m_e.step(6);
+ }
+
+ public void change(Map properties, A a) {
+ Assert.assertEquals("bar2", properties.get("foo"));
+ m_e.step(7);
+ }
+
+ public void destroy() {
+ m_e.step(8);
+ }
+
+ public void remove(A a) {
+ m_e.step(9);
+ }
+ }
+
+ public void testAdapterWithChangedInstanceBoundDependency() {
+ DependencyManager m = new DependencyManager(context);
+ Ensure e = new Ensure();
+
+ Dictionary props = new Hashtable();
+ props.put("foo", "bar");
+ Component a = m.createComponent()
+ .setImplementation(new AImpl(e))
+ .setInterface(A.class.getName(), props);
+
+ Component b = m.createAdapterService(A.class, null, "add", "change", "remove")
+ .setInterface(B.class.getName(), null)
+ .setImplementation(new BImpl(e));
+
+ Component c = m.createComponent()
+ .setImplementation(new CImpl())
+ .setInterface(C.class.getName(), null)
+ .add(m.createServiceDependency().setService(A.class, "(foo=bar)").setRequired(true));
+
+ m.add(a);
+ m.add(c);
+ m.add(b);
+
+ e.waitForStep(4, 5000);
+
+ System.out.println("changing A props ...");
+ props = new Hashtable();
+ props.put("foo", "bar2");
+ a.setServiceProperties(props);
+
+ e.waitForStep(7, 5000);
+
+ m.remove(c);
+ m.remove(a);
+ m.remove(b);
+
+ e.waitForStep(9, 5000);
+ }
+}
Added: felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/AdapterWithPropagationTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/AdapterWithPropagationTest.java?rev=1575421&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/AdapterWithPropagationTest.java (added)
+++ felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/AdapterWithPropagationTest.java Fri Mar 7 21:38:49 2014
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package dm.it;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
+
+import dm.Component;
+import dm.DependencyManager;
+import junit.framework.Assert;
+
+/**
+ * Checks if a service adapter propagates its service properties, if
+ * the adapted service properties are changed:
+ *
+ * S1Impl provides S
+ * S1Adapter adapts S1Impl(S) to S2
+ * S3 depends on S2
+ *
+ * So, when S1Impl service properties are changed, S1Adapter shall propagate the changed properties to S3.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class AdapterWithPropagationTest extends TestBase {
+ public static interface S1 {}
+
+ static class S1Impl implements S1 {
+ private Ensure m_ensure;
+ public S1Impl(Ensure e) {
+ m_ensure = e;
+ }
+
+ public void start() {
+ m_ensure.step(1);
+ }
+ }
+
+ public static interface S2 {}
+
+ static class S1Adapter implements S2 {
+ private Ensure m_ensure;
+ public S1Adapter(Ensure e) {
+ m_ensure = e;
+ }
+
+ public void add(Map properties, S1 s1) {
+ Assert.assertTrue("bar".equals(properties.get("foo")));
+ m_ensure.step(2);
+ }
+
+ public void change(Map properties, S1 s1) {
+ Assert.assertTrue("bar2".equals(properties.get("foo")));
+ m_ensure.step(4);
+ }
+ }
+
+ static class S3 {
+ private final Ensure m_ensure;
+
+ public S3(Ensure e) {
+ m_ensure = e;
+ }
+
+ public void add(Map properties, S2 s2) {
+ Assert.assertTrue("bar".equals(properties.get("foo")));
+ m_ensure.step(3);
+ }
+
+ public void change(Map properties, S2 s2) {
+ Assert.assertTrue("bar2".equals(properties.get("foo")));
+ m_ensure.step(5);
+ }
+ }
+
+ public void testAdapterWithPropagation() {
+ DependencyManager m = new DependencyManager(context);
+ // helper class that ensures certain steps get executed in sequence
+ Ensure e = new Ensure();
+
+ Dictionary s1Properties = new Hashtable();
+ s1Properties.put("foo", "bar");
+ Component s1 = m.createComponent()
+ .setImplementation(new S1Impl(e))
+ .setInterface(S1.class.getName(), s1Properties);
+
+ Component s1Adapter = m.createAdapterService(S1.class, null, "add", "change", null)
+ .setInterface(S2.class.getName(), null)
+ .setImplementation(new S1Adapter(e));
+
+ Component s3 = m.createComponent()
+ .setImplementation(new S3(e))
+ .add(m.createServiceDependency()
+ .setService(S2.class)
+ .setRequired(true)
+ .setCallbacks("add", "change", null));
+
+
+ m.add(s1);
+ m.add(s1Adapter);
+ m.add(s3);
+
+ e.waitForStep(3, 5000);
+
+ s1Properties = new Hashtable();
+ s1Properties.put("foo", "bar2");
+ s1.setServiceProperties(s1Properties);
+
+ e.waitForStep(5, 5000);
+
+ m.clear();
+ }
+}