use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class AdapterWithModifiedInstanceBoundDependencyTest method testAdapterWithChangedInstanceBoundDependency.
public void testAdapterWithChangedInstanceBoundDependency() {
DependencyManager m = getDM();
Ensure e = new Ensure();
Dictionary props = new Hashtable();
props.put("foo", "bar");
Component a = m.createComponent().setImplementation(new AImpl(e)).setInterface(A.class.getName(), props);
Component b = m.createAdapterService(A.class, null, "add", "change", "remove").setInterface(B.class.getName(), null).setImplementation(new BImpl(e));
Component c = m.createComponent().setImplementation(new CImpl()).setInterface(C.class.getName(), null).add(m.createServiceDependency().setService(A.class, "(foo=bar)").setRequired(true));
m.add(a);
m.add(c);
m.add(b);
e.waitForStep(4, 5000);
System.out.println("changing A props ...");
props = new Hashtable();
props.put("foo", "bar2");
a.setServiceProperties(props);
e.waitForStep(7, 5000);
m.remove(c);
m.remove(a);
m.remove(b);
e.waitForStep(9, 5000);
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class AdapterWithPropagationTest method testAdapterWithPropagation.
public void testAdapterWithPropagation() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
Dictionary s1Properties = new Hashtable();
s1Properties.put("p1", "v1");
// should not override adapter
s1Properties.put("p2", "v2overriden");
Component s1 = m.createComponent().setImplementation(new S1Impl(e)).setInterface(S1.class.getName(), s1Properties);
Dictionary s1AdapterProperties = new Hashtable();
s1AdapterProperties.put("p2", "v2");
Component s1Adapter = m.createAdapterService(S1.class, null, "add", "change", null).setInterface(S2.class.getName(), s1AdapterProperties).setImplementation(new S1Adapter(e));
Component s3 = m.createComponent().setImplementation(new S3(e)).add(m.createServiceDependency().setService(S2.class).setRequired(true).setCallbacks("add", "change", null));
m.add(s1);
m.add(s1Adapter);
m.add(s3);
e.waitForStep(3, 5000);
s1Properties = new Hashtable();
s1Properties.put("p1", "v1modified");
s1Properties.put("p2", "v2overriden");
s1.setServiceProperties(s1Properties);
e.waitForStep(5, 5000);
m.clear();
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class AdapterWithoutPropagationTest method testAdapterNoPropagate.
public void testAdapterNoPropagate() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// The provider has a "foo=bar" property
Hashtable<String, String> props = new Hashtable<>();
props.put("foo", "bar");
ServiceProvider serviceProvider = new ServiceProvider(e);
Component provider = m.createComponent().setInterface(OriginalService.class.getName(), props).setImplementation(serviceProvider);
// The Adapter will see the "foo=bar" property from the adaptee
Component adapter = m.createAdapterService(OriginalService.class, null, null, null, "set", "change", null, null, false).setInterface(AdaptedService.class.getName(), null).setImplementation(new ServiceAdapter(e));
// The consumer depends on the AdaptedService, but won't see foo=bar property from the adaptee
Component consumer = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(AdaptedService.class).setRequired(true).setCallbacks("set", "change", null));
// add the provider and the adapter
m.add(provider);
m.add(adapter);
// Checks if the adapter has been started and has seen the adaptee properties
e.waitForStep(1, 5000);
// add a consumer that must not see the adaptee service properties
m.add(consumer);
e.waitForStep(2, 5000);
// change the service properties of the provider, and check that the adapter callback instance is caled.
serviceProvider.changeServiceProperties();
e.waitForStep(3, 5000);
// cleanup
m.clear();
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class AspectBaseTest method testSingleAspectThatAlreadyExisted.
@SuppressWarnings("serial")
public void testSingleAspectThatAlreadyExisted() {
DependencyManager m = new DependencyManager(context);
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a service provider and consumer
ServiceProvider p = new ServiceProvider(e, "a");
ServiceConsumer c = new ServiceConsumer(e);
Component sp = m.createComponent().setImplementation(p).setInterface(ServiceInterface.class.getName(), new Hashtable() {
{
put("name", "a");
}
});
Component sc = m.createComponent().setImplementation(c).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true).setCallbacks("add", "remove").setAutoConfig("m_service"));
Component sa = m.createAspectService(ServiceInterface.class, null, 20, null).setImplementation(ServiceAspect.class);
// we first add the aspect
m.add(sa);
// then the service provider
m.add(sp);
// finally the consumer
m.add(sc);
Assert.assertEquals("aa", c.invoke());
// now the consumer's added should be invoked once, as the aspect is already available and should
// directly hide the original service
e.waitForStep(1, 2000);
e.step(2);
m.remove(sa);
// after removing the aspect, the consumer should get the original service back, so
// remove and add will be invoked
e.waitForStep(4, 2000);
Assert.assertEquals("a", c.invoke());
m.remove(sp);
// after removing the original service, the consumer's remove should be called once
e.waitForStep(5, 2000);
m.remove(sc);
e.step(6);
}
use of org.apache.felix.dm.DependencyManager in project felix by apache.
the class AspectBaseTest method testMultipleAspects.
@SuppressWarnings("serial")
public void testMultipleAspects() {
DependencyManager m = new DependencyManager(context);
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create service providers and consumers
ServiceConsumer c = new ServiceConsumer(e);
Component sp = m.createComponent().setImplementation(new ServiceProvider(e, "a")).setInterface(ServiceInterface.class.getName(), new Hashtable() {
{
put("name", "a");
}
});
Component sp2 = m.createComponent().setImplementation(new ServiceProvider(e, "b")).setInterface(ServiceInterface.class.getName(), new Hashtable() {
{
put("name", "b");
}
});
Component sc = m.createComponent().setImplementation(c).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true).setCallbacks("add", "remove"));
Component sa = m.createAspectService(ServiceInterface.class, null, 20, null).setImplementation(ServiceAspect.class);
Component sa2 = m.createAspectService(ServiceInterface.class, null, 10, null).setImplementation(ServiceAspect.class);
m.add(sp);
m.add(sp2);
m.add(sa);
m.add(sa2);
m.add(sc);
// the consumer will monitor progress, it should get it's add invoked twice, once for every
// (highest) aspect
e.waitForStep(2, 2000);
e.step(3);
// now invoke all services the consumer collected
List<String> list = c.invokeAll();
// and make sure both of them are correctly invoked
Assert.assertTrue(list.size() == 2);
Assert.assertTrue(list.contains("aaa"));
Assert.assertTrue(list.contains("bbb"));
m.remove(sc);
// removing the consumer now should get its removed method invoked twice
e.waitForStep(5, 2000);
e.step(6);
m.remove(sa2);
m.remove(sa);
m.remove(sp2);
m.remove(sp);
e.step(7);
}
Aggregations