Search in sources :

Example 91 with Component

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

the class ConfigurationDependencyTest method testFELIX4907.

public void testFELIX4907() {
    // This test validates updated(null) is not invoked when a component that have a configuration dependency is stopped.
    DependencyManager m = getDM();
    Ensure e = new Ensure();
    Component s1 = m.createComponent().setImplementation(new ConfigurationConsumer3(e)).add(m.createConfigurationDependency().setPid(PID));
    Component s2 = m.createComponent().setImplementation(new ConfigurationCreator(e, PID)).add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true));
    m.add(s1);
    m.add(s2);
    e.waitForStep(3, 5000);
    m.remove(s1);
    e.waitForStep(4, 5000);
    m.remove(s2);
    // 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 92 with Component

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

the class ConfigurationDependencyTest method testComponentWithRequiredConfigurationWithTypeSafeConfiguration.

/**
 * Tests that we can provision a type-safe configuration to a component.
 */
public void testComponentWithRequiredConfigurationWithTypeSafeConfiguration() {
    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 ConfigurationConsumerWithTypeSafeConfiguration(e)).add(m.createConfigurationDependency().setCallback(null, "updated", MyConfig.class).setPid(PID).setPropagate(true));
    Component s2 = m.createComponent().setImplementation(new ConfigurationCreator(e, PID)).add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true));
    m.add(s1);
    m.add(s2);
    // s2 called in init
    e.waitForStep(1, 5000);
    // s1 called in updated(), then in init()
    e.waitForStep(3, 5000);
    // remove conf
    m.remove(s2);
    // s2 destroyed, s1 called in updated(null), s1 called in destroy()
    e.waitForStep(6, 5000);
    m.remove(s1);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 93 with Component

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

the class ConfigurationDependencyTest method testFELIX4907_updated_with_null_dictionary_called_when_configuration_is_lost.

public void testFELIX4907_updated_with_null_dictionary_called_when_configuration_is_lost() {
    DependencyManager m = getDM();
    Ensure e = new Ensure();
    Component s1 = m.createComponent().setImplementation(new ConfigurationConsumer4(e)).add(m.createConfigurationDependency().setPid(PID));
    Component s2 = m.createComponent().setImplementation(new ConfigurationCreator(e, PID)).add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true));
    m.add(s1);
    m.add(s2);
    // component configured and started.
    e.waitForStep(3, 5000);
    // configuration will be removed
    m.remove(s2);
    // configuration creator destroyed
    e.waitForStep(4, 5000);
    // consumer called in updated(null)
    e.waitForStep(5, 5000);
    // consumer des
    e.waitForStep(6, 5000);
    m.remove(s1);
    // ensure we executed all steps inside the component instance
    e.step(7);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 94 with Component

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

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

Aggregations

Component (org.apache.felix.dm.Component)271 DependencyManager (org.apache.felix.dm.DependencyManager)227 Ensure (org.apache.felix.dm.itest.util.Ensure)91 DependencyManagerActivator.component (org.apache.felix.dm.lambda.DependencyManagerActivator.component)65 Hashtable (java.util.Hashtable)59 Assert (org.junit.Assert)46 Dictionary (java.util.Dictionary)32 ServiceReference (org.osgi.framework.ServiceReference)25 Map (java.util.Map)23 DependencyManagerActivator.aspect (org.apache.felix.dm.lambda.DependencyManagerActivator.aspect)21 Bundle (org.osgi.framework.Bundle)17 ServiceRegistration (org.osgi.framework.ServiceRegistration)17 DependencyManagerActivator.adapter (org.apache.felix.dm.lambda.DependencyManagerActivator.adapter)15 ArrayList (java.util.ArrayList)14 ComponentDeclaration (org.apache.felix.dm.ComponentDeclaration)13 HashMap (java.util.HashMap)12 ServiceDependency (org.apache.felix.dm.ServiceDependency)12 Test (org.junit.Test)11 Properties (java.util.Properties)10 DependencyGraph (org.apache.felix.dm.diagnostics.DependencyGraph)10