tm.begin();
emf.createEntityManager().getProperties();
QuiesceParticipant participant = getParticipant("org.apache.aries.jpa.container.context");
TestQuiesceCallback callback = new TestQuiesceCallback();
participant.quiesce(callback, Collections.singletonList(context().getBundleByName(
"org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle")));
Thread.sleep(1000);
assertFalse("Quiesce finished", callback.bundleClearedUp());
emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)("
+ PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
"(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))");
tm.commit();
assertTrue("Quiesce not finished", callback.bundleClearedUp());
ServiceReference[] refs = bundleContext.getAllServiceReferences(EntityManagerFactory.class.getName(), "(&(osgi.unit.name=test-unit)("
+ PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
"(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))");
assertNull("No context should exist",refs);
//Restart the bundle to check the context gets re-registered, then ensure it isn't
//tidied up immediately again!
Bundle b = context().getBundleByName("org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle");
b.stop();
b.start();
emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)("
+ PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
"(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))");
tm.begin();
emf.createEntityManager().getProperties();
tm.commit();
Thread.sleep(1000);
emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)("
+ PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
"(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))", 100);
//Test again to make sure we don't hold state over
tm.begin();
emf.createEntityManager().getProperties();
callback = new TestQuiesceCallback();
participant.quiesce(callback, Collections.singletonList(context().getBundleByName(
"org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle")));
Thread.sleep(1000);
assertFalse("Quiesce finished", callback.bundleClearedUp());