aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyjw...@apache.org
Subject svn commit: r1166169 [2/2] - in /aries/trunk: ejb/ejb-modeller-itest/ ejb/ejb-modeller-itest/src/test/java/org/apache/aries/ejb/container/itest/ ejb/openejb-extender-itest/ ejb/openejb-extender-itest/src/test/java/beans/integration/ ejb/openejb-extende...
Date Wed, 07 Sep 2011 13:29:16 GMT
Modified: aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/context/transaction/impl/JTAPersistenceContextRegistryTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/context/transaction/impl/JTAPersistenceContextRegistryTest.java?rev=1166169&r1=1166168&r2=1166169&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/context/transaction/impl/JTAPersistenceContextRegistryTest.java
(original)
+++ aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/context/transaction/impl/JTAPersistenceContextRegistryTest.java
Wed Sep  7 13:29:15 2011
@@ -21,6 +21,7 @@ package org.apache.aries.jpa.container.c
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
@@ -246,4 +247,96 @@ public class JTAPersistenceContextRegist
     contexts.getCurrentPersistenceContext(emf1, props1, new AtomicLong(), Skeleton.newMock(DestroyCallback.class));
   }
   
+  @Test(expected=TransactionRequiredException.class)
+  public void testGetExistingNoTran() {
+    reg.setTransactionKey(null);
+    contexts.getExistingPersistenceContext(emf1);
+  }
+  
+  @Test(expected=TransactionRequiredException.class)
+  public void testGetExistingNoTranSyncRegistry() {
+    reg.setTransactionKey("");
+    contexts.removedService(ref, ref);
+    contexts.getExistingPersistenceContext(emf1);
+  }
+  
+  @Test
+  public void testGetExisting()
+  {
+    reg.setTransactionKey("");
+    
+    assertNull(contexts.getExistingPersistenceContext(emf1));
+    assertNull(contexts.getExistingPersistenceContext(emf2));
+    
+    AtomicLong useCount = new AtomicLong(0);
+    DestroyCallback cbk = Skeleton.newMock(DestroyCallback.class);
+    reg.setTransactionKey("");
+    
+    EntityManager em1a = contexts.getCurrentPersistenceContext(emf1, props1, useCount, cbk);
+    EntityManager em1b = contexts.getExistingPersistenceContext(emf1);
+    
+    Skeleton.getSkeleton(emf1).assertCalledExactNumberOfTimes(new MethodCall(EntityManagerFactory.class,
"createEntityManager", props1), 1);
+    Skeleton.getSkeleton(emf1).assertNotCalled(new MethodCall(EntityManagerFactory.class,
"createEntityManager"));
+    Skeleton.getSkeleton(em1a).assertNotCalled(new MethodCall(EntityManager.class, "close"));
+    assertSame("We should get the same delegate!", em1a, em1b);
+    assertEquals("Expected only one creation", 1, useCount.get());
+    Skeleton.getSkeleton(cbk).assertSkeletonNotCalled();
+    
+    EntityManager em2a = contexts.getCurrentPersistenceContext(emf2, props1, useCount, cbk);
+    EntityManager em2b = contexts.getExistingPersistenceContext(emf2);
+    
+    Skeleton.getSkeleton(emf2).assertCalledExactNumberOfTimes(new MethodCall(EntityManagerFactory.class,
"createEntityManager", props1), 1);
+    Skeleton.getSkeleton(emf2).assertNotCalled(new MethodCall(EntityManagerFactory.class,
"createEntityManager"));
+    Skeleton.getSkeleton(em2a).assertNotCalled(new MethodCall(EntityManager.class, "close"));
+    assertSame("We should get the same delegate!", em2a, em2b);
+    assertEquals("Expected a second creation", 2, useCount.get());
+    Skeleton.getSkeleton(cbk).assertSkeletonNotCalled();
+    
+    reg.afterCompletion("");
+    
+    Skeleton.getSkeleton(em1a).assertCalledExactNumberOfTimes(new MethodCall(EntityManager.class,
"close"),1);
+    Skeleton.getSkeleton(em2a).assertCalledExactNumberOfTimes(new MethodCall(EntityManager.class,
"close"),1);
+    assertEquals("Expected creations to be uncounted", 0, useCount.get());
+    Skeleton.getSkeleton(cbk).assertCalledExactNumberOfTimes(new MethodCall(DestroyCallback.class,
+        "callback"), 2);
+  }
+  
+  @Test
+  public void testManageExisting()
+  {
+    reg.setTransactionKey("");
+    
+    assertNull(contexts.getExistingPersistenceContext(emf1));
+    assertNull(contexts.getExistingPersistenceContext(emf2));
+    
+    EntityManager em1a = emf1.createEntityManager(props1);
+    contexts.manageExistingPersistenceContext(emf1, em1a);
+    
+    Skeleton.getSkeleton(em1a).assertCalledExactNumberOfTimes(new MethodCall(EntityManager.class,
"joinTransaction"), 1);
+    
+    EntityManager em1b = contexts.getExistingPersistenceContext(emf1);
+    
+    Skeleton.getSkeleton(emf1).assertCalledExactNumberOfTimes(new MethodCall(EntityManagerFactory.class,
"createEntityManager", props1), 1);
+    Skeleton.getSkeleton(emf1).assertNotCalled(new MethodCall(EntityManagerFactory.class,
"createEntityManager"));
+    Skeleton.getSkeleton(em1a).assertNotCalled(new MethodCall(EntityManager.class, "close"));
+    assertSame("We should get the same delegate!", em1a, em1b);
+    
+    EntityManager em2a = emf2.createEntityManager(props1);
+    contexts.manageExistingPersistenceContext(emf2, em2a);
+    
+    Skeleton.getSkeleton(em2a).assertCalledExactNumberOfTimes(new MethodCall(EntityManager.class,
"joinTransaction"), 1);
+    
+    EntityManager em2b = contexts.getExistingPersistenceContext(emf2);
+    
+    Skeleton.getSkeleton(emf2).assertCalledExactNumberOfTimes(new MethodCall(EntityManagerFactory.class,
"createEntityManager", props1), 1);
+    Skeleton.getSkeleton(emf2).assertNotCalled(new MethodCall(EntityManagerFactory.class,
"createEntityManager"));
+    Skeleton.getSkeleton(em2a).assertNotCalled(new MethodCall(EntityManager.class, "close"));
+    assertSame("We should get the same delegate!", em2a, em2b);
+    
+    reg.afterCompletion("");
+    
+    Skeleton.getSkeleton(em1a).assertNotCalled(new MethodCall(EntityManager.class, "close"));
+    Skeleton.getSkeleton(em2a).assertNotCalled(new MethodCall(EntityManager.class, "close"));
+  }
+  
 }

Modified: aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/context/transaction/impl/TranSyncRegistryMock.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/context/transaction/impl/TranSyncRegistryMock.java?rev=1166169&r1=1166168&r2=1166169&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/context/transaction/impl/TranSyncRegistryMock.java
(original)
+++ aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/context/transaction/impl/TranSyncRegistryMock.java
Wed Sep  7 13:29:15 2011
@@ -72,9 +72,10 @@ public class TranSyncRegistryMock
   
   public void afterCompletion(String s)
   {
-    for(Synchronization sync : syncs.get(s))
-      sync.afterCompletion(Status.STATUS_COMMITTED);
-    
+    if(syncs.get(s) != null) {
+      for(Synchronization sync : syncs.remove(s))
+        sync.afterCompletion(Status.STATUS_COMMITTED);
+    }
     resources.remove(s);
   }
 }
\ No newline at end of file



Mime
View raw message