You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ma...@apache.org on 2014/02/13 17:44:05 UTC

svn commit: r1567974 - in /felix/sandbox/marrs/dependencymanager-prototype/dm: src/dm/Dependency.java src/dm/impl/DependencyImpl.java test/test/ComponentTest.java test/test/ConcurrencyTest.java test/test/ServiceRaceTest.java

Author: marrs
Date: Thu Feb 13 16:44:05 2014
New Revision: 1567974

URL: http://svn.apache.org/r1567974
Log:
Initial support for optional dependencies. Note that dependencies are now optional by default.

Modified:
    felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/Dependency.java
    felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/impl/DependencyImpl.java
    felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ComponentTest.java
    felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ConcurrencyTest.java
    felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ServiceRaceTest.java

Modified: felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/Dependency.java
URL: http://svn.apache.org/viewvc/felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/Dependency.java?rev=1567974&r1=1567973&r2=1567974&view=diff
==============================================================================
--- felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/Dependency.java (original)
+++ felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/Dependency.java Thu Feb 13 16:44:05 2014
@@ -26,6 +26,8 @@ public interface Dependency {
 	public void setCallbacks(String add, String remove);
 	public void setCallbacks(String add, String change, String remove);
 	
+	public void setRequired(boolean required);
+	
 	public void invokeAdd();
 	public void invokeRemove();
 }

Modified: felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/impl/DependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/impl/DependencyImpl.java?rev=1567974&r1=1567973&r2=1567974&view=diff
==============================================================================
--- felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/impl/DependencyImpl.java (original)
+++ felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/impl/DependencyImpl.java Thu Feb 13 16:44:05 2014
@@ -11,6 +11,7 @@ public class DependencyImpl implements D
 	private Component m_component;
 	private boolean m_available;
 	private boolean m_instanceBound;
+	private boolean m_required;
 	private String m_add;
 	private String m_change;
 	private String m_remove;
@@ -108,7 +109,7 @@ public class DependencyImpl implements D
 	
 	@Override
 	public boolean isRequired() {
-		return true;
+		return m_required;
 	}
 	public boolean isInstanceBound() {
 		return m_instanceBound;
@@ -165,4 +166,8 @@ public class DependencyImpl implements D
 		// specific for this type of dependency
 		m_component.invokeCallbackMethod(getInstances(), m_remove, new Class[][] {{}}, new Object[][] {{}});
 	}
+	@Override
+	public void setRequired(boolean required) {
+		m_required = required;
+	}
 }

Modified: felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ComponentTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ComponentTest.java?rev=1567974&r1=1567973&r2=1567974&view=diff
==============================================================================
--- felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ComponentTest.java (original)
+++ felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ComponentTest.java Thu Feb 13 16:44:05 2014
@@ -58,6 +58,7 @@ public class ComponentTest {
 	public void testAddDependencyFromInitCallback() {
 		final Ensure e = new Ensure();
 		final Dependency d = new DependencyImpl();
+		d.setRequired(true);
 		Component c = new ComponentImpl();
 		c.setImplementation(new Object() {
 			void init(Component c) {
@@ -89,6 +90,7 @@ public class ComponentTest {
 		Component c = new ComponentImpl();
 		c.setImplementation(MyComponent.class);
 		Dependency d = new DependencyImpl();
+		d.setRequired(true);
 		c.add(d);
 		c.start();
 		Assert.assertEquals("should not be available when started because of missing dependency", false, c.isAvailable());
@@ -101,6 +103,7 @@ public class ComponentTest {
 		Component c = new ComponentImpl();
 		c.setImplementation(MyComponent.class);
 		Dependency d = new DependencyImpl();
+		d.setRequired(true);
 		c.start();
 		Assert.assertEquals("should be available when started", true, c.isAvailable());
 		c.add(d);
@@ -115,6 +118,7 @@ public class ComponentTest {
 		Component c = new ComponentImpl();
 		c.setImplementation(MyComponent.class);
 		Dependency d = new DependencyImpl();
+		d.setRequired(true);
 		c.start();
 		c.add(d);
 		Assert.assertEquals("component should not be available: it is started but the dependency is not available", false, c.isAvailable());
@@ -133,6 +137,7 @@ public class ComponentTest {
 		Component c = new ComponentImpl();
 		c.setImplementation(MyComponent.class);
 		final Dependency d = new DependencyImpl();
+		d.setRequired(true);
 		ComponentStateListener l = new ComponentStateListener() {
 			@Override
 			public void changed(ComponentState state) {
@@ -163,7 +168,9 @@ public class ComponentTest {
 		Component c = new ComponentImpl();
 		c.setImplementation(MyComponent.class);
 		Dependency d1 = new DependencyImpl();
+		d1.setRequired(true);
 		Dependency d2 = new DependencyImpl();
+		d2.setRequired(true);
 		c.start();
 		c.add(d1);
 		c.add(d2);
@@ -198,6 +205,7 @@ public class ComponentTest {
 		});
 		Dependency d1 = new DependencyImpl();
 		d1.setCallbacks("add", "remove");
+		d1.setRequired(true);
 		// add the dependency to the component
 		c.add(d1);
 		// start the component
@@ -228,6 +236,7 @@ public class ComponentTest {
 		});
 		Dependency d1 = new DependencyImpl();
 		d1.setCallbacks("add", "remove");
+		d1.setRequired(true);
 		// start the component (it should become available)
 		c.start();
 		// add the dependency (it should become unavailable)
@@ -259,8 +268,10 @@ public class ComponentTest {
 		});
 		Dependency d1 = new DependencyImpl();
 		d1.setCallbacks("add", "remove");
+		d1.setRequired(true);
 		Dependency d2 = new DependencyImpl();
 		d2.setCallbacks("add", "remove");
+		d2.setRequired(true);
 		// start the component, which should become active because there are no
 		// dependencies yet
 		c.start();
@@ -305,8 +316,10 @@ public class ComponentTest {
 		c.start();
 		Dependency d1 = new DependencyImpl();
 		d1.setCallbacks("add", "remove");
+		d1.setRequired(true);
 		Dependency d2 = new DependencyImpl();
 		d2.setCallbacks("add", "remove");
+		d2.setRequired(true);
 		// add the first dependency, component should be unavailable
 		c.add(d1);
 		c.add(d2);
@@ -346,8 +359,10 @@ public class ComponentTest {
 		c.start();
 		Dependency d1 = new DependencyImpl();
 		d1.setCallbacks("add", "remove");
+		d1.setRequired(true);
 		Dependency d2 = new DependencyImpl();
 		d2.setCallbacks("add", "remove");
+		d2.setRequired(true);
 		c.add(d1);
 		c.add(d2);
 		// add three instances to first dependency, no callbacks should
@@ -398,6 +413,7 @@ public class ComponentTest {
 		});
 		Dependency d1 = new DependencyImpl();
 		d1.setCallbacks("add", "change", "remove");
+		d1.setRequired(true);
 		// add the dependency to the component
 		c.add(d1);
 		// start the component
@@ -417,4 +433,44 @@ public class ComponentTest {
 		Assert.assertEquals("component stopped, should be unavailable again", false, c.isAvailable());
 	}
 
+	@Test
+	public void createComponentWithOptionalDependency() {
+		final Ensure e = new Ensure();
+		Component c = new ComponentImpl();
+		c.setImplementation(new Object() {
+			public void add() {
+				e.step(1);
+			}
+			public void change() {
+				e.step(3);
+			}
+			public void remove() {
+				e.step(5);
+			}
+		});
+		Dependency d1 = new DependencyImpl();
+		d1.setCallbacks("add", "change", "remove");
+		d1.setRequired(false);
+		// add the dependency to the component
+		c.add(d1);
+		// start the component
+		c.start();
+		Assert.assertEquals("component started with an optional dependency, should be available", true, c.isAvailable());
+		// make the dependency available, we expect the add callback
+		// to be invoked here
+		d1.add(new EventImpl());
+		e.step(2);
+		Assert.assertEquals("component started with an optional dependency, should be available", true, c.isAvailable());
+		// change the dependency
+		d1.change(new EventImpl());
+		e.step(4);
+		Assert.assertEquals("component started with an optional dependency, should be available", true, c.isAvailable());
+		// remove the dependency, should trigger the remove callback
+		d1.remove(new EventImpl());
+		Assert.assertEquals("component started with an optional dependency, should be available", true, c.isAvailable());
+		e.step(6);
+		c.stop();
+		c.remove(d1);
+		Assert.assertEquals("component stopped, should be unavailable again", false, c.isAvailable());
+	}
 }

Modified: felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ConcurrencyTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ConcurrencyTest.java?rev=1567974&r1=1567973&r2=1567974&view=diff
==============================================================================
--- felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ConcurrencyTest.java (original)
+++ felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ConcurrencyTest.java Thu Feb 13 16:44:05 2014
@@ -27,7 +27,9 @@ public class ConcurrencyTest {
 		final Semaphore s = new Semaphore(0);
 		final Component c = new ComponentImpl();
 		final Dependency d = new DependencyImpl();
+		d.setRequired(true);
 		final Dependency d2 = new DependencyImpl();
+		d2.setRequired(true);
 		final Thread t = new Thread() {
 			public void run() {
 				c.add(d2);
@@ -83,6 +85,7 @@ public class ConcurrencyTest {
 				@Override
 				public void run() {
 					Dependency d = new DependencyImpl();
+					d.setRequired(true);
 					c.add(d);
 //					d.changed(new EventImpl(true));
 //					d.changed(new EventImpl(false));

Modified: felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ServiceRaceTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ServiceRaceTest.java?rev=1567974&r1=1567973&r2=1567974&view=diff
==============================================================================
--- felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ServiceRaceTest.java (original)
+++ felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ServiceRaceTest.java Thu Feb 13 16:44:05 2014
@@ -87,6 +87,7 @@ public class ServiceRaceTest extends Tes
         final Dependency[] dependencies = new Dependency[DEPENDENCIES];
         for (int i = 0; i < DEPENDENCIES; i++) {
             dependencies[i] = new DependencyImpl();
+            dependencies[i].setRequired(true);
             client.add(dependencies[i]);
         }