use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class TemporalTest 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-CheckServiceProviderUsingTemporal", 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();
}
use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class TemporalTest method testDelayWithProxy.
@Test
public void testDelayWithProxy() {
String prov = "provider";
ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
String un = "under-1";
ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-ProxiedCheckServiceProviderUsingTemporal", 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();
}
use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class TemporalTest method testTimeout.
@Test
public void testTimeout() {
String prov = "provider";
ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
String un = "under-1";
ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-CheckServiceProviderUsingTemporal", 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, 4000);
dp.start();
cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
try {
cs.check();
} catch (RuntimeException e) {
// OK
dp.stop();
provider.stop();
provider.dispose();
under.stop();
under.dispose();
return;
}
fail("Timeout expected");
}
use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class TemporalTest method testSetTimeoutWithProxy.
@Test
public void testSetTimeoutWithProxy() {
String prov = "provider";
ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
String un = "under-1";
ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-ProxiedCheckServiceProviderTimeoutUsingTemporal", 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);
try {
cs.check();
} catch (RuntimeException e) {
// OK
dp.stop();
provider.stop();
provider.dispose();
under.stop();
under.dispose();
return;
}
fail("Timeout expected");
}
use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class TestInstallation method install.
@Test
public void install() throws NotSupportedException, SystemException, IllegalStateException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException, InvalidSyntaxException {
Bundle[] bundles = context.getBundles();
for (Bundle b : bundles) {
System.out.println("Bundle : " + b.getSymbolicName() + " - " + b.getState());
Assert.assertTrue(b.getSymbolicName(), b.getState() == Bundle.ACTIVE);
}
osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
// Transaction Service available
osgiHelper.isServiceAvailable(TransactionManager.class.getName());
TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
Assert.assertNotNull(tm.getTransaction());
tm.commit();
tm.begin();
Assert.assertNotNull(tm.getTransaction());
tm.rollback();
// Handler exposed
ServiceReference ref = osgiHelper.getServiceReference(HandlerFactory.class.getName(), "(&(handler.name=transaction)(handler.namespace=org.apache.felix.ipojo.transaction))");
Assert.assertNotNull(ref);
// Create an install of the components
ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
ComponentInstance under = ipojoHelper.createComponentInstance("requires-ok");
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
ServiceReference[] refs = context.getAllServiceReferences(CheckService.class.getName(), "(instance.name=" + under.getInstanceName() + ")");
// ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(refs);
((CheckService) osgiHelper.getServiceObject(refs[0])).doSomethingGood();
}
Aggregations