use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class DiagnosticsTest method testGraphsWithSeveralComponentDependencyCombinations.
public void testGraphsWithSeveralComponentDependencyCombinations() throws Exception {
DependencyManager dm = getDM();
Component component0 = dm.createComponent().setImplementation(C0.class).add(dm.createServiceDependency().setService(S1.class).setRequired(true)).add(dm.createServiceDependency().setService(S3.class).setRequired(true)).add(dm.createServiceDependency().setService(S4.class).setRequired(true));
Component component1 = dm.createComponent().setImplementation(C1.class).add(dm.createServiceDependency().setService(S5.class).setRequired(true)).add(dm.createServiceDependency().setService(S6.class).setRequired(true)).add(dm.createServiceDependency().setService(S7.class).setRequired(true));
Component s1Impl1 = dm.createComponent().setImplementation(S1Impl1.class).setInterface(S1.class.getName(), null).add(dm.createServiceDependency().setService(S2.class).setRequired(true));
Component s1Impl2 = dm.createComponent().setImplementation(S1Impl2.class).setInterface(S1.class.getName(), null);
Component s3Impl1 = dm.createComponent().setImplementation(S3Impl1.class).setInterface(S3.class.getName(), null).add(dm.createConfigurationDependency().setPid("missing.config.pid"));
Component s3s4Impl = dm.createComponent().setImplementation(S3S4Impl.class).setInterface(new String[] { S3.class.getName(), S4.class.getName() }, null);
Component s4Impl1 = dm.createComponent().setImplementation(S4Impl1.class).setInterface(S4.class.getName(), null);
Component s5Impl1 = dm.createComponent().setImplementation(S5Impl1.class).setInterface(S5.class.getName(), null);
Component s6s7Impl = dm.createComponent().setImplementation(S6S7Impl.class).setInterface(new String[] { S6.class.getName(), S7.class.getName() }, null).add(dm.createServiceDependency().setService(S8.class).setRequired(true));
Component s8Impl1 = dm.createComponent().setImplementation(S8Impl1.class).setInterface(S8.class.getName(), null).add(dm.createServiceDependency().setService(S6.class).setRequired(true));
dm.add(component0);
dm.add(component1);
dm.add(s1Impl1);
dm.add(s1Impl2);
dm.add(s3Impl1);
dm.add(s3s4Impl);
dm.add(s4Impl1);
dm.add(s5Impl1);
dm.add(s6s7Impl);
dm.add(s8Impl1);
// graph containing all components and dependencies
DependencyGraph graph = DependencyGraph.getGraph(ComponentState.ALL, DependencyState.ALL);
List<ComponentDeclaration> allComponents = graph.getAllComponents();
assertTrue(checkComponentCount(10, allComponents.size()));
List<MissingDependency> missingDependencies = graph.getMissingDependencies("service");
assertEquals(1, missingDependencies.size());
missingDependencies = graph.getMissingDependencies("configuration");
assertEquals(1, missingDependencies.size());
List<CircularDependency> circularDependencies = graph.getCircularDependencies();
assertEquals(1, circularDependencies.size());
CircularDependency circularDependency = circularDependencies.get(0);
assertEquals(3, circularDependency.getComponents().size());
assertTrue(circularDependency.getComponents().contains(s6s7Impl));
assertTrue(circularDependency.getComponents().contains(s8Impl1));
// graph containing unregistered components and unavailable required dependencies
graph = null;
graph = DependencyGraph.getGraph(ComponentState.UNREGISTERED, DependencyState.REQUIRED_UNAVAILABLE);
List<ComponentDeclaration> unregComponents = graph.getAllComponents();
assertEquals(5, unregComponents.size());
assertTrue(unregComponents.contains(s1Impl1));
assertTrue(unregComponents.contains(s3Impl1));
assertTrue(unregComponents.contains(component1));
assertTrue(unregComponents.contains(s6s7Impl));
assertTrue(unregComponents.contains(s8Impl1));
assertFalse(unregComponents.contains(component0));
circularDependencies = graph.getCircularDependencies();
assertEquals(1, circularDependencies.size());
circularDependency = circularDependencies.get(0);
assertEquals(3, circularDependency.getComponents().size());
assertTrue(circularDependency.getComponents().contains(s6s7Impl));
assertTrue(circularDependency.getComponents().contains(s8Impl1));
missingDependencies = graph.getMissingDependencies("service");
assertEquals(1, missingDependencies.size());
missingDependencies = graph.getMissingDependencies("configuration");
assertEquals(1, missingDependencies.size());
// call getCircularDependencies again on the same graph
circularDependencies = graph.getCircularDependencies();
assertEquals(1, circularDependencies.size());
circularDependency = circularDependencies.get(0);
assertEquals(3, circularDependency.getComponents().size());
assertTrue(circularDependency.getComponents().contains(s6s7Impl));
assertTrue(circularDependency.getComponents().contains(s8Impl1));
List<MissingDependency> allMissingDependencies = graph.getMissingDependencies(null);
assertEquals(2, allMissingDependencies.size());
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class DiagnosticsTest method testProvidersWithProperties.
public void testProvidersWithProperties() throws Exception {
DependencyManager dm = getDM();
ServiceDependency serviceDependency1 = dm.createServiceDependency().setService(S1.class, "(key=value)").setRequired(true);
Component component1 = dm.createComponent().setImplementation(C0.class).add(serviceDependency1);
Properties component2Properties = new Properties();
component2Properties.put("key", "value");
Properties component4Properties = new Properties();
component4Properties.put("key", "otherValue");
Component component2 = dm.createComponent().setImplementation(S1Impl1.class).setInterface(S1.class.getName(), component2Properties);
Component component3 = dm.createComponent().setImplementation(S1Impl2.class).setInterface(S1.class.getName(), null);
Component component4 = dm.createComponent().setImplementation(S1Impl3.class).setInterface(S1.class.getName(), component4Properties);
m_dm.add(component1);
m_dm.add(component2);
m_dm.add(component3);
m_dm.add(component4);
DependencyGraph graph = DependencyGraph.getGraph(ComponentState.ALL, DependencyState.ALL);
List<ComponentDeclaration> providers = graph.getProviders(serviceDependency1);
assertEquals(1, providers.size());
assertTrue(providers.contains(component2));
assertFalse(providers.contains(component3));
assertFalse(providers.contains(component4));
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class FELIX2344_ExtraDependencyWithAutoConfigTest method testExtraDependencyWithAutoConfig.
/**
* Test if an auto config extra dependency is injected in the expected order.
*/
public void testExtraDependencyWithAutoConfig() {
DependencyManager m = getDM();
// Helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// Create a service provider
Component sp = m.createComponent().setInterface(ProviderInterface.class.getName(), null).setImplementation(ProviderImpl.class);
// Create a service consumer with a required/autoconfig dependency over the service provider.
Client c1;
Component sc1 = m.createComponent().setImplementation((c1 = new Client(e, true, 1)));
// Create a second service consumer with an optional/autoconfig dependency over the service provider.
Client c2;
Component sc2 = m.createComponent().setImplementation(c2 = new Client(e, false, 3));
// Add service provider and consumer sc1 (required dependency over provider)
m.add(sc1);
m.add(sp);
e.waitForStep(2, 5000);
// Remove provider and consumer
m.remove(sc1);
m.remove(sp);
// Add consumer sc2 (optional dependency over provider)
m.add(sc2);
e.waitForStep(4, 5000);
m.clear();
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class FELIX2344_ExtraDependencyWithCallbackTest method testExtraDependencyWithCallback.
/**
* Checks if an extra optional/required dependency is properly injected into a consumer, using callbacks.
*/
public void testExtraDependencyWithCallback() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a service consumer and provider
Component sp = m.createComponent().setInterface(ProviderInterface.class.getName(), null).setImplementation(ProviderImpl.class);
Component sc = m.createComponent().setImplementation(new Client(e, false, 1));
Component sc2 = m.createComponent().setImplementation(new Client(e, true, 5));
Component sc3 = m.createComponent().setImplementation(new Client(e, true, 9));
// add the provider first, then add the consumer which initially will have no dependencies
// but via the init() method an optional dependency with a callback method will be added
m.add(sp);
m.add(sc);
// remove the consumer again
m.remove(sc);
e.waitForStep(4, 5000);
// next up, add a second consumer, identical to the first, but with a required dependency
// with a callback method which will be added in the init() method
m.add(sc2);
// remove the consumer again
m.remove(sc2);
e.waitForStep(8, 5000);
// now remove the provider, add a third consumer, identical to the second, and after the
// consumer has started, add the provider again
m.remove(sp);
m.add(sc3);
m.add(sp);
e.waitForStep(12, 5000);
m.clear();
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class FELIX2369_ExtraDependencyTest method testExtraDependencies.
public void testExtraDependencies() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a service consumer and provider
Component sp1 = m.createComponent().setInterface(MyService1.class.getName(), null).setImplementation(new MyService1Impl());
Component sc = m.createComponent().setImplementation(new MyClient(e, 1));
// provides the MyService1 service (but not the MyService2, which is required by MyClient).
m.add(sp1);
// add MyClient (it should not be invoked in its start() method because MyService2 is not there
m.add(sc);
// remove MyClient (it should not be invoked in its stop() method because it should not be active, since MyService2 is not there.
m.remove(sc);
e.waitForStep(2, 5000);
m.clear();
}
Aggregations