use of org.apache.felix.ipojo.handler.temporal.services.CheckService in project felix by apache.
the class FilterTest method testWithTemporalFrom.
/**
* Checks <tt>temporal.from</tt> with dependency id.
* The filter is made to get only one specific provider.
*/
@Test
public void testWithTemporalFrom() {
String prov = "provider";
ComponentInstance provider1 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
String prov2 = "provider2";
ComponentInstance provider2 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov2);
Dictionary configuration = new Hashtable();
String un = "under-1";
configuration.put("instance.name", un);
Dictionary filter = new Hashtable();
filter.put("foo", "provider2");
configuration.put("temporal.from", filter);
ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-MultipleCheckServiceProvider", configuration);
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.
provider2.stop();
ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
assertNotNull("Check cs availability - 2", ref_cs);
long begin = System.currentTimeMillis();
DelayedProvider dp2 = new DelayedProvider(provider2, 100);
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);
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();
}
use of org.apache.felix.ipojo.handler.temporal.services.CheckService in project felix by apache.
the class FilterTest method testWithRequiresFrom.
/**
* Checks <tt>requires.from</tt> with dependency id.
* The filter is made to get only one specific provider.
*/
@Test
public void testWithRequiresFrom() {
String prov = "provider";
ComponentInstance provider1 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
String prov2 = "provider2";
ComponentInstance provider2 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov2);
Dictionary configuration = new Hashtable();
String un = "under-1";
configuration.put("instance.name", un);
Dictionary filter = new Hashtable();
filter.put("foo", "provider2");
configuration.put("requires.from", filter);
ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-MultipleCheckServiceProvider", configuration);
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.
provider2.stop();
ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
assertNotNull("Check cs availability - 2", ref_cs);
long begin = System.currentTimeMillis();
DelayedProvider dp2 = new DelayedProvider(provider2, 100);
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);
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();
}
use of org.apache.felix.ipojo.handler.temporal.services.CheckService in project felix by apache.
the class NoDelayTest method testCollectionNoDelay.
@Test
public void testCollectionNoDelay() {
String prov1 = "provider-1";
ComponentInstance provider1 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov1);
String un = "under-2";
ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-ColCheckServiceProvider", un);
ServiceReference ref_fs = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov1);
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());
provider1.stop();
provider1.dispose();
under.stop();
under.dispose();
}
use of org.apache.felix.ipojo.handler.temporal.services.CheckService in project felix by apache.
the class NoDelayTest method testMultipleNoDelay.
@Test
public void testMultipleNoDelay() {
String prov1 = "provider-1";
ComponentInstance provider1 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov1);
String un = "under-2";
ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-MultipleCheckServiceProvider", un);
ServiceReference ref_fs = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov1);
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());
provider1.stop();
provider1.dispose();
under.stop();
under.dispose();
}
use of org.apache.felix.ipojo.handler.temporal.services.CheckService in project felix by apache.
the class NoDelayTest method testProxiedCollectionNoDelay.
@Test
public void testProxiedCollectionNoDelay() {
String prov1 = "provider-1";
ComponentInstance provider1 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov1);
String un = "under-2";
ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-ProxiedColCheckServiceProvider", un);
ServiceReference ref_fs = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov1);
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());
provider1.stop();
provider1.dispose();
under.stop();
under.dispose();
}
Aggregations