Package org.apache.felix.dm.test.components

Examples of org.apache.felix.dm.test.components.Ensure


public class AspectChainTest extends TestBase {
    @Test
    public void testBuildAspectChain() {
        DependencyManager m = new DependencyManager(context);
        // 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();
       
        m.remove(sa3);
        m.remove(sa2);
        m.remove(sa1);
        m.remove(sp);
View Full Code Here


public class AspectAwareServiceDependencyTest extends TestBase {
    @Test
    public void testServiceRegistrationAndConsumption() {
        DependencyManager m = new DependencyManager(context);
        // 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 ServiceConsumerCallbacks(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(false).setCallbacks("add", "change", "remove", "swap"));
        Component asp = m.createAspectService(ServiceInterface.class, null, 1000, null).setImplementation(ServiceProviderAspect.class);
        m.add(sp);
        m.add(sc);
        m.add(asp);       
        m.remove(sc);
        m.remove(sp);
        // ensure we executed all steps inside the component instance
        e.step(4);
    }
View Full Code Here

   
    @Test
    public void testShareResourceDependencyWithMultipleServices() throws Exception {
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        // create a service provider and consumer
        ResourceDependency dependency = m.createResourceDependency().setFilter("(" + ResourceHandler.HOST + "=localhost)").setRequired(true);
        Component consumer1 = m.createComponent().setImplementation(new ResourceConsumer(e, 1)).add(dependency);
        Component consumer2 = m.createComponent().setImplementation(new ResourceConsumer(e, 2)).add(dependency);
        Component resourceProvider = m.createComponent().setImplementation(new ResourceProvider()).add(m.createServiceDependency().setService(ResourceHandler.class).setCallbacks("add", "remove"));;
        m.add(resourceProvider);
        m.add(consumer1);
        e.waitForStep(1, 15000);
        m.add(consumer2);
        e.waitForStep(2, 15000);
        m.remove(consumer2);
        m.remove(consumer1);
        m.remove(resourceProvider);
    }
View Full Code Here

public class ResourceAdapterDependencyAddAndRemoveTest2 extends TestBase {
    @Test
    public void testBasicResourceAdapter() throws Exception {
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        // create a resource provider
        ResourceProvider provider = new ResourceProvider(e);
        // activate it
        Properties props = new Properties();
        props.setProperty("id", "1");
        m.add(m.createComponent()
        .setInterface(ServiceInterface.class.getName(), props)
        .setImplementation(new ServiceProvider(e))
    );
       
        props = new Properties();
        props.setProperty("id", "2");
        m.add(m.createComponent()
        .setInterface(ServiceInterface.class.getName(), props)
        .setImplementation(new ServiceProvider(e))
    );
       
        m.add(m.createComponent()
        .setImplementation(provider)
        .add(m.createServiceDependency()
          .setService(ResourceHandler.class)
          .setCallbacks("add", "remove")
      )
    );
       
        // create a resource adapter for our single resource
        // note that we can provide an actual implementation instance here because there will be only one
        // adapter, normally you'd want to specify a Class here
        ResourceAdapter service = new ResourceAdapter(e);
        CallbackInstance callbackInstance = new CallbackInstance(e);
        Component component = m.createResourceAdapterService("(&(path=/path/to/*.txt)(host=localhost))", false, callbackInstance, "changed")
            .setImplementation(new ResourceAdapter(e))
            .setCallbacks(callbackInstance, "init", "start", "stop", "destroy")
            .add(m.createServiceDependency()
            .setService(ServiceInterface.class, "(id=1)")
            .setRequired(true)
            .setInstanceBound(true)
        );
        component.addStateListener(new ComponentStateListenerImpl(e));
        m.add(component);
        // wait until the single resource is available
        e.waitForStep(1, 5000);
        // trigger a 'change' in our resource
        provider.change();
        // wait until the changed callback is invoked
        e.waitForStep(2, 5000);
       
        System.out.println("Done!");
        m.clear();
     }
View Full Code Here

public class FELIX2696_ConfigurationAndServiceDependencyTest extends TestBase {
    @Test
    public void testComponentWithRequiredConfigurationAndServicePropertyPropagation() {
        DependencyManager m = new DependencyManager(context);
        // 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("test"));
        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);
        m.remove(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);
    }
View Full Code Here

   
    @Test
    public void testComponentWithRequiredUpdatedConfigurationAndServicePropertyPropagation() {
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();       
        ConfigurationCreator confCreator = new ConfigurationCreator();
        Component s1 = m.createComponent()
                .setImplementation(new S1(e))
                .setInterface(S1.class.getName(), null)
                .add(m.createConfigurationDependency()
                     .setPid("test")
                     .setPropagate(true));
        Component s2 = m.createComponent()
                .setImplementation(new S2(e))
                .add(m.createServiceDependency()
                     .setService(S1.class, ("(testkey=testvalue)"))
                     .setRequired(true)
                     .setCallbacks("add", "change", null));
        Component s3 = m.createComponent()
                .setImplementation(confCreator)
                .add(m.createServiceDependency()
                     .setService(ConfigurationAdmin.class)
                     .setRequired(true));

        m.add(s1);
        m.add(s2);
        m.add(s3);
        e.waitForStep(2, 15000);
        confCreator.update();
        e.waitForStep(4, 15000);
        m.remove(s1);
        m.remove(s2);
        m.remove(s3);
    }
View Full Code Here

    }
   
    @Test
    public void testAdapterWithChangedInstanceBoundDependency() {
        DependencyManager m = new DependencyManager(context);
        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.dependencymanager.shell)")
                        .setStateMask(Bundle.INSTALLED|Bundle.ACTIVE|Bundle.RESOLVED|Bundle.STARTING)
                        .setRequired(true)
                        .setCallbacks("add", "change", "remove"));
                   
        Bundle dmtest = getBundle("org.apache.felix.dependencymanager.shell");
        try {
            dmtest.stop();
        } catch (BundleException e1) {
            Assert.fail("couold not find dependencymanager shell bundle");
        }
       
        m.add(a);
        m.add(b);
       
        e.waitForStep(4, 5000);       
        m.remove(a); // B will loose A and will enter into "waiting for required (instantiated)" state.
        System.out.println("Starting dependency manager shell ...");       
        try {
            dmtest.start();
        } catch (BundleException e1) {
            Assert.fail("could not start dependencymanager shell bundle");
        }
        e.waitForStep(7, 5000);    
        m.remove(b);       
        e.waitForStep(10, 5000);               
    }
View Full Code Here

public class ServiceDependencyComponentLifeCycleTest extends TestBase {
    @Test
    public void testComponentLifeCycleWhenAddingAndRemovingDependencies() throws Exception {
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        // create a resource provider
       
        Component component = m.createComponent().setInterface(MyService2.class.getName(), null).setImplementation(new MyComponent(e));
        ServiceDependency dependency = m.createServiceDependency().setService(MyService.class).setRequired(true);
        ServiceDependency dependency2 = m.createServiceDependency().setService(MyService.class).setRequired(true);
        ServiceTracker st = new ServiceTracker(context, MyService2.class.getName(), null);
        st.open();
        Component component2 = m.createComponent().setInterface(MyService.class.getName(), null).setImplementation(new MyImpl(e));
       
        // add the component: it has no dependencies so it should be activated immediately
        m.add(component);
        Assert.assertNotNull("service should be available", st.getService());
               
        // add a required dependency that is not available, so the component should be deactivated
        component.add(dependency);
        Assert.assertNull("service should no longer be available", st.getService());
        // remove the dependency again, so the component should be activated again
        component.remove(dependency);
        Assert.assertNotNull("service should be available", st.getService());
        // make the dependency instance bound
        dependency.setInstanceBound(true);
       
        // add it again, the component was already active so even though the dependency
        // is required, the component will *NOT* go through the destroy life cycle methods
        component.add(dependency);
        Assert.assertNull("service should no longer be available", st.getService());
        component.remove(dependency);
        Assert.assertNotNull("service should be available", st.getService());
       
        // make the second dependency instance bound too
        dependency2.setInstanceBound(true);
       
        // activate the service we depend on
        m.add(component2);
        // init and start should be invoked here, so wait for them to complete
        e.waitForStep(10, 5000);
       
        component.add(dependency);
        Assert.assertNotNull("service should be available", st.getService());
        component.add(dependency2);
        Assert.assertNotNull("service should be available", st.getService());
        component.remove(dependency);
        Assert.assertNotNull("service should be available", st.getService());
       
        e.step(11);
       
        // remove the service again, the component still has an instance bound
        // dependency on it, so stop() should be invoked, but the component
        // should not be destroyed
        m.remove(component2);
        e.step(15);
        Assert.assertNull("service should no longer be available", st.getService());
        component.remove(dependency2);
        Assert.assertNotNull("service should be available", st.getService());
        m.remove(component);
        e.step(19);
    }
View Full Code Here

     */
    @Test
    public void testExtraDependencyWithCallback() {
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        // create a service consumer and provider
        Component sp = m.createComponent().setInterface(ProviderInterface.class.getName(), null).setImplementation(ProviderImpl.class);
        Component sc = m.createComponent().setImplementation(new Client(e, false, 1));
        Component sc2 = m.createComponent().setImplementation(new Client(e, true, 5));
        Component sc3 = m.createComponent().setImplementation(new Client(e, true, 9));
       
        // add the provider first, then add the consumer which initially will have no dependencies
        // but via the init() method an optional dependency with a callback method will be added
        m.add(sp);
        m.add(sc);
        // remove the consumer again
        m.remove(sc);
        e.waitForStep(4, 5000);

        // next up, add a second consumer, identical to the first, but with a required dependency
        // with a callback method which will be added in the init() method
        m.add(sc2);
        // remove the consumer again
        m.remove(sc2);
        e.waitForStep(8, 5000);

        // now remove the provider, add a third consumer, identical to the second, and after the
        // consumer has started, add the provider again
        m.remove(sp);
        m.add(sc3);
        m.add(sp);
        e.waitForStep(12, 5000);
        m.clear();
    }
View Full Code Here

public class TemporalServiceDependencyTest extends TestBase {
    @Test
    public void testServiceConsumptionAndIntermittentAvailability() {
        DependencyManager m = new DependencyManager(context);
        // 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 TemporalServiceProvider(e)).setInterface(TemporalServiceInterface.class.getName(), null);
        Component sp2 = m.createComponent().setImplementation(new TemporalServiceProvider2(e)).setInterface(TemporalServiceInterface.class.getName(), null);
        Component sc = m.createComponent().setImplementation(new TemporalServiceConsumer(e)).add(m.createTemporalServiceDependency().setService(TemporalServiceInterface.class).setRequired(true));
        // add the service consumer
        m.add(sc);
        // now add the first provider
        m.add(sp);
        e.waitForStep(2, 15000);
        // and remove it again (this should not affect the consumer yet)
        m.remove(sp);
        // now add the second provider
        m.add(sp2);
        e.step(3);
        e.waitForStep(4, 15000);
        // and remove it again
        m.remove(sp2);
        // finally remove the consumer
        m.remove(sc);
        // ensure we executed all steps inside the component instance
        e.step(6);
    }
View Full Code Here

TOP

Related Classes of org.apache.felix.dm.test.components.Ensure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.