use of org.apache.felix.ipojo.handler.temporal.services.CheckService in project felix by apache.
the class EmptyTest method testEmptyArrayTimeout.
@Test
public void testEmptyArrayTimeout() {
String prov = "provider";
ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
String un = "under-1";
ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-EmptyMultipleCheckServiceProviderTimeout", 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("An empty array was expected ...");
}
assertTrue("Check empty array", res);
dp.stop();
provider.stop();
provider.dispose();
under.stop();
under.dispose();
return;
}
use of org.apache.felix.ipojo.handler.temporal.services.CheckService in project felix by apache.
the class EmptyTest method testEmptyCollectionTimeout.
@Test
public void testEmptyCollectionTimeout() {
String prov = "provider";
ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
String un = "under-1";
ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-EmptyColCheckServiceProviderTimeout", 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("An empty array was expected ...");
}
assertTrue("Check empty array", res);
dp.stop();
provider.stop();
provider.dispose();
under.stop();
under.dispose();
return;
}
use of org.apache.felix.ipojo.handler.temporal.services.CheckService in project felix by apache.
the class FilterTest method testWithTemporalFilters.
/**
* Checks <tt>temporal.filter</tt> with dependency id.
* The filter is made to get only one provider.
*/
@Test
public void testWithTemporalFilters() {
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", "(instance.name=provider2)");
configuration.put("temporal.filters", 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 testNoDelay.
@Test
public void testNoDelay() {
String prov = "provider";
ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
String un = "under-1";
ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-CheckServiceProvider", un);
assertNotNull("Check creation", under);
assertNotNull("Check provider creation", prov);
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());
provider.stop();
provider.dispose();
under.stop();
under.dispose();
}
use of org.apache.felix.ipojo.handler.temporal.services.CheckService in project felix by apache.
the class NoDelayTest method testNoDelayWithProxy.
@Test
public void testNoDelayWithProxy() {
String prov = "provider";
ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
String un = "under-1";
ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-ProxiedCheckServiceProvider", un);
assertNotNull("Check creation", under);
assertNotNull("Check provider creation", prov);
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());
provider.stop();
provider.dispose();
under.stop();
under.dispose();
}
Aggregations