use of org.apache.felix.ipojo.runtime.test.dependencies.timeout.services.CheckService in project felix by apache.
the class TimeoutTest method testDelay.
@Test
public void testDelay() {
String prov = "provider";
ComponentInstance provider = ipojoHelper.createComponentInstance("FooProvider", prov);
String un = "under-1";
ComponentInstance under = ipojoHelper.createComponentInstance("CheckServiceProviderTimeout", 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.getRawServiceObject(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.getRawServiceObject(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.getRawServiceObject(ref_cs);
assertTrue("Check invocation - 3", cs.check());
provider.stop();
provider.dispose();
under.stop();
under.dispose();
}
use of org.apache.felix.ipojo.runtime.test.dependencies.timeout.services.CheckService in project felix by apache.
the class NullableTest method testNullableTimeout.
@Test
public void testNullableTimeout() {
String prov = "provider";
ComponentInstance provider = ipojoHelper.createComponentInstance("FooProvider", prov);
String un = "under-1";
ComponentInstance under = ipojoHelper.createComponentInstance("NullableCheckServiceProvider", 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.getRawServiceObject(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.getRawServiceObject(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();
}
use of org.apache.felix.ipojo.runtime.test.dependencies.timeout.services.CheckService in project felix by apache.
the class TimeoutTest method testTimeoutWithException.
@Test
public void testTimeoutWithException() {
String prov = "provider";
ComponentInstance provider = ipojoHelper.createComponentInstance("FooProvider", prov);
String un = "under-1";
ComponentInstance under = ipojoHelper.createComponentInstance("ExceptionCheckServiceProviderTimeout", 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.getRawServiceObject(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);
delayed = new DelayedProvider(provider, 1000);
delayed.start();
cs = (CheckService) osgiHelper.getRawServiceObject(ref_cs);
try {
cs.check();
} catch (RuntimeException e) {
// OK
delayed.stop();
provider.stop();
provider.dispose();
under.stop();
under.dispose();
return;
}
if (TimeUtils.TIME_FACTOR == 1) {
fail("An exception was expected ...");
} else {
System.err.println("An exception was expected, however this test really depends on your CPU and IO " + "speed");
}
}
use of org.apache.felix.ipojo.runtime.test.dependencies.timeout.services.CheckService in project felix by apache.
the class NullTest method testDelayTimeout.
@Test
public void testDelayTimeout() {
String prov = "provider";
ComponentInstance provider = ipojoHelper.createComponentInstance("FooProvider", prov);
String un = "under-1";
ComponentInstance under = ipojoHelper.createComponentInstance("NullCheckServiceProviderTimeout", 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.getRawServiceObject(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.getRawServiceObject(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.getRawServiceObject(ref_cs);
assertTrue("Check invocation - 3", cs.check());
provider.stop();
provider.dispose();
under.stop();
under.dispose();
}
use of org.apache.felix.ipojo.runtime.test.dependencies.timeout.services.CheckService in project felix by apache.
the class NullableTest method testDelayTimeout.
@Test
public void testDelayTimeout() {
String prov = "provider";
ComponentInstance provider = ipojoHelper.createComponentInstance("FooProvider", prov);
String un = "under-1";
ComponentInstance under = ipojoHelper.createComponentInstance("NullableCheckServiceProviderTimeout", 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.getRawServiceObject(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.getRawServiceObject(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.getRawServiceObject(ref_cs);
assertTrue("Check invocation - 3", cs.check());
provider.stop();
provider.dispose();
under.stop();
under.dispose();
}
Aggregations