use of org.apache.felix.dm.itest.util.Ensure 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);
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class AspectChainTest method testBuildAspectChain.
public void testBuildAspectChain() {
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().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
Component sa2 = m.createAspectService(ServiceInterface.class, null, 20, null).setImplementation(new ServiceAspect(e, 3));
Component sa3 = m.createAspectService(ServiceInterface.class, null, 30, null).setImplementation(new ServiceAspect(e, 2));
Component sa1 = m.createAspectService(ServiceInterface.class, null, 10, null).setImplementation(new ServiceAspect(e, 4));
m.add(sc);
m.add(sp);
m.add(sa2);
m.add(sa3);
m.add(sa1);
e.step();
e.waitForStep(5, 5000);
m.remove(sa3);
m.remove(sa2);
m.remove(sa1);
m.remove(sp);
m.remove(sc);
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class AspectServiceDependencyTest method testServiceRegistrationAndConsumption.
public void testServiceRegistrationAndConsumption() {
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().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setCallbacks("add", "remove").setRequired(true));
Component asp = m.createAspectService(ServiceInterface.class, null, 100).setImplementation(ServiceProviderAspect.class);
m.add(sp);
m.add(sc);
m.add(asp);
m.remove(asp);
m.remove(sc);
m.remove(sp);
// ensure we executed all steps inside the component instance
e.step(8);
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class AspectServiceDependencyWithSwapCallbackTest method testServiceRegistrationAndConsumption.
public void testServiceRegistrationAndConsumption() {
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().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setCallbacks("add", null, "remove", "swap").setRequired(true));
Component asp = m.createAspectService(ServiceInterface.class, null, 100).setImplementation(ServiceProviderAspect.class);
m.add(sp);
m.add(sc);
m.add(asp);
m.remove(asp);
m.remove(sc);
m.remove(sp);
// ensure we executed all steps inside the component instance
e.step(7);
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class AspectWithCallbacksServiceDependencyTest method testServiceRegistrationAndConsumptionWithAspectCallbackInstance.
public void testServiceRegistrationAndConsumptionWithAspectCallbackInstance() {
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().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setCallbacks("add", "remove").setRequired(true));
ServiceProviderAspect providerAspect = new ServiceProviderAspect();
ServiceProviderAspectCallbackInstance aspectCb = new ServiceProviderAspectCallbackInstance(providerAspect);
Component asp = m.createAspectService(ServiceInterface.class, null, 100, aspectCb, "add", null, "remove", "swap").setImplementation(providerAspect);
m.add(sp);
m.add(sc);
m.add(asp);
m.remove(asp);
m.remove(sc);
m.remove(sp);
// ensure we executed all steps inside the component instance
e.step(8);
}
Aggregations