Search in sources :

Example 56 with Ensure

use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.

the class MultipleServiceDependencyTest method testReplacementCallbacks.

public void testReplacementCallbacks() {
    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 = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
    Component provider2 = m.createComponent().setImplementation(new ServiceProvider2(e)).setInterface(ServiceInterface.class.getName(), null);
    Component consumer = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true).setCallbacks("add", "remove"));
    m.add(provider2);
    m.add(consumer);
    e.waitForStep(3, 15000);
    m.add(provider);
    m.remove(provider2);
    e.step(4);
    e.waitForStep(5, 15000);
    m.remove(provider);
    m.remove(consumer);
    e.waitForStep(6, 15000);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 57 with Ensure

use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.

the class OptionalConfigurationDependencyTest method testOptionalConfigurationConsumer.

public void testOptionalConfigurationConsumer() {
    DependencyManager m = getDM();
    Ensure e = new Ensure();
    Component c1 = m.createComponent().setImplementation(new ConfigurationCreator(e, PID, 3)).add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true));
    Component c2 = m.createComponent().setImplementation(new OptionalConfigurationConsumer(e)).add(m.createConfigurationDependency().setCallback("updated", MyConfig.class).setPid(PID).setPropagate(true).setRequired(false));
    m.add(c2);
    // c2 called in updated with testKey="default" config
    e.waitForStep(1, 5000);
    // c2 called in start()
    e.waitForStep(2, 5000);
    // c1 registers a "testKey=testvalue" configuration, using config admin.
    m.add(c1);
    // c1 created the conf.
    e.waitForStep(3, 5000);
    // c2 called in updated with testKey="testvalue"
    e.waitForStep(4, 5000);
    // remove configuration.
    m.remove(c1);
    // c2 called in updated with default "testkey=default" property (using the default method from the config interface.
    e.waitForStep(5, 5000);
    // stop the OptionalConfigurationConsumer component
    m.remove(c2);
    // c2 stopped
    e.waitForStep(6, 5000);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 58 with Ensure

use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.

the class AspectAnnotationTest method testAspectChain.

public void testAspectChain() throws Throwable {
    Ensure e = new Ensure();
    // Activate service consumer
    ServiceRegistration scSequencer = register(e, ServiceConsumer.ENSURE);
    // Activate service provider
    ServiceRegistration spSequencer = register(e, ServiceProvider.ENSURE);
    // Activate service aspect 2
    ServiceRegistration sa2Sequencer = register(e, ServiceAspect2.ENSURE);
    // Activate service aspect 3
    ServiceRegistration sa3Sequencer = register(e, ServiceAspect3.ENSURE);
    // Activate service aspect 1
    ServiceRegistration sa1Sequencer = register(e, ServiceAspect1.ENSURE);
    e.step();
    e.waitForStep(6, 10000);
    // Deactivate service provider
    spSequencer.unregister();
    // Make sure that service aspect 1 has been called in ts removed and stop callbacks
    e.waitForStep(8, 10000);
    e.ensure();
    scSequencer.unregister();
    sa1Sequencer.unregister();
    sa2Sequencer.unregister();
    sa3Sequencer.unregister();
}
Also used : Ensure(org.apache.felix.dm.itest.util.Ensure) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 59 with Ensure

use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.

the class AspectLifecycleAnnotationTest method testAnnotatedAspect.

public void testAnnotatedAspect() {
    Ensure e = new Ensure();
    // Provide the Sequencer server to the ServiceProvider service
    ServiceRegistration sr1 = register(e, ServiceProvider.ENSURE);
    // Check if the ServiceProvider has been injected in the AspectTest service.
    e.waitForStep(1, 10000);
    // Provide the Sequencer server to the ServiceProviderAspect service
    ServiceRegistration sr2 = register(e, ServiceProviderAspect.ENSURE);
    // Check if the AspectTest has been injected with the aspect
    e.waitForStep(3, 10000);
    // Stop the ServiceProviderAspect service.
    sr2.unregister();
    // And check if the aspect has been called in its stop/destroy methods.
    e.waitForStep(7, 10000);
    sr1.unregister();
}
Also used : Ensure(org.apache.felix.dm.itest.util.Ensure) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 60 with Ensure

use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.

the class AspectLifecycleWithDynamicProxyAnnotationTest method testAnnotatedAspect.

public void testAnnotatedAspect() {
    Ensure e = new Ensure();
    // Provide the Sequencer server to the ServiceProvider service
    ServiceRegistration sr1 = register(e, ServiceProvider.ENSURE);
    // Check if the ServiceProvider has been injected in the AspectTest service.
    e.waitForStep(1, 10000);
    // Provide the Sequencer server to the ServiceProviderAspect service
    ServiceRegistration sr2 = register(e, ServiceProviderAspect.ENSURE);
    // Check if the AspectTest has been injected with the aspect
    e.waitForStep(3, 10000);
    // Remove the ServiceProviderAspect service
    sr2.unregister();
    // And check if the aspect has been called in its stop/destroy methods.
    e.waitForStep(7, 10000);
    sr1.unregister();
}
Also used : Ensure(org.apache.felix.dm.itest.util.Ensure) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Aggregations

Ensure (org.apache.felix.dm.itest.util.Ensure)135 Component (org.apache.felix.dm.Component)90 DependencyManager (org.apache.felix.dm.DependencyManager)90 ServiceRegistration (org.osgi.framework.ServiceRegistration)42 Hashtable (java.util.Hashtable)32 Dictionary (java.util.Dictionary)8 URL (java.net.URL)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ResourceHandler (org.apache.felix.dm.ResourceHandler)5 IOException (java.io.IOException)4 Dependency (org.apache.felix.dm.Dependency)4 ServiceDependency (org.apache.felix.dm.ServiceDependency)4 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)4 ArrayList (java.util.ArrayList)2 ForkJoinPool (java.util.concurrent.ForkJoinPool)2 TimeUnit (java.util.concurrent.TimeUnit)2 ComponentStateListener (org.apache.felix.dm.ComponentStateListener)2 TestBase (org.apache.felix.dm.itest.util.TestBase)2 Bundle (org.osgi.framework.Bundle)2