Search in sources :

Example 86 with DependencyManager

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

the class ConfigurationDependencyTest method testComponentWithRequiredConfigurationWithComponentArgAndServicePropertyPropagation.

public void testComponentWithRequiredConfigurationWithComponentArgAndServicePropertyPropagation() {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a service provider and consumer
    Component s1 = m.createComponent().setImplementation(new ConfigurationConsumerWithComponentArg(e)).setInterface(Runnable.class.getName(), null).add(m.createConfigurationDependency().setPid(PID).setPropagate(true));
    Component s2 = m.createComponent().setImplementation(new ConfigurationCreator(e, PID)).add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true));
    Component s3 = m.createComponent().setImplementation(new ConfiguredServiceConsumer(e)).add(m.createServiceDependency().setService(Runnable.class, ("(testkey=testvalue)")).setRequired(true));
    m.add(s1);
    m.add(s2);
    m.add(s3);
    e.waitForStep(4, 50000000);
    m.remove(s1);
    m.remove(s2);
    m.remove(s3);
    // ensure we executed all steps inside the component instance
    e.step(6);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 87 with DependencyManager

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

the class DiagnosticsTest method testSingleComponent.

public void testSingleComponent() throws Exception {
    DependencyManager dm = getDM();
    Component component = dm.createComponent().setImplementation(Object.class);
    dm.add(component);
    DependencyGraph graph = DependencyGraph.getGraph(ComponentState.ALL, DependencyState.ALL);
    assertTrue(checkComponentCount(1, graph.getAllComponents().size()));
    assertTrue(graph.getAllDependencies().isEmpty());
    graph = DependencyGraph.getGraph(ComponentState.UNREGISTERED, DependencyState.ALL_UNAVAILABLE);
    assertTrue(graph.getAllComponents().isEmpty());
    assertTrue(graph.getAllDependencies().isEmpty());
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) DependencyGraph(org.apache.felix.dm.diagnostics.DependencyGraph) Component(org.apache.felix.dm.Component)

Example 88 with DependencyManager

use of org.apache.felix.dm.DependencyManager 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 89 with DependencyManager

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

the class DiagnosticsTest method testConfigurationDependencyMissing.

public void testConfigurationDependencyMissing() throws Exception {
    DependencyManager dm = getDM();
    ConfigurationDependency configurationDependency1 = dm.createConfigurationDependency().setPid("missing.configuration.pid");
    Component component1 = dm.createComponent().setImplementation(Object.class).add(configurationDependency1);
    m_dm.add(component1);
    DependencyGraph graph = DependencyGraph.getGraph(ComponentState.UNREGISTERED, DependencyState.REQUIRED_UNAVAILABLE);
    assertEquals(1, graph.getAllComponents().size());
    assertEquals(1, graph.getAllDependencies().size());
    List<MissingDependency> missingServiceDependencies = graph.getMissingDependencies("service");
    assertTrue(missingServiceDependencies.isEmpty());
    List<MissingDependency> missingConfigDependencies = graph.getMissingDependencies("configuration");
    assertEquals(1, missingConfigDependencies.size());
    MissingDependency missingConfigDependency = missingConfigDependencies.get(0);
    assertEquals("missing.configuration.pid", missingConfigDependency.getName());
}
Also used : ConfigurationDependency(org.apache.felix.dm.ConfigurationDependency) 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)

Example 90 with DependencyManager

use of org.apache.felix.dm.DependencyManager 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)

Aggregations

DependencyManager (org.apache.felix.dm.DependencyManager)255 Component (org.apache.felix.dm.Component)226 Ensure (org.apache.felix.dm.itest.util.Ensure)91 DependencyManagerActivator.component (org.apache.felix.dm.lambda.DependencyManagerActivator.component)70 Hashtable (java.util.Hashtable)56 Assert (org.junit.Assert)50 Dictionary (java.util.Dictionary)28 Map (java.util.Map)27 ServiceReference (org.osgi.framework.ServiceReference)24 DependencyManagerActivator.aspect (org.apache.felix.dm.lambda.DependencyManagerActivator.aspect)21 ServiceRegistration (org.osgi.framework.ServiceRegistration)18 DependencyManagerActivator.adapter (org.apache.felix.dm.lambda.DependencyManagerActivator.adapter)15 Bundle (org.osgi.framework.Bundle)15 HashMap (java.util.HashMap)13 ArrayList (java.util.ArrayList)12 ComponentDeclaration (org.apache.felix.dm.ComponentDeclaration)12 ServiceDependency (org.apache.felix.dm.ServiceDependency)11 Properties (java.util.Properties)10 List (java.util.List)9 DependencyGraph (org.apache.felix.dm.diagnostics.DependencyGraph)9