Search in sources :

Example 26 with Ensure

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

the class AspectBaseTest method testMultipleAspects.

@SuppressWarnings("serial")
public void testMultipleAspects() {
    DependencyManager m = new DependencyManager(context);
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create service providers and consumers
    ServiceConsumer c = new ServiceConsumer(e);
    Component sp = m.createComponent().setImplementation(new ServiceProvider(e, "a")).setInterface(ServiceInterface.class.getName(), new Hashtable() {

        {
            put("name", "a");
        }
    });
    Component sp2 = m.createComponent().setImplementation(new ServiceProvider(e, "b")).setInterface(ServiceInterface.class.getName(), new Hashtable() {

        {
            put("name", "b");
        }
    });
    Component sc = m.createComponent().setImplementation(c).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true).setCallbacks("add", "remove"));
    Component sa = m.createAspectService(ServiceInterface.class, null, 20, null).setImplementation(ServiceAspect.class);
    Component sa2 = m.createAspectService(ServiceInterface.class, null, 10, null).setImplementation(ServiceAspect.class);
    m.add(sp);
    m.add(sp2);
    m.add(sa);
    m.add(sa2);
    m.add(sc);
    // the consumer will monitor progress, it should get it's add invoked twice, once for every
    // (highest) aspect
    e.waitForStep(2, 2000);
    e.step(3);
    // now invoke all services the consumer collected
    List<String> list = c.invokeAll();
    // and make sure both of them are correctly invoked
    Assert.assertTrue(list.size() == 2);
    Assert.assertTrue(list.contains("aaa"));
    Assert.assertTrue(list.contains("bbb"));
    m.remove(sc);
    // removing the consumer now should get its removed method invoked twice
    e.waitForStep(5, 2000);
    e.step(6);
    m.remove(sa2);
    m.remove(sa);
    m.remove(sp2);
    m.remove(sp);
    e.step(7);
}
Also used : Hashtable(java.util.Hashtable) DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 27 with Ensure

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

the class AspectChainTest method testBuildAspectChain.

public void testBuildAspectChain() {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a service provider and consumer
    Component sp = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
    Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
    Component sa2 = m.createAspectService(ServiceInterface.class, null, 20, null).setImplementation(new ServiceAspect(e, 3));
    Component sa3 = m.createAspectService(ServiceInterface.class, null, 30, null).setImplementation(new ServiceAspect(e, 2));
    Component sa1 = m.createAspectService(ServiceInterface.class, null, 10, null).setImplementation(new ServiceAspect(e, 4));
    m.add(sc);
    m.add(sp);
    m.add(sa2);
    m.add(sa3);
    m.add(sa1);
    e.step();
    e.waitForStep(5, 5000);
    m.remove(sa3);
    m.remove(sa2);
    m.remove(sa1);
    m.remove(sp);
    m.remove(sc);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 28 with Ensure

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

the class AspectServiceDependencyTest method testServiceRegistrationAndConsumption.

public void testServiceRegistrationAndConsumption() {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a service provider and consumer
    Component sp = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
    Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setCallbacks("add", "remove").setRequired(true));
    Component asp = m.createAspectService(ServiceInterface.class, null, 100).setImplementation(ServiceProviderAspect.class);
    m.add(sp);
    m.add(sc);
    m.add(asp);
    m.remove(asp);
    m.remove(sc);
    m.remove(sp);
    // ensure we executed all steps inside the component instance
    e.step(8);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 29 with Ensure

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

the class AspectServiceDependencyWithSwapCallbackTest method testServiceRegistrationAndConsumption.

public void testServiceRegistrationAndConsumption() {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a service provider and consumer
    Component sp = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
    Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setCallbacks("add", null, "remove", "swap").setRequired(true));
    Component asp = m.createAspectService(ServiceInterface.class, null, 100).setImplementation(ServiceProviderAspect.class);
    m.add(sp);
    m.add(sc);
    m.add(asp);
    m.remove(asp);
    m.remove(sc);
    m.remove(sp);
    // ensure we executed all steps inside the component instance
    e.step(7);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 30 with Ensure

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

the class AspectWithCallbacksServiceDependencyTest method testServiceRegistrationAndConsumptionWithAspectCallbackInstance.

public void testServiceRegistrationAndConsumptionWithAspectCallbackInstance() {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a service provider and consumer
    Component sp = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
    Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setCallbacks("add", "remove").setRequired(true));
    ServiceProviderAspect providerAspect = new ServiceProviderAspect();
    ServiceProviderAspectCallbackInstance aspectCb = new ServiceProviderAspectCallbackInstance(providerAspect);
    Component asp = m.createAspectService(ServiceInterface.class, null, 100, aspectCb, "add", null, "remove", "swap").setImplementation(providerAspect);
    m.add(sp);
    m.add(sc);
    m.add(asp);
    m.remove(asp);
    m.remove(sc);
    m.remove(sp);
    // ensure we executed all steps inside the component instance
    e.step(8);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

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