use of org.apache.felix.ipojo.handler.transaction.services.CheckService in project felix by apache.
the class TestNotSupported method testOkInsideTransaction.
@Test
public void testOkInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-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();
cs.doSomethingGood();
// Is executed in the transaction despite it's not supported.
Transaction t2 = cs.getCurrentTransaction();
Assert.assertSame(t2, t);
t.commit();
}
use of org.apache.felix.ipojo.handler.transaction.services.CheckService in project felix by apache.
the class TestNotSupported method testExpectedExceptionOutsideTransaction.
@Test(expected = UnsupportedOperationException.class)
public void testExpectedExceptionOutsideTransaction() {
ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-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);
((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad2();
}
use of org.apache.felix.ipojo.handler.transaction.services.CheckService in project felix by apache.
the class TestNotSupported method testOkOutsideTransactionWithCallback.
@Test
public void testOkOutsideTransactionWithCallback() {
ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-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.doSomethingGood();
Assert.assertNull(cs.getLastRolledBack());
Assert.assertNull(cs.getLastCommitted());
Assert.assertEquals(0, cs.getNumberOfCommit());
Assert.assertEquals(0, cs.getNumberOfRollback());
}
use of org.apache.felix.ipojo.handler.transaction.services.CheckService in project felix by apache.
the class TestNotSupported method testExceptionOutsideTransaction.
@Test(expected = NullPointerException.class)
public void testExceptionOutsideTransaction() {
ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-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);
((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad();
}
use of org.apache.felix.ipojo.handler.transaction.services.CheckService in project felix by apache.
the class TestRequires 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("requires-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();
}
Aggregations