ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
osgi.waitForService(TransactionManager.class.getName(), null, 5000);
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
Thread thread = new Thread (new Runnable() {
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
prov.dispose();
}
});
thread.start();
tm.begin();
Transaction t = tm.getTransaction();
cs.doSomethingLong(); // 5s, so prov should be disposed during this time and under becomes invalid
Assert.assertEquals(ComponentInstance.INVALID, under.getState());
Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, t.getStatus());