use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class TestBase method setUp.
public void setUp() throws Exception {
warn("Setting up test " + getClass().getName());
context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
Hashtable<String, Object> props = new Hashtable<>();
props.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE));
logService = context.registerService(LogService.class.getName(), this, props);
context.addFrameworkListener(this);
m_dm = new DependencyManager(context);
if (m_parallel) {
warn("Using threadpool ...");
m_threadPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors());
m_componentExecutorFactoryReg = context.registerService(ComponentExecutorFactory.class.getName(), new ComponentExecutorFactory() {
@Override
public Executor getExecutorFor(Component component) {
return m_threadPool;
}
}, null);
}
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class AbstractServiceDependencyTest method testAbstractClassDependency.
public void testAbstractClassDependency() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a service provider and consumer
Component sp = m.createComponent().setInterface(ServiceAbstract.class.getName(), null).setImplementation(new ServiceProvider(e));
Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceAbstract.class).setRequired(true).setCallbacks("bind", "unbind"));
m.add(sp);
m.add(sc);
m.remove(sp);
// ensure we executed all steps inside the component instance
e.step(8);
m.clear();
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class AdapterAndConsumerTest method testServiceWithAdapterAndConsumer.
public void testServiceWithAdapterAndConsumer() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
Component provider = m.createComponent().setInterface(OriginalService.class.getName(), null).setImplementation(new ServiceProvider(e));
Component consumer = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(AdaptedService.class).setRequired(true));
Component adapter = m.createAdapterService(OriginalService.class, null).setInterface(AdaptedService.class.getName(), null).setImplementation(ServiceAdapter.class);
// add the provider and the adapter
m.add(provider);
m.add(adapter);
// add a consumer that will invoke the adapter
// which will in turn invoke the original provider
m.add(consumer);
// now validate that both have been invoked in the right order
e.waitForStep(2, 5000);
// remove the provider again
m.remove(provider);
// ensure that the consumer is stopped
e.waitForStep(3, 5000);
// remove adapter and consumer
m.remove(adapter);
m.remove(consumer);
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class AdapterNoAutoConfigIfInstanceCallbackIsUsed method testNoAutoConfigIfINstanceCallbackIsUsed.
public void testNoAutoConfigIfINstanceCallbackIsUsed() {
DependencyManager m = getDM();
// Declare S1 service
Component s1 = m.createComponent().setImplementation(S1Impl.class).setInterface(S1.class.getName(), null);
m.add(s1);
// Declare S1 adapter
S1AdapterCallback s1AdapterCB = new S1AdapterCallback();
Component s1Adapter = m.createAdapterService(S1.class, null, null, s1AdapterCB, "set", null, null, null, false).setImplementation(S1Adapter.class);
m.add(s1Adapter);
// At this point, the s1AdapterCB.set(S1 s1) method should be called, and s1Adapter.start() method should then be called.
// but s1 should not be injected on s1Adapter class fields.
m_e.waitForStep(3, 5000);
m.clear();
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class AdapterWithConfigurationAndMetaType method testAdapterWithConfigurationDependencyAndMetaType.
public void testAdapterWithConfigurationDependencyAndMetaType() {
DependencyManager m = getDM();
Ensure e = new Ensure();
m.add(m.createAdapterService(A.class, null).setInterface(B.class.getName(), null).setImplementation(new BImpl(e)).add(m.createConfigurationDependency().setPid(PID).setHeading(PID_HEADING).setDescription(PID_DESC).add(m.createPropertyMetaData().setCardinality(Integer.MAX_VALUE).setType(String.class).setHeading(WORDS_HEADING).setDescription(WORDS_DESC).setDefaults(new String[] { "hello", "world" }).setId(WORDS_PROPERTY))));
m.add(m.createComponent().setInterface(A.class.getName(), null).setImplementation(new AImpl()));
Component configurator = m.createComponent().setImplementation(new Configurator(e)).add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true)).add(m.createServiceDependency().setService(MetaTypeService.class).setRequired(true));
m.add(configurator);
// Ensures that all components are started
e.waitForStep(4, 5000);
// now stop configurator, and ensure that all components have been stopped
m.remove(configurator);
e.waitForStep(7, 5000);
m.clear();
}
Aggregations