Search in sources :

Example 41 with CheckService

use of org.apache.felix.ipojo.handler.temporal.services.CheckService in project felix by apache.

the class DefaultImplementationTest method testDelayOnProxiedCollectionDependency.

@Test
public void testDelayOnProxiedCollectionDependency() {
    String prov = "provider";
    ComponentInstance provider1 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String prov2 = "provider2";
    ComponentInstance provider2 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov2);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-NullableProxiedColCheckServiceProviderTimeout", 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 providers.
    provider1.stop();
    provider2.stop();
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 2", ref_cs);
    long begin = System.currentTimeMillis();
    DelayedProvider dp = new DelayedProvider(provider1, 1500);
    DelayedProvider dp2 = new DelayedProvider(provider2, 100);
    dp.start();
    dp2.start();
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation - 2", cs.check());
    long end = System.currentTimeMillis();
    System.out.println("delay = " + (end - begin));
    assertTrue("Assert min delay", (end - begin) >= 100);
    assertTrue("Assert max delay", (end - begin) <= 1000);
    dp.stop();
    dp2.stop();
    provider1.stop();
    provider2.stop();
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 3", ref_cs);
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    // Will return false as the contained DI will return false to the foo method.
    assertFalse("Check invocation - 3", cs.check());
    provider1.dispose();
    provider2.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 42 with CheckService

use of org.apache.felix.ipojo.handler.temporal.services.CheckService in project felix by apache.

the class DelayTest method testDelayOnCollectionDependency.

@Test
public void testDelayOnCollectionDependency() {
    String prov = "provider";
    ComponentInstance provider1 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String prov2 = "provider2";
    ComponentInstance provider2 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov2);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-ColCheckServiceProvider", 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 providers.
    provider1.stop();
    provider2.stop();
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 2", ref_cs);
    long begin = System.currentTimeMillis();
    DelayedProvider dp = new DelayedProvider(provider1, 1500);
    DelayedProvider dp2 = new DelayedProvider(provider2, 100);
    dp.start();
    dp2.start();
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation - 2", cs.check());
    long end = System.currentTimeMillis();
    System.out.println("delay = " + (end - begin));
    assertTrue("Assert min delay", (end - begin) >= 100);
    assertTrue("Assert max delay", (end - begin) <= 1000);
    dp.stop();
    dp2.stop();
    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());
    provider1.stop();
    provider2.stop();
    provider1.dispose();
    provider2.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 43 with CheckService

use of org.apache.felix.ipojo.handler.temporal.services.CheckService in project felix by apache.

the class DelayTest method testDelayOnProxiedCollectionDependency.

@Test
public void testDelayOnProxiedCollectionDependency() {
    String prov = "provider";
    ComponentInstance provider1 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String prov2 = "provider2";
    ComponentInstance provider2 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov2);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-ProxiedColCheckServiceProvider", 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 providers.
    provider1.stop();
    provider2.stop();
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 2", ref_cs);
    long begin = System.currentTimeMillis();
    DelayedProvider dp = new DelayedProvider(provider1, 1500);
    DelayedProvider dp2 = new DelayedProvider(provider2, 100);
    dp.start();
    dp2.start();
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation - 2", cs.check());
    long end = System.currentTimeMillis();
    System.out.println("delay = " + (end - begin));
    assertTrue("Assert min delay", (end - begin) >= 100);
    assertTrue("Assert max delay", (end - begin) <= 1000);
    dp.stop();
    dp2.stop();
    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());
    provider1.stop();
    provider2.stop();
    provider1.dispose();
    provider2.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 44 with CheckService

use of org.apache.felix.ipojo.handler.temporal.services.CheckService in project felix by apache.

the class DelayTest method testDelayOnMultipleDependency.

@Test
public void testDelayOnMultipleDependency() {
    String prov = "provider";
    ComponentInstance provider1 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String prov2 = "provider2";
    ComponentInstance provider2 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov2);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-MultipleCheckServiceProvider", 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 providers.
    provider1.stop();
    provider2.stop();
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 2", ref_cs);
    long begin = System.currentTimeMillis();
    DelayedProvider dp = new DelayedProvider(provider1, 1500);
    DelayedProvider dp2 = new DelayedProvider(provider2, 100);
    dp.start();
    dp2.start();
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation - 2", cs.check());
    long end = System.currentTimeMillis();
    System.out.println("delay = " + (end - begin));
    assertTrue("Assert min delay", (end - begin) >= 100);
    assertTrue("Assert max delay", (end - begin) <= 1000);
    dp.stop();
    dp2.stop();
    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());
    provider1.stop();
    provider2.stop();
    provider1.dispose();
    provider2.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 45 with CheckService

use of org.apache.felix.ipojo.handler.temporal.services.CheckService in project felix by apache.

the class DelayTest method testDelay.

@Test
public void testDelay() {
    String prov = "provider";
    ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-CheckServiceProvider", 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();
    assertNull("No FooService", osgiHelper.getServiceReference(FooService.class.getName(), null));
    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) + ")", (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)

Aggregations

ComponentInstance (org.apache.felix.ipojo.ComponentInstance)70 CheckService (org.apache.felix.ipojo.handler.temporal.services.CheckService)70 FooService (org.apache.felix.ipojo.handler.temporal.services.FooService)70 Test (org.junit.Test)70 ServiceReference (org.osgi.framework.ServiceReference)70 Dictionary (java.util.Dictionary)4 Hashtable (java.util.Hashtable)4