Search in sources :

Example 6 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class DefaultImplementationTest method testDefaultImplementation.

@Test
public void testDefaultImplementation() {
    String prov = "provider";
    ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-DICheckServiceProvider", un);
    ServiceReference ref_fs = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov);
    assertNotNull("Check foo availability", ref_fs);
    ServiceReference ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability", ref_cs);
    CheckService cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation", cs.check());
    // Stop the provider.
    provider.stop();
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 2", ref_cs);
    long begin = System.currentTimeMillis();
    DelayedProvider dp = new DelayedProvider(provider, 200);
    dp.start();
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation - 2", cs.check());
    long end = System.currentTimeMillis();
    assertTrue("Assert delay", (end - begin) >= 200);
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 3", ref_cs);
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation - 3", cs.check());
    provider.stop();
    provider.dispose();
    under.stop();
    under.dispose();
}
Also used : FooService(org.apache.felix.ipojo.handler.temporal.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.temporal.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 7 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class DefaultImplementationTest method testDelayTimeoutWithProxy.

@Test
public void testDelayTimeoutWithProxy() {
    String prov = "provider";
    ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-DIProxiedCheckServiceProviderTimeout", un);
    ServiceReference ref_fs = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov);
    assertNotNull("Check foo availability", ref_fs);
    ServiceReference ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability", ref_cs);
    CheckService cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation", cs.check());
    // Stop the provider.
    provider.stop();
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 2", ref_cs);
    long begin = System.currentTimeMillis();
    DelayedProvider dp = new DelayedProvider(provider, 200);
    dp.start();
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation - 2", cs.check());
    long end = System.currentTimeMillis();
    assertTrue("Assert delay", (end - begin) >= 200);
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 3", ref_cs);
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation - 3", cs.check());
    provider.stop();
    provider.dispose();
    under.stop();
    under.dispose();
}
Also used : FooService(org.apache.felix.ipojo.handler.temporal.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.temporal.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 8 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class DefaultImplementationTest method testDefaultImplementationProxiedCollectionTimeout.

@Test
public void testDefaultImplementationProxiedCollectionTimeout() {
    String prov = "provider";
    ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-DIProxiedColCheckServiceProviderTimeout", un);
    ServiceReference ref_fs = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov);
    assertNotNull("Check foo availability", ref_fs);
    ServiceReference ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability", ref_cs);
    CheckService cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation", cs.check());
    // Stop the provider.
    provider.stop();
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 2", ref_cs);
    DelayedProvider dp = new DelayedProvider(provider, 400);
    dp.start();
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    boolean res = false;
    try {
        res = cs.check();
    } catch (RuntimeException e) {
        fail("A nullable was expected ...");
    }
    assertFalse("Check nullable", res);
    dp.stop();
    provider.stop();
    provider.dispose();
    under.stop();
    under.dispose();
    return;
}
Also used : FooService(org.apache.felix.ipojo.handler.temporal.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.temporal.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 9 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class DefaultImplementationTest method testDefaultImplementationTimeout.

@Test
public void testDefaultImplementationTimeout() {
    String prov = "provider";
    ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-DICheckServiceProvider", un);
    ServiceReference ref_fs = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov);
    assertNotNull("Check foo availability", ref_fs);
    ServiceReference ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability", ref_cs);
    CheckService cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation", cs.check());
    // Stop the provider.
    provider.stop();
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 2", ref_cs);
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    boolean res = false;
    try {
        res = cs.check();
    } catch (RuntimeException e) {
        fail("A nullable was expected ...");
    }
    assertFalse("Check nullable", res);
    provider.stop();
    provider.dispose();
    under.stop();
    under.dispose();
    return;
}
Also used : FooService(org.apache.felix.ipojo.handler.temporal.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.temporal.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 10 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class DefaultImplementationTest method testDefaultImplementationCollectionTimeout.

@Test
public void testDefaultImplementationCollectionTimeout() {
    String prov = "provider";
    ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-DIColCheckServiceProviderTimeout", un);
    ServiceReference ref_fs = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov);
    assertNotNull("Check foo availability", ref_fs);
    ServiceReference ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability", ref_cs);
    CheckService cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation", cs.check());
    // Stop the provider.
    provider.stop();
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 2", ref_cs);
    DelayedProvider dp = new DelayedProvider(provider, 400);
    dp.start();
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    boolean res = false;
    try {
        res = cs.check();
    } catch (RuntimeException e) {
        fail("A nullable was expected ...");
    }
    assertFalse("Check nullable", res);
    dp.stop();
    provider.stop();
    provider.dispose();
    under.stop();
    under.dispose();
    return;
}
Also used : FooService(org.apache.felix.ipojo.handler.temporal.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.temporal.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

ComponentInstance (org.apache.felix.ipojo.ComponentInstance)373 Test (org.junit.Test)360 ServiceReference (org.osgi.framework.ServiceReference)215 Properties (java.util.Properties)142 CheckService (org.apache.felix.ipojo.handler.temporal.services.CheckService)70 FooService (org.apache.felix.ipojo.handler.temporal.services.FooService)70 CheckService (org.apache.felix.ipojo.handler.transaction.services.CheckService)65 Factory (org.apache.felix.ipojo.Factory)53 CheckService (org.apache.felix.ipojo.runtime.core.services.CheckService)50 ServiceContext (org.apache.felix.ipojo.ServiceContext)47 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)39 IOException (java.io.IOException)29 CheckService (org.apache.felix.ipojo.runtime.core.test.services.CheckService)22 BundleContext (org.osgi.framework.BundleContext)19 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)17 ComponentFactory (org.apache.felix.ipojo.ComponentFactory)14 Dictionary (java.util.Dictionary)12 Hashtable (java.util.Hashtable)12 BarService (org.apache.felix.ipojo.runtime.core.services.BarService)10 DependencyDescription (org.apache.felix.ipojo.handlers.dependency.DependencyDescription)9