* @throws InvalidSyntaxException
*/
@Test
public void testActiveContextsQuiesce() throws InvalidSyntaxException
{
TranSyncRegistryMock backingTSR = new TranSyncRegistryMock();
TransactionSynchronizationRegistry tsr = Skeleton.newMock(backingTSR, TransactionSynchronizationRegistry.class);
context.registerService(TransactionSynchronizationRegistry.class.getName(), tsr, new Hashtable<String, Object>());
assertNoContextRegistered();
reg1 = registerUnit(emf1, "unit", TRUE);
mgr.registerContext("unit", client1, new HashMap<String, Object>());
reg2 = registerUnit(emf2, "unit2", TRUE);
mgr.registerContext("unit2", client2, new HashMap<String, Object>());
ServiceReference[] refs = context.getServiceReferences(EntityManagerFactory.class.getName(),"(&(" +
PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=true)(osgi.unit.name=unit))");
assertEquals("Wrong number of services found", 1, refs.length);
ServiceReference[] refs2 = context.getServiceReferences(EntityManagerFactory.class.getName(),"(&(" +
PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=true)(osgi.unit.name=unit2))");
assertEquals("Wrong number of services found", 1, refs2.length);
EntityManagerFactory emf = (EntityManagerFactory) context.getService(refs[0]);
EntityManagerFactory emf2 = (EntityManagerFactory) context.getService(refs2[0]);
backingTSR.setTransactionKey("new");
emf.createEntityManager().persist(new Object());
emf2.createEntityManager().persist(new Object());
DestroyCallback cbk = Skeleton.newMock(DestroyCallback.class);
Bundle b = context.getBundle();
mgr.quiesceUnits(b, cbk);
Skeleton.getSkeleton(cbk).assertNotCalled(new MethodCall(DestroyCallback.class,
"callback"));
backingTSR.setTransactionKey("new2");
emf2.createEntityManager().persist(new Object());
Skeleton.getSkeleton(cbk).assertNotCalled(new MethodCall(DestroyCallback.class,
"callback"));
backingTSR.afterCompletion("new");
Skeleton.getSkeleton(cbk).assertNotCalled(new MethodCall(DestroyCallback.class,
"callback"));
assertUniqueContextRegistered("unit2");
backingTSR.afterCompletion("new2");
Skeleton.getSkeleton(cbk).assertCalledExactNumberOfTimes(new MethodCall(DestroyCallback.class,
"callback"), 1);
assertNoContextRegistered();