Package org.apache.aries.jpa.container.context.transaction.impl

Examples of org.apache.aries.jpa.container.context.transaction.impl.TranSyncRegistryMock


   * @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();
View Full Code Here


   * @throws InvalidSyntaxException
   */
  @Test
  public void testActiveContextsQuiesceAll() 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.quiesceAllUnits(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();
View Full Code Here

TOP

Related Classes of org.apache.aries.jpa.container.context.transaction.impl.TranSyncRegistryMock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.