Search in sources :

Example 51 with Ensure

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);
}
Also used : Bundle(org.osgi.framework.Bundle) DependencyManager(org.apache.felix.dm.DependencyManager) BundleException(org.osgi.framework.BundleException) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 52 with Ensure

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();
}
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 53 with Ensure

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();
}
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 54 with Ensure

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);
}
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 55 with Ensure

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();
}
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)

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