use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class ComponentTest method testSimple.
public void testSimple() throws Exception {
final DependencyManager dm = getDM();
Component consumer = dm.createComponent();
consumer.setImplementation(new Consumer()).add(dm.createServiceDependency().setService(Provider.class, "(name=provider2)").setRequired(true).setCallbacks("add", "remove")).add(dm.createServiceDependency().setService(Provider.class, "(name=provider1)").setRequired(true).setAutoConfig("m_autoConfiguredProvider"));
Dictionary props = new Hashtable();
props.put("name", "provider1");
Component provider1 = dm.createComponent().setImplementation(new Provider() {
public String toString() {
return "provider1";
}
}).setInterface(Provider.class.getName(), props);
props = new Hashtable();
props.put("name", "provider2");
Component provider2 = dm.createComponent().setImplementation(new Provider() {
public String toString() {
return "provider2";
}
}).setInterface(Provider.class.getName(), props);
dm.add(provider1);
dm.add(provider2);
dm.add(consumer);
m_ensure.waitForStep(2, 5000);
dm.remove(provider1);
dm.remove(provider2);
m_ensure.waitForStep(5, 5000);
dm.clear();
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class ConfigurationDependencyTest method testFELIX2987.
public void testFELIX2987() {
// mimics testComponentWithRequiredConfigurationAndServicePropertyPropagation
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 ConfigurationConsumer2(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, 5000);
m.remove(s1);
m.remove(s2);
m.remove(s3);
// ensure we executed all steps inside the component instance
e.step(6);
}
use of org.apache.felix.dm.DependencyManager 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);
}
use of org.apache.felix.dm.DependencyManager 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);
}
use of org.apache.felix.dm.DependencyManager 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);
}
Aggregations