use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class FELIX2696_ConfigurationAndServiceDependencyTest method testComponentWithRequiredConfigurationAndServicePropertyPropagation.
public void testComponentWithRequiredConfigurationAndServicePropertyPropagation() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a service provider and consumer
Component s1 = m.createComponent().setImplementation(new ConfigurationConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true)).add(m.createConfigurationDependency().setPid(PID));
Component s2 = m.createComponent().setImplementation(new ConfigurationCreator(e)).add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true));
Component s3 = m.createComponent().setInterface(ServiceInterface.class.getName(), null).setImplementation(DependentServiceProvider.class);
m.add(s1);
m.add(s2);
m.add(s3);
e.waitForStep(2, 5000);
warn("removing s3");
m.remove(s3);
warn("readding s3");
m.add(s3);
// after adding the required dependency again, the issue in FELIX-2696 means that the
// updated() method is not invoked for the new instance, and init() is, so our step
// count will only go up to 3 (not 4) causing this test to fail
e.waitForStep(4, 5000);
m.remove(s3);
m.remove(s2);
m.remove(s1);
e.waitForStep(5, 5000);
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class FELIX4913_OptionalCallbackInvokedTwiceTest method test_A_Defines_BDependency_FromInitMethod.
public void test_A_Defines_BDependency_FromInitMethod() throws Throwable {
final DependencyManager m = getDM();
Ensure e = new Ensure();
Component bFactory = m.createComponent().setImplementation(new BFactory()).setInterface(BFactory.class.getName(), null);
Dependency dep = m.createServiceDependency().setService(B.class).setRequired(false).setCallbacks("bind", "unbind");
Component a = m.createComponent().setImplementation(new A(e, dep)).add(m.createServiceDependency().setService(BFactory.class).setRequired(false).setCallbacks("bind", "unbind"));
// Enable first bFactory.
m.add(bFactory);
// Then Enable A.
m.add(a);
// A should get BFactory, then it should instantiate B, and B should then be bound to A.
e.waitForStep(4, 5000);
// Now, remove BFactory. The AComponent should then call bFactory.removeB(), abd A.unbind(B) should be called.
m.remove(bFactory);
e.waitForStep(6, 5000);
e.ensure();
clearComponents();
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class FELIX5238_TypeSafeConfigWithDefaultMethodTest method testComponentWithRequiredConfigurationWithTypeSafeConfigAnnotation.
/**
* Tests that we can provision a type-safe config annotation to a component.
*/
public void testComponentWithRequiredConfigurationWithTypeSafeConfigAnnotation() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a service provider and consumer
ConfigurationConsumer1 consumer = new ConfigurationConsumer1(e);
Component s1 = m.createComponent().setImplementation(consumer).add(m.createConfigurationDependency().setCallback("updated", MyConfigAnnot.class).setPid(PID).setPropagate(true));
Component s2 = m.createComponent().setImplementation(new ConfigurationCreator(e, PID, 1)).add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true));
m.add(s1);
m.add(s2);
// s2 called in init
e.waitForStep(1, 5000);
// s1 called in updated(), then in init()
e.waitForStep(3, 5000);
// remove conf
m.remove(s2);
// s1 called in updated(null), s1 called in destroy()
e.waitForStep(5, 5000);
m.remove(s1);
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class FELIX5471_CyclicDependencyTest method testCyclicDependency.
public void testCyclicDependency() throws InterruptedException {
DependencyManager m = getDM();
ForkJoinPool tpool = new ForkJoinPool(2);
try {
for (int count = 0; count < 1000; count++) {
m_ensure = new Ensure(false);
Component a = m.createComponent().setImplementation(new A()).setInterface(A.class.getName(), null).add(m.createServiceDependency().setService(B.class).setRequired(true).setCallbacks("add", "remove"));
Component b = m.createComponent().setImplementation(new B()).setInterface(B.class.getName(), null).add(m.createServiceDependency().setService(A.class).setRequired(false).setCallbacks("add", "remove"));
m.add(a);
m.add(b);
ComponentStateListener l = (c, s) -> {
if (s == ComponentState.INACTIVE) {
m_ensure.step();
}
};
a.add(l);
b.add(l);
// A started, B started
m_ensure.waitForStep(4, 5000);
tpool.execute(() -> m.remove(a));
tpool.execute(() -> m.remove(b));
// A unbound from B, stopped and inactive, B unbound from A, stopped and inactive
m_ensure.waitForStep(10, 5000);
tpool.awaitQuiescence(5000, TimeUnit.MILLISECONDS);
}
} finally {
tpool.shutdown();
}
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class FELIX_4168AdapterWithDynamicallyAddedDependencies method testAdapterWithExtraDependenciesAndCallbacks.
public void testAdapterWithExtraDependenciesAndCallbacks() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a service S2, which will be added to A1 (needs to be available)
Component s2 = m.createComponent().setInterface(S2.class.getName(), null).setImplementation(new S2Impl(e));
m.add(s2);
// create a service adapter that adapts to services S1 and has an optional dependency on services S2
Component sa = m.createAdapterService(S1.class, null).setImplementation(SA.class);
m.add(sa);
// create a service S1, which triggers the creation of the first adapter instance (A1)
Component s1 = m.createComponent().setInterface(S1.class.getName(), null).setImplementation(new S1Impl());
m.add(s1);
// create a second service S1, which triggers the creation of the second adapter instance (A2)
Component s1b = m.createComponent().setInterface(S1.class.getName(), null).setImplementation(new S1Impl());
m.add(s1b);
// observe that S2 is also added to A2
e.waitForStep(2, 5000);
// remove S2 again
m.remove(s2);
// make sure both adapters have their "remove" callbacks invoked
e.waitForStep(4, 5000);
m.clear();
}
Aggregations