use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class ModifiedBundleDependencyTest method testAdapterWithChangedInstanceBoundDependency.
public void testAdapterWithChangedInstanceBoundDependency() {
DependencyManager m = getDM();
Ensure e = new Ensure();
Component a = m.createComponent().setImplementation(new AImpl()).setInterface(A.class.getName(), null);
Component b = m.createComponent().setInterface(B.class.getName(), null).setImplementation(new BImpl(e)).add(m.createBundleDependency().setFilter("(Bundle-SymbolicName=org.apache.felix.metatype)").setStateMask(Bundle.INSTALLED | Bundle.ACTIVE | Bundle.RESOLVED | Bundle.STARTING).setRequired(true).setCallbacks("add", "change", "remove"));
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.itest.util.Ensure 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 = m.createComponent().setInterface(Service1.class.getName(), null).setImplementation(new MyComponent1(e)).add(m.createServiceDependency().setService(Service2.class).setRequired(true).setAutoConfig("m_service2"));
Component c2 = m.createComponent().setImplementation(new MyComponent2(e)).add(m.createServiceDependency().setService(Service1.class).setRequired(false).setAutoConfig(false).setCallbacks("added", null, null));
Component c3 = m.createComponent().setInterface(Service2.class.getName(), null).setImplementation(Service2Impl.class);
Hashtable h = new Hashtable();
h.put("type", "xx");
Component c4 = m.createComponent().setInterface(Service3.class.getName(), h).setImplementation(Service3Impl1.class);
h = new Hashtable();
h.put("type", "yy");
Component c5 = m.createComponent().setInterface(Service3.class.getName(), h).setImplementation(Service3Impl2.class);
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.itest.util.Ensure 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 = m.createComponent().setInterface(Service1.class.getName(), null).setImplementation(new MyComponent1(e)).add(m.createServiceDependency().setService(Service2.class).setRequired(true).setAutoConfig("m_service2"));
Component c2 = m.createComponent().setImplementation(new MyComponent2(e)).add(m.createServiceDependency().setService(Service1.class).setRequired(false).setAutoConfig(false).setCallbacks("added", null, null));
Component c3 = m.createComponent().setInterface(Service2.class.getName(), null).setImplementation(Service2Impl.class);
Hashtable h = new Hashtable();
h.put("type", "xx");
Component c4 = m.createComponent().setInterface(Service3.class.getName(), h).setImplementation(Service3Impl1.class);
h = new Hashtable();
h.put("type", "yy");
Component c5 = m.createComponent().setInterface(Service3.class.getName(), h).setImplementation(Service3Impl2.class);
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.itest.util.Ensure in project felix by apache.
the class MultipleExtraDependencyTest method testMultipleExtraDependencies.
public void testMultipleExtraDependencies() {
DependencyManager m = getDM();
Ensure e = new Ensure();
Component sp2 = m.createComponent().setImplementation(ServiceProvider2.class).setInterface(ServiceProvider2.class.getName(), null).add(m.createServiceDependency().setService(Runnable.class, "(foo=bar)").setRequired(false).setAutoConfig("m_runnable")).add(m.createServiceDependency().setService(Sequencer.class).setRequired(true).setCallbacks("bind", null)).setCallbacks(null, "start", "stop", null).setComposition("getComposition");
Component sp = m.createComponent().setImplementation(ServiceProvider.class).setInterface(ServiceInterface.class.getName(), new Hashtable() {
{
put("foo", "bar");
}
}).add(m.createServiceDependency().setService(Sequencer.class).setRequired(true).setAutoConfig("m_sequencer")).add(m.createServiceDependency().setService(ServiceProvider2.class).setRequired(true).setCallbacks("bind", "unbind")).setCallbacks(null, "start", "stop", null);
Component sc = m.createComponent().setImplementation(ServiceConsumer.class).add(m.createServiceDependency().setService(Sequencer.class).setRequired(true).setAutoConfig("m_sequencer")).add(m.createServiceDependency().setService(ServiceInterface.class, "(foo=bar)").setRequired(true).setAutoConfig("m_service")).setCallbacks(null, "start", "stop", null);
Component sequencer = m.createComponent().setImplementation(new SequencerImpl(e)).setInterface(Sequencer.class.getName(), null);
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.itest.util.Ensure in project felix by apache.
the class MultipleExtraDependencyTest2 method testMultipleExtraDependencies.
public void testMultipleExtraDependencies() {
DependencyManager m = getDM();
Ensure e = new Ensure();
Component sp2 = m.createComponent().setImplementation(ServiceProvider2.class).setInterface(ServiceProvider2.class.getName(), null).setCallbacks("init", "start", "stop", null).setComposition("getComposition");
Component sp = m.createComponent().setImplementation(ServiceProvider.class).setInterface(ServiceInterface.class.getName(), new Hashtable() {
{
put("foo", "bar");
}
}).setCallbacks("init", "start", "stop", null);
Component sc = m.createComponent().setImplementation(ServiceConsumer.class).setCallbacks("init", "start", "stop", null);
// Provide the Sequencer service to the MultipleAnnotationsTest class.
Component sequencer = m.createComponent().setImplementation(new SequencerImpl(e)).setInterface(Sequencer.class.getName(), null);
m.add(sp2);
m.add(sp);
m.add(sc);
m.add(sequencer);
// Check if the test.annotation components have been initialized orderly
e.waitForStep(7, 10000);
// Stop the test.annotation bundle
m.remove(sequencer);
m.remove(sp);
m.remove(sp2);
m.remove(sc);
// m.remove(sp2);
// m.remove(sc);
// m.remove(sp);
// m.remove(sequencer);
// And check if the test.annotation bundle has been deactivated orderly
e.waitForStep(11, 10000);
m.clear();
}
Aggregations