Search in sources :

Example 6 with ComponentDeclaration

use of org.apache.felix.dm.ComponentDeclaration in project felix by apache.

the class DiagnosticsTest method testCircularDependencies.

public void testCircularDependencies() throws Exception {
    DependencyManager dm = getDM();
    Component component0 = dm.createComponent().setImplementation(C0.class).add(dm.createServiceDependency().setService(S1.class).setRequired(true));
    Component component1 = dm.createComponent().setImplementation(S1Impl1.class).setInterface(S1.class.getName(), null).add(dm.createServiceDependency().setService(S2.class).setRequired(true));
    Component component2 = dm.createComponent().setImplementation(S2Impl1.class).setInterface(S2.class.getName(), null).add(dm.createServiceDependency().setService(S1.class).setRequired(true));
    m_dm.add(component0);
    m_dm.add(component1);
    m_dm.add(component2);
    DependencyGraph graph = DependencyGraph.getGraph(ComponentState.UNREGISTERED, DependencyState.REQUIRED_UNAVAILABLE);
    List<CircularDependency> circularDependencies = graph.getCircularDependencies();
    assertEquals(1, circularDependencies.size());
    List<ComponentDeclaration> circularDependencyComponents = circularDependencies.get(0).getComponents();
    assertTrue(circularDependencyComponents.contains(component1));
    assertTrue(circularDependencyComponents.contains(component2));
    assertFalse(circularDependencyComponents.contains(component0));
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration) DependencyManager(org.apache.felix.dm.DependencyManager) DependencyGraph(org.apache.felix.dm.diagnostics.DependencyGraph) Component(org.apache.felix.dm.Component) CircularDependency(org.apache.felix.dm.diagnostics.CircularDependency)

Example 7 with ComponentDeclaration

use of org.apache.felix.dm.ComponentDeclaration in project felix by apache.

the class DiagnosticsTest method testProvidersWithoutProperties.

public void testProvidersWithoutProperties() throws Exception {
    DependencyManager dm = getDM();
    ServiceDependency serviceDependency1 = dm.createServiceDependency().setService(S1.class).setRequired(true);
    Component component1 = dm.createComponent().setImplementation(C0.class).add(serviceDependency1);
    Component component2 = dm.createComponent().setImplementation(S1Impl1.class).setInterface(S1.class.getName(), null);
    Component component3 = dm.createComponent().setImplementation(S1Impl2.class).setInterface(S1.class.getName(), null);
    dm.add(component1);
    dm.add(component2);
    dm.add(component3);
    DependencyGraph graph = DependencyGraph.getGraph(ComponentState.ALL, DependencyState.ALL);
    List<ComponentDeclaration> providers = graph.getProviders(serviceDependency1);
    assertEquals(2, providers.size());
    assertTrue(providers.contains(component2));
    assertTrue(providers.contains(component3));
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration) DependencyManager(org.apache.felix.dm.DependencyManager) DependencyGraph(org.apache.felix.dm.diagnostics.DependencyGraph) ServiceDependency(org.apache.felix.dm.ServiceDependency) Component(org.apache.felix.dm.Component)

Example 8 with ComponentDeclaration

use of org.apache.felix.dm.ComponentDeclaration 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());
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration) MissingDependency(org.apache.felix.dm.diagnostics.MissingDependency) DependencyManager(org.apache.felix.dm.DependencyManager) DependencyGraph(org.apache.felix.dm.diagnostics.DependencyGraph) Component(org.apache.felix.dm.Component) CircularDependency(org.apache.felix.dm.diagnostics.CircularDependency)

Example 9 with ComponentDeclaration

use of org.apache.felix.dm.ComponentDeclaration 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));
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration) DependencyManager(org.apache.felix.dm.DependencyManager) DependencyGraph(org.apache.felix.dm.diagnostics.DependencyGraph) ServiceDependency(org.apache.felix.dm.ServiceDependency) Component(org.apache.felix.dm.Component) Properties(java.util.Properties)

Example 10 with ComponentDeclaration

use of org.apache.felix.dm.ComponentDeclaration in project felix by apache.

the class FELIX4158_DependencyDeclarationTest method testResourceDependencyDeclarationWithFilter.

public void testResourceDependencyDeclarationWithFilter() {
    DependencyManager m = getDM();
    Component c = m.createComponent().setImplementation(new Object()).add(m.createResourceDependency().setFilter("(&(path=/path/to/*.txt)(host=localhost))"));
    ComponentDeclaration cd = c.getComponentDeclaration();
    ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies();
    Assert.assertNotNull(cdds);
    Assert.assertNotNull(cdds.length == 1);
    Assert.assertEquals(cdds[0].getName(), ("(&(path=/path/to/*.txt)(host=localhost))"));
    Assert.assertNull(cdds[0].getSimpleName());
    Assert.assertNotNull(cdds[0].getFilter());
    Assert.assertEquals(cdds[0].getFilter(), "(&(path=/path/to/*.txt)(host=localhost))");
    m.clear();
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration) DependencyManager(org.apache.felix.dm.DependencyManager) ComponentDependencyDeclaration(org.apache.felix.dm.ComponentDependencyDeclaration) Component(org.apache.felix.dm.Component)

Aggregations

ComponentDeclaration (org.apache.felix.dm.ComponentDeclaration)18 Component (org.apache.felix.dm.Component)13 DependencyManager (org.apache.felix.dm.DependencyManager)12 ComponentDependencyDeclaration (org.apache.felix.dm.ComponentDependencyDeclaration)8 DependencyGraph (org.apache.felix.dm.diagnostics.DependencyGraph)6 CircularDependency (org.apache.felix.dm.diagnostics.CircularDependency)4 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 ServiceDependency (org.apache.felix.dm.ServiceDependency)2 MissingDependency (org.apache.felix.dm.diagnostics.MissingDependency)2 URL (java.net.URL)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 Descriptor (org.apache.felix.service.command.Descriptor)1 Bundle (org.osgi.framework.Bundle)1 Filter (org.osgi.framework.Filter)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 LogService (org.osgi.service.log.LogService)1