You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2012/09/11 03:23:19 UTC

svn commit: r1383205 - in /cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne: ./ access/

Author: aadamchik
Date: Tue Sep 11 01:23:19 2012
New Revision: 1383205

URL: http://svn.apache.org/viewvc?rev=1383205&view=rev
Log:
CAY-1737 ObjectContexts listening to DataChannel events must be non-blocking

adding delays to mt unit tests

Modified:
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextClientChannelEventsTest.java
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextParentEventsTest.java
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java

Modified: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextClientChannelEventsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextClientChannelEventsTest.java?rev=1383205&r1=1383204&r2=1383205&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextClientChannelEventsTest.java (original)
+++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextClientChannelEventsTest.java Tue Sep 11 01:23:19 2012
@@ -176,6 +176,9 @@ public class CayenneContextClientChannel
 
         o1.setGlobalAttribute1("X");
         c1.commitChanges();
+        
+        // let the events propagate to peers
+        Thread.sleep(500);
 
         assertEquals("X", o2.getGlobalAttribute1());
         assertFalse(c1.internalGraphManager().hasChanges());
@@ -207,6 +210,9 @@ public class CayenneContextClientChannel
                 new ObjectIdQuery(new ObjectId("MtTable1", "TABLE1_ID", 2)));
         o1.setTable1(o1r);
         c1.commitChanges();
+        
+        // let the events propagate to peers
+        Thread.sleep(500);
 
         assertEquals("g2", o2.getTable1().getGlobalAttribute1());
         assertEquals(o1r.getObjectId(), o2.getTable1().getObjectId());
@@ -237,6 +243,9 @@ public class CayenneContextClientChannel
         o1.addToTable2Array(o1r);
 
         c1.commitChanges();
+        
+        // let the events propagate to peers
+        Thread.sleep(500);
 
         assertEquals(2, o1.getTable2Array().size());
         assertEquals(2, o2.getTable2Array().size());
@@ -304,6 +313,8 @@ public class CayenneContextClientChannel
         o1.removeFromTable5s(o1r);
 
         c1.commitChanges();
+        // let the events propagate to peers
+        Thread.sleep(500);
 
         assertEquals(1, o1.getTable5s().size());
         assertEquals(1, o2.getTable5s().size());

Modified: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java?rev=1383205&r1=1383204&r2=1383205&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java (original)
+++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java Tue Sep 11 01:23:19 2012
@@ -46,44 +46,57 @@ public class DataContextDataChannelEvent
     @Inject
     private ServerRuntime runtime;
 
-    public void testCommitEvent() {
+    public void testCommitEvent() throws Exception {
         Artist a = context.newObject(Artist.class);
         a.setArtistName("X");
         context.commitChanges();
 
-        MockChannelListener listener = new MockChannelListener();
+        final MockChannelListener listener = new MockChannelListener();
         EventUtil.listenForChannelEvents(context, listener);
 
         a.setArtistName("Y");
         context.commitChanges();
 
-        assertTrue(listener.graphCommitted);
-        assertFalse(listener.graphChanged);
-        assertFalse(listener.graphRolledBack);
+        new ThreadedTestHelper() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                assertTrue(listener.graphCommitted);
+                assertFalse(listener.graphChanged);
+                assertFalse(listener.graphRolledBack);
+            }
+        }.assertWithTimeout(1000);
+
     }
 
-    public void testRollbackEvent() {
+    public void testRollbackEvent() throws Exception {
         Artist a = context.newObject(Artist.class);
         a.setArtistName("X");
         context.commitChanges();
 
-        MockChannelListener listener = new MockChannelListener();
+        final MockChannelListener listener = new MockChannelListener();
         EventUtil.listenForChannelEvents(context, listener);
 
         a.setArtistName("Y");
         context.rollbackChanges();
 
-        assertFalse(listener.graphCommitted);
-        assertFalse(listener.graphChanged);
-        assertTrue(listener.graphRolledBack);
+        new ThreadedTestHelper() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                assertFalse(listener.graphCommitted);
+                assertFalse(listener.graphChanged);
+                assertTrue(listener.graphRolledBack);
+            }
+        }.assertWithTimeout(1000);
     }
 
-    public void testChangeEventOnChildChange() {
+    public void testChangeEventOnChildChange() throws Exception {
         Artist a = context.newObject(Artist.class);
         a.setArtistName("X");
         context.commitChanges();
 
-        MockChannelListener listener = new MockChannelListener();
+        final MockChannelListener listener = new MockChannelListener();
         EventUtil.listenForChannelEvents(context, listener);
 
         ObjectContext childContext = runtime.getContext(context);
@@ -93,9 +106,15 @@ public class DataContextDataChannelEvent
         a1.setArtistName("Y");
         childContext.commitChangesToParent();
 
-        assertFalse(listener.graphCommitted);
-        assertTrue(listener.graphChanged);
-        assertFalse(listener.graphRolledBack);
+        new ThreadedTestHelper() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                assertFalse(listener.graphCommitted);
+                assertTrue(listener.graphChanged);
+                assertFalse(listener.graphRolledBack);
+            }
+        }.assertWithTimeout(1000);
     }
 
     public void testChangeEventOnPeerChange() throws Exception {

Modified: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextParentEventsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextParentEventsTest.java?rev=1383205&r1=1383204&r2=1383205&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextParentEventsTest.java (original)
+++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextParentEventsTest.java Tue Sep 11 01:23:19 2012
@@ -20,31 +20,42 @@
 package org.apache.cayenne.access;
 
 import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.apache.cayenne.unit.util.ThreadedTestHelper;
 
 @UseServerRuntime(ServerCase.TESTMAP_PROJECT)
 public class NestedDataContextParentEventsTest extends ServerCase {
 
     @Inject
+    protected ServerRuntime runtime;
+
+    @Inject
     private DataContext context;
 
-    public void testParentUpdatedId() {
-        ObjectContext child1 = context.createChildContext();
+    public void testParentUpdatedId() throws Exception {
+        ObjectContext child1 = runtime.getContext(context);
 
-        Artist ac = child1.newObject(Artist.class);
+        final Artist ac = child1.newObject(Artist.class);
         ac.setArtistName("X");
         child1.commitChangesToParent();
 
-        Artist ap = (Artist) context.getGraphManager().getNode(ac.getObjectId());
+        final Artist ap = (Artist) context.getGraphManager().getNode(ac.getObjectId());
         assertNotNull(ap);
 
         assertTrue(ap.getObjectId().isTemporary());
         context.commitChanges();
 
-        assertFalse(ap.getObjectId().isTemporary());
-        assertEquals(ap.getObjectId(), ac.getObjectId());
+        new ThreadedTestHelper() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                assertFalse(ap.getObjectId().isTemporary());
+                assertEquals(ap.getObjectId(), ac.getObjectId());
+            }
+        }.assertWithTimeout(1000);
     }
 }

Modified: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java?rev=1383205&r1=1383204&r2=1383205&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java (original)
+++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java Tue Sep 11 01:23:19 2012
@@ -37,7 +37,7 @@ public class NestedDataContextPeerEvents
     @Inject
     private ServerRuntime runtime;
 
-    public void testPeerObjectUpdatedTempOID() {
+    public void testPeerObjectUpdatedTempOID() throws Exception {
 
         ObjectContext peer1 = runtime.getContext(context);
         Artist a1 = peer1.newObject(Artist.class);
@@ -52,12 +52,16 @@ public class NestedDataContextPeerEvents
         assertEquals(a1TempId, a2.getObjectId());
 
         peer1.commitChanges();
+
+        // pause to let the context events propagate
+        Thread.sleep(500);
+
         assertFalse(a1.getObjectId().isTemporary());
         assertFalse(a2.getObjectId().isTemporary());
         assertEquals(a2.getObjectId(), a1.getObjectId());
     }
 
-    public void testPeerObjectUpdatedSimpleProperty() {
+    public void testPeerObjectUpdatedSimpleProperty() throws Exception {
         Artist a = context.newObject(Artist.class);
         a.setArtistName("X");
         context.commitChanges();
@@ -71,6 +75,9 @@ public class NestedDataContextPeerEvents
         a1.setArtistName("Y");
         assertEquals("X", a2.getArtistName());
         peer1.commitChangesToParent();
+
+        // pause to let the context events propagate
+        Thread.sleep(500);
         assertEquals("Y", a2.getArtistName());
 
         assertFalse(
@@ -78,7 +85,7 @@ public class NestedDataContextPeerEvents
                 peer2.hasChanges());
     }
 
-    public void testPeerObjectUpdatedToOneRelationship() {
+    public void testPeerObjectUpdatedToOneRelationship() throws Exception {
 
         Artist a = context.newObject(Artist.class);
         Artist altA = context.newObject(Artist.class);
@@ -102,6 +109,9 @@ public class NestedDataContextPeerEvents
         p1.setToArtist(altA1);
         assertSame(a2, p2.getToArtist());
         peer1.commitChangesToParent();
+        // pause to let the context events propagate
+        Thread.sleep(500);
+
         assertEquals(altA2, p2.getToArtist());
 
         assertFalse(
@@ -109,7 +119,7 @@ public class NestedDataContextPeerEvents
                 peer2.hasChanges());
     }
 
-    public void testPeerObjectUpdatedToManyRelationship() {
+    public void testPeerObjectUpdatedToManyRelationship() throws Exception {
 
         Artist a = context.newObject(Artist.class);
         a.setArtistName("X");
@@ -122,6 +132,8 @@ public class NestedDataContextPeerEvents
         py.setPaintingTitle("PY");
 
         context.commitChanges();
+        // pause to let the context events propagate
+        Thread.sleep(500);
 
         ObjectContext peer1 = runtime.getContext(context);
         Painting py1 = peer1.localObject(py);
@@ -135,6 +147,9 @@ public class NestedDataContextPeerEvents
         assertEquals(1, a2.getPaintingArray().size());
         assertFalse(a2.getPaintingArray().contains(py2));
         peer1.commitChangesToParent();
+        // pause to let the context events propagate
+        Thread.sleep(500);
+
         assertEquals(2, a2.getPaintingArray().size());
         assertTrue(a2.getPaintingArray().contains(py2));