use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class DynamicProxyAspectTest method testImplementGenericAspectWithDynamicProxy.
public void testImplementGenericAspectWithDynamicProxy() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create two service providers, each providing a different service interface
Component sp1 = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
Component sp2 = m.createComponent().setImplementation(new ServiceProvider2(e)).setInterface(ServiceInterface2.class.getName(), null);
// create a dynamic proxy based aspect and hook it up to both services
Component a1 = m.createAspectService(ServiceInterface.class, null, 10, "m_service").setFactory(new Factory(e, ServiceInterface.class, "ServiceInterfaceProxy"), "create");
Component a2 = m.createAspectService(ServiceInterface2.class, null, 10, "m_service").setFactory(new Factory(e, ServiceInterface2.class, "ServiceInterfaceProxy2"), "create");
// create a client that invokes a method on boths services, validate that it goes
// through the proxy twice
Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true)).add(m.createServiceDependency().setService(ServiceInterface2.class).setRequired(true));
// register both producers, validate that both services are started
m.add(sp1);
e.waitForStep(1, 2000);
m.add(sp2);
e.waitForStep(2, 2000);
// add both aspects, and validate that both instances have been created
m.add(a1);
m.add(a2);
e.waitForStep(4, 4000);
// add the client, which will automatically invoke both services
m.add(sc);
// wait until both services have been invoked
e.waitForStep(6, 4000);
// make sure the proxy has been called twice
Assert.assertEquals("Proxy should have been invoked this many times.", 2, DynamicProxyHandler.getCounter());
m.remove(sc);
m.remove(a2);
m.remove(a1);
m.remove(sp2);
m.remove(sp1);
m.remove(a2);
m.remove(a1);
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class FELI5155_AdapterCallbackInstanceCalledTwice method testAdapterCallbackInstanceCalledTwice.
public void testAdapterCallbackInstanceCalledTwice() {
DependencyManager m = getDM();
m_e = new Ensure();
S1AdapterImpl adapterImpl = new S1AdapterImpl();
S2DependencyCallbackInstance cb = new S2DependencyCallbackInstance(adapterImpl);
Component s1 = m.createComponent().setImplementation(S1Impl.class).setInterface(S1.class.getName(), null);
Component s2 = m.createComponent().setImplementation(S2Impl.class).setInterface(S2.class.getName(), null);
Component s1Adapter = m.createAdapterService(S1.class, null, "setS1", null, null, null).setImplementation(adapterImpl).add(m.createServiceDependency().setService(S2.class).setRequired(true).setCallbacks(cb, "setS2", null, null, null));
m.add(s1);
m.add(s1Adapter);
m.add(s2);
m_e.waitForStep(2, 5000);
clearComponents();
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class FELIX2078_ServiceDependencyTest method testOptionalServiceRegistrationAndConsumption.
public void testOptionalServiceRegistrationAndConsumption() {
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 sp2 = 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(false).setCallbacks("add", "remove"));
m.add(sp);
m.add(sp2);
m.add(sc);
// wait until both services have been added to our consumer
e.waitForStep(2, 5000);
m.remove(sc);
m.remove(sp2);
m.remove(sp);
// ensure we executed all steps inside the component instance
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class FELIX2078_ServiceDependencyTest method testRequiredServiceRegistrationAndConsumption.
public void testRequiredServiceRegistrationAndConsumption() {
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 sp2 = 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).setCallbacks("add", "remove"));
m.add(sp);
m.add(sp2);
System.out.println("adding client");
m.add(sc);
System.out.println("waiting");
// wait until both services have been added to our consumer
e.waitForStep(2, 5000);
m.remove(sc);
m.remove(sp2);
m.remove(sp);
// ensure we executed all steps inside the component instance
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class FELIX2348_ResourceAdapterTest method testBasicResourceAdapter.
public void testBasicResourceAdapter() throws Exception {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
m.add(m.createResourceAdapterService("(&(path=/path/to/*.txt)(host=localhost))", false, null, "changed").setImplementation(new ResourceAdapter(e)));
URL resourceURL = new URL("file://localhost/path/to/file1.txt");
m.add(m.createComponent().setImplementation(new ResourceProvider(context, resourceURL)).add(m.createServiceDependency().setService(ResourceHandler.class).setCallbacks("add", "remove")));
e.waitForStep(3, 5000);
m.clear();
}
Aggregations