use of org.apache.felix.dm.Component in project felix by apache.
the class ModifiedBundleDependencyTest method testAdapterWithChangedInstanceBoundDependencyRef.
public void testAdapterWithChangedInstanceBoundDependencyRef() {
DependencyManager m = getDM();
Ensure e = new Ensure();
Component a = component(m, comp -> comp.impl(new AImpl()).provides(A.class).autoAdd(false));
BImpl impl = new BImpl(e);
String filter = "(Bundle-SymbolicName=org.apache.felix.metatype)";
int mask = Bundle.INSTALLED | Bundle.ACTIVE | Bundle.RESOLVED | Bundle.STARTING;
Component b = component(m).provides(B.class).impl(impl).withBundle(bd -> bd.filter(filter).mask(mask).add(impl::add).change(impl::change).remove(impl::remove)).build();
Bundle dmtest = getBundle("org.apache.felix.metatype");
try {
dmtest.stop();
} catch (BundleException e1) {
Assert.fail("could not find metatype bundle");
}
m.add(a);
m.add(b);
e.waitForStep(4, 5000);
// B will loose A and will enter into "waiting for required (instantiated)" state.
m.remove(a);
System.out.println("Starting metatype bundle ...");
try {
dmtest.start();
} catch (BundleException e1) {
Assert.fail("could not start metatype bundle");
}
e.waitForStep(7, 5000);
m.remove(b);
e.waitForStep(10, 5000);
}
use of org.apache.felix.dm.Component in project felix by apache.
the class MultipleExtraDependenciesTest method testWithOneAvailableExtraDependency.
/**
* Check that list of extra dependencies (defined from init method) are handled properly.
* The extra dependencies are added using a List object (Component.add(List)).
* A component c1 will define two extra dependencies over c4/c5. At the point c1.init()
* is adding the two extra dependencies from its init method, c4 is available, but not c5.
* So, c1 is not yet activated.
* Then c5 is added, and it triggers the c1 activation ...
*/
public void testWithOneAvailableExtraDependency() {
DependencyManager m = getDM();
// Helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
Component c1 = component(m).provides(Service1.class).impl(new MyComponent1(e)).withSvc(Service2.class, srv -> srv.autoConfig("m_service2")).build();
Component c2 = component(m).impl(new MyComponent2(e)).withSvc(Service1.class, srv -> srv.required(false).autoConfig(false).add("added")).build();
Component c3 = component(m).provides(Service2.class).impl(Service2Impl.class).build();
Component c4 = component(m).impl(Service3Impl1.class).provides(Service3.class, type -> "xx").build();
Component c5 = component(m).impl(Service3Impl2.class).provides(Service3.class, type -> "yy").build();
System.out.println("\n+++ Adding c2 / MyComponent2");
m.add(c2);
System.out.println("\n+++ Adding c3 / Service2");
m.add(c3);
System.out.println("\n+++ Adding c4 / Service3(xx)");
m.add(c4);
System.out.println("\n+++ Adding c1 / MyComponent1");
m.add(c1);
// c1 have declared two extra dependency on Service3 (xx/yy).
// So, because we have not yet added c5 (yy), c1 should not be started currently.
// But, now, we'll add c5 (Service3/yy) and c1 should then be started ...
System.out.println("\n+++ Adding c5 / Service3(yy)");
m.add(c5);
e.waitForStep(3, 3000);
m.clear();
}
use of org.apache.felix.dm.Component in project felix by apache.
the class MultipleExtraDependenciesTest method testWithTwoAvailableExtraDependency.
/**
* Check that list of extra dependencies (defined from init method) are handled properly.
* The extra dependencies are added using a List object (Component.add(List)).
* A component c1 will define two extra dependencies over *available* c4/c5 services.
*/
public void testWithTwoAvailableExtraDependency() {
DependencyManager m = getDM();
// Helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
Component c1 = component(m).provides(Service1.class).impl(new MyComponent1(e)).withSvc(Service2.class, srv -> srv.autoConfig("m_service2")).build();
Component c2 = component(m).impl(new MyComponent2(e)).withSvc(Service1.class, srv -> srv.required(false).autoConfig(false).add("added")).build();
Component c3 = component(m).provides(Service2.class).impl(Service2Impl.class).build();
Component c4 = component(m).impl(Service3Impl1.class).provides(Service3.class, type -> "xx").build();
Component c5 = component(m).impl(Service3Impl2.class).provides(Service3.class, type -> "yy").build();
System.out.println("\n+++ Adding c2 / MyComponent2");
m.add(c2);
System.out.println("\n+++ Adding c3 / Service2");
m.add(c3);
System.out.println("\n+++ Adding c4 / Service3(xx)");
m.add(c4);
System.out.println("\n+++ Adding c5 / Service3(yy)");
m.add(c5);
System.out.println("\n+++ Adding c1 / MyComponent1");
// c1 have declared two extra dependency on Service3 (xx/yy).
// both extra dependencies are available, so the c1 component should be started immediately.
m.add(c1);
e.waitForStep(3, 3000);
m.clear();
}
use of org.apache.felix.dm.Component in project felix by apache.
the class MultipleExtraDependencyTest method testMultipleExtraDependencies.
public void testMultipleExtraDependencies() {
DependencyManager m = getDM();
Ensure e = new Ensure();
Component sp2 = component(m).impl(ServiceProvider2.class).provides(ServiceProvider2.class).withSvc(Runnable.class, srv -> srv.filter("(foo=bar)").required(false).autoConfig("m_runnable")).withSvc(Sequencer.class, srv -> srv.add("bind")).composition("getComposition").build();
Component sp = component(m).impl(ServiceProvider.class).provides(ServiceInterface.class, foo -> "bar").start("start").stop("stop").withSvc(Sequencer.class, srv -> srv.autoConfig("m_sequencer")).withSvc(ServiceProvider2.class, srv -> srv.add("bind").remove("unbind")).build();
Component sc = component(m).impl(ServiceConsumer.class).start("start").stop("stop").withSvc(Sequencer.class, srv -> srv.autoConfig("m_sequencer")).withSvc(ServiceInterface.class, srv -> srv.filter("(foo=bar)").autoConfig("m_service")).build();
Component sequencer = component(m).impl(new SequencerImpl(e)).provides(Sequencer.class.getName()).build();
m.add(sp2);
m.add(sp);
m.add(sc);
m.add(sequencer);
// Check if ServiceProvider component have been initialized orderly
e.waitForStep(7, 5000);
// Stop the test.annotation bundle
m.remove(sequencer);
m.remove(sp);
m.remove(sp2);
m.remove(sc);
// And check if ServiceProvider2 has been deactivated orderly
e.waitForStep(11, 5000);
}
use of org.apache.felix.dm.Component in project felix by apache.
the class MultipleServiceDependencyTest method testMultipleServiceRegistrationAndConsumption.
public void testMultipleServiceRegistrationAndConsumption() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a service provider and consumer
Component provider = component(m).impl(new ServiceProvider(e)).provides(ServiceInterface.class.getName()).build();
Component providerWithHighRank = component(m).impl(new ServiceProvider2(e)).provides(ServiceInterface.class.getName(), Constants.SERVICE_RANKING, Integer.valueOf(5)).build();
Component consumer = component(m).impl(new ServiceConsumer(e)).withSvc(ServiceInterface.class, true).build();
m.add(provider);
m.add(providerWithHighRank);
m.add(consumer);
e.waitForStep(3, 5000);
m.remove(providerWithHighRank);
e.step(4);
e.waitForStep(5, 5000);
m.remove(provider);
m.remove(consumer);
e.waitForStep(6, 5000);
}
Aggregations