use of org.apache.felix.dm.Component in project felix by apache.
the class BundleDependencyTest method testBundleDependenciesRef.
public void testBundleDependenciesRef() {
DependencyManager m = getDM();
// create a service provider and consumer
MyConsumer c = new MyConsumer();
Component consumer = component(m, comp -> comp.impl(c).withBundle(bundle -> bundle.add(MyConsumer::add).remove(MyConsumer::remove)));
// check if at least one bundle was found
c.check();
// remove the consumer again
m.remove(consumer);
// check if all bundles were removed correctly
c.doubleCheck();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
String filter = "(Bundle-SymbolicName=" + BSN + ")";
Component consumerWithFilter = component(m, comp -> comp.impl(new FilteredConsumer(e)).withBundle(bundle -> bundle.filter(filter).add(FilteredConsumer::add).remove(FilteredConsumer::remove)));
e.step(2);
// remove the consumer again
m.remove(consumerWithFilter);
e.step(4);
}
use of org.apache.felix.dm.Component in project felix by apache.
the class CFDependencyTest method testComponentWithCFDependencyDefinedFromInit.
public void testComponentWithCFDependencyDefinedFromInit() throws Exception {
final DependencyManager dm = getDM();
// Create a consumer depending on a Provider and on the result of a CF.
// (the CF dependency is added from the Consumer.init() method).
CompletableFuture<String> cf = new CompletableFuture<>();
Component consumer = component(dm).impl(new Consumer(cf)).withSvc(Provider.class, true).build();
// Create provider
Component provider = component(dm).impl(new ProviderImpl()).provides(Provider.class).build();
dm.add(consumer);
dm.add(provider);
// Sets the result in the CF: this will normally trigger the activation of the Consumer component.
cf.complete("cfFesult");
m_ensure.waitForStep(3, 5000);
dm.clear();
}
use of org.apache.felix.dm.Component in project felix by apache.
the class DynamicProxyAspectTest method testImplementGenericAspectWithDynamicProxyAndFactory.
public void testImplementGenericAspectWithDynamicProxyAndFactory() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
DynamicProxyHandler.resetCounter();
// create two service providers, each providing a different service interface
Component sp1 = component(m).impl(new ServiceProvider(e)).provides(ServiceInterface.class).build();
Component sp2 = component(m).impl(new ServiceProvider2(e)).provides(ServiceInterface2.class).build();
// create a dynamic proxy based aspect and hook it up to both services
Component a1 = aspect(m, ServiceInterface.class).rank(10).autoConfig("m_service").factory(new Factory(e, ServiceInterface.class, "ServiceInterfaceProxy"), "create").build();
Component a2 = aspect(m, ServiceInterface2.class).rank(10).autoConfig("m_service").factory(new Factory(e, ServiceInterface2.class, "ServiceInterfaceProxy2"), "create").build();
// create a client that invokes a method on boths services, validate that it goes
// through the proxy twice
Component sc = component(m).impl(new ServiceConsumer(e)).withSvc(true, ServiceInterface.class, ServiceInterface2.class).build();
// 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);
}
use of org.apache.felix.dm.Component in project felix by apache.
the class DynamicProxyAspectTest method testImplementGenericAspectWithDynamicProxyAndFactoryRef.
public void testImplementGenericAspectWithDynamicProxyAndFactoryRef() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
DynamicProxyHandler.resetCounter();
// create two service providers, each providing a different service interface
Component sp1 = component(m).impl(new ServiceProvider(e)).provides(ServiceInterface.class).build();
Component sp2 = component(m).impl(new ServiceProvider2(e)).provides(ServiceInterface2.class).build();
// create a dynamic proxy based aspect and hook it up to both services
Component a1 = aspect(m, ServiceInterface.class).rank(10).autoConfig("m_service").factory(() -> new Factory(e, ServiceInterface.class, "ServiceInterfaceProxy"), Factory::create).build();
Component a2 = aspect(m, ServiceInterface2.class).rank(10).autoConfig("m_service").factory(() -> new Factory(e, ServiceInterface2.class, "ServiceInterfaceProxy2"), Factory::create).build();
// create a client that invokes a method on boths services, validate that it goes
// through the proxy twice
Component sc = component(m).impl(new ServiceConsumer(e)).withSvc(true, ServiceInterface.class, ServiceInterface2.class).build();
// 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);
}
use of org.apache.felix.dm.Component in project felix by apache.
the class FELIX5516Test method testServiceNotDereferencedInternallyUsingReflectionCallback.
public void testServiceNotDereferencedInternallyUsingReflectionCallback() throws Exception {
final DependencyManager dm = getDM();
Component service = component(dm).impl(new Factory()).provides(Service.class).build();
Component client = component(dm).impl(new Client()).withSvc(Service.class, svc -> svc.required().dereference(false).add("bind")).build();
dm.add(service);
dm.add(client);
m_ensure.waitForStep(9, 5000);
dm.clear();
}
Aggregations