use of org.apache.felix.ipojo.handler.transaction.services.CheckService 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();
}
use of org.apache.felix.ipojo.handler.transaction.services.CheckService in project felix by apache.
the class TestMandatory 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("mandatory-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();
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 TestMandatory method testExceptionOutsideTransaction.
@Test(expected = RuntimeException.class)
public void testExceptionOutsideTransaction() {
ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-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);
// Fail, RTE thrown before the other exception
((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad();
}
use of org.apache.felix.ipojo.handler.transaction.services.CheckService in project felix by apache.
the class TestMandatory method testExpectedExceptionOutsideTransactionWithCallback.
@Test(expected = RuntimeException.class)
public void testExpectedExceptionOutsideTransactionWithCallback() {
ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-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();
}
use of org.apache.felix.ipojo.handler.transaction.services.CheckService in project felix by apache.
the class TestMandatory 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("mandatory-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