cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1384172 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java
Date Thu, 13 Sep 2012 00:54:28 GMT
Author: aadamchik
Date: Thu Sep 13 00:54:27 2012
New Revision: 1384172

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

adding delays to mt unit tests - doing it the right way

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java?rev=1384172&r1=1384171&r2=1384172&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextPeerEventsTest.java
Thu Sep 13 00:54:27 2012
@@ -27,6 +27,7 @@ import org.apache.cayenne.testdo.testmap
 import org.apache.cayenne.testdo.testmap.Painting;
 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 NestedDataContextPeerEventsTest extends ServerCase {
@@ -40,25 +41,29 @@ public class NestedDataContextPeerEvents
     public void testPeerObjectUpdatedTempOID() throws Exception {
 
         ObjectContext peer1 = runtime.getContext(context);
-        Artist a1 = peer1.newObject(Artist.class);
+        final Artist a1 = peer1.newObject(Artist.class);
         a1.setArtistName("Y");
 
         ObjectId a1TempId = a1.getObjectId();
         assertTrue(a1TempId.isTemporary());
 
         ObjectContext peer2 = runtime.getContext(context);
-        Artist a2 = peer2.localObject(a1);
+        final Artist a2 = peer2.localObject(a1);
 
         assertEquals(a1TempId, a2.getObjectId());
 
         peer1.commitChanges();
 
         // pause to let the context events propagate
-        Thread.sleep(500);
+        new ThreadedTestHelper() {
 
-        assertFalse(a1.getObjectId().isTemporary());
-        assertFalse(a2.getObjectId().isTemporary());
-        assertEquals(a2.getObjectId(), a1.getObjectId());
+            @Override
+            protected void assertResult() throws Exception {
+                assertFalse(a1.getObjectId().isTemporary());
+                assertFalse(a2.getObjectId().isTemporary());
+                assertEquals(a2.getObjectId(), a1.getObjectId());
+            }
+        }.assertWithTimeout(1000);
     }
 
     public void testPeerObjectUpdatedSimpleProperty() throws Exception {
@@ -69,20 +74,25 @@ public class NestedDataContextPeerEvents
         ObjectContext peer1 = runtime.getContext(context);
         Artist a1 = peer1.localObject(a);
 
-        ObjectContext peer2 = runtime.getContext(context);
-        Artist a2 = peer2.localObject(a);
+        final ObjectContext peer2 = runtime.getContext(context);
+        final Artist a2 = peer2.localObject(a);
 
         a1.setArtistName("Y");
         assertEquals("X", a2.getArtistName());
         peer1.commitChangesToParent();
 
         // pause to let the context events propagate
-        Thread.sleep(500);
-        assertEquals("Y", a2.getArtistName());
+        new ThreadedTestHelper() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                assertEquals("Y", a2.getArtistName());
+                assertFalse(
+                        "Peer data context became dirty on event processing",
+                        peer2.hasChanges());
+            }
+        }.assertWithTimeout(1000);
 
-        assertFalse(
-                "Peer data context became dirty on event processing",
-                peer2.hasChanges());
     }
 
     public void testPeerObjectUpdatedToOneRelationship() throws Exception {
@@ -101,22 +111,28 @@ public class NestedDataContextPeerEvents
         Painting p1 = peer1.localObject(p);
         Artist altA1 = peer1.localObject(altA);
 
-        ObjectContext peer2 = runtime.getContext(context);
-        Painting p2 = peer2.localObject(p);
-        Artist altA2 = peer2.localObject(altA);
+        final ObjectContext peer2 = runtime.getContext(context);
+        final Painting p2 = peer2.localObject(p);
+        final Artist altA2 = peer2.localObject(altA);
         Artist a2 = peer2.localObject(a);
 
         p1.setToArtist(altA1);
         assertSame(a2, p2.getToArtist());
         peer1.commitChangesToParent();
+
         // pause to let the context events propagate
-        Thread.sleep(500);
+        new ThreadedTestHelper() {
 
-        assertEquals(altA2, p2.getToArtist());
+            @Override
+            protected void assertResult() throws Exception {
+                assertEquals(altA2, p2.getToArtist());
+
+                assertFalse(
+                        "Peer data context became dirty on event processing",
+                        peer2.hasChanges());
+            }
+        }.assertWithTimeout(1000);
 
-        assertFalse(
-                "Peer data context became dirty on event processing",
-                peer2.hasChanges());
     }
 
     public void testPeerObjectUpdatedToManyRelationship() throws Exception {
@@ -139,22 +155,27 @@ public class NestedDataContextPeerEvents
         Painting py1 = peer1.localObject(py);
         Artist a1 = peer1.localObject(a);
 
-        ObjectContext peer2 = runtime.getContext(context);
-        Painting py2 = peer2.localObject(py);
-        Artist a2 = peer2.localObject(a);
+        final ObjectContext peer2 = runtime.getContext(context);
+        final Painting py2 = peer2.localObject(py);
+        final Artist a2 = peer2.localObject(a);
 
         a1.addToPaintingArray(py1);
         assertEquals(1, a2.getPaintingArray().size());
         assertFalse(a2.getPaintingArray().contains(py2));
         peer1.commitChangesToParent();
         // pause to let the context events propagate
-        Thread.sleep(500);
+        new ThreadedTestHelper() {
 
-        assertEquals(2, a2.getPaintingArray().size());
-        assertTrue(a2.getPaintingArray().contains(py2));
+            @Override
+            protected void assertResult() throws Exception {
+                assertEquals(2, a2.getPaintingArray().size());
+                assertTrue(a2.getPaintingArray().contains(py2));
+
+                assertFalse(
+                        "Peer data context became dirty on event processing",
+                        peer2.hasChanges());
+            }
+        }.assertWithTimeout(1000);
 
-        assertFalse(
-                "Peer data context became dirty on event processing",
-                peer2.hasChanges());
     }
 }



Mime
View raw message