use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class TestSupported method testExpectedExceptionOutsideTransactionWithCallback.
@Test(expected = UnsupportedOperationException.class)
public void testExpectedExceptionOutsideTransactionWithCallback() {
ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
ComponentInstance under = ipojoHelper.createComponentInstance("supported-cb");
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
cs.doSomethingBad2();
Assert.assertNull(cs.getLastRolledBack());
Assert.assertNull(cs.getLastCommitted());
Assert.assertEquals(0, cs.getNumberOfCommit());
Assert.assertEquals(0, cs.getNumberOfRollback());
}
use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class TestSupported method testExceptionInsideTransactionRB.
@Test
public void testExceptionInsideTransactionRB() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
ComponentInstance under = ipojoHelper.createComponentInstance("supported-ok");
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
Transaction t = tm.getTransaction();
try {
cs.doSomethingBad();
Assert.fail("NullPointerException expected");
} catch (Exception e) {
Assert.assertTrue(e instanceof NullPointerException);
}
Transaction t2 = cs.getCurrentTransaction();
Assert.assertSame(t2, t);
Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, t.getStatus());
t.rollback();
}
use of org.apache.felix.ipojo.ComponentInstance 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.ComponentInstance in project felix by apache.
the class TestCallbacks method testWithPostUnregistrationOnly.
@Test
public void testWithPostUnregistrationOnly() {
ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Callbacks-unreg-only");
// Controller set to true.
osgiHelper.waitForService(FooService.class.getName(), null, 5000);
osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
assertNotNull(check);
Integer reg = (Integer) check.getProps().get("registered");
Integer unreg = (Integer) check.getProps().get("unregistered");
assertNotNull(reg);
assertNotNull(unreg);
assertEquals(new Integer(0), reg);
assertEquals(new Integer(0), unreg);
ci.stop();
reg = (Integer) check.getProps().get("registered");
unreg = (Integer) check.getProps().get("unregistered");
assertNotNull(reg);
assertNotNull(unreg);
assertEquals(new Integer(0), reg);
assertEquals(new Integer(1), unreg);
}
use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class TestCallbacks method testWithTwoPairsOfCallbacks.
@Test
public void testWithTwoPairsOfCallbacks() {
ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Callbacks-both-2");
// Controller set to true.
osgiHelper.waitForService(FooService.class.getName(), null, 5000);
osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
assertNotNull(check);
Integer reg = (Integer) check.getProps().get("registered");
Integer unreg = (Integer) check.getProps().get("unregistered");
Integer reg2 = (Integer) check.getProps().get("registered2");
Integer unreg2 = (Integer) check.getProps().get("unregistered2");
assertNotNull(reg);
assertNotNull(unreg);
assertNotNull(reg2);
assertNotNull(unreg2);
assertEquals(new Integer(1), reg);
assertEquals(new Integer(0), unreg);
assertEquals(new Integer(1), reg2);
assertEquals(new Integer(0), unreg2);
ci.stop();
reg = (Integer) check.getProps().get("registered");
unreg = (Integer) check.getProps().get("unregistered");
reg2 = (Integer) check.getProps().get("registered2");
unreg2 = (Integer) check.getProps().get("unregistered2");
assertNotNull(reg2);
assertNotNull(unreg2);
assertEquals(new Integer(1), reg);
assertEquals(new Integer(1), unreg);
assertEquals(new Integer(1), reg2);
assertEquals(new Integer(1), unreg2);
}
Aggregations