cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1337864 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetchTest.java
Date Sun, 13 May 2012 12:59:43 GMT
Author: aadamchik
Date: Sun May 13 12:59:42 2012
New Revision: 1337864

URL: http://svn.apache.org/viewvc?rev=1337864&view=rev
Log:
ensure reproducible test results

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

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetchTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetchTest.java?rev=1337864&r1=1337863&r2=1337864&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetchTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetchTest.java
Sun May 13 12:59:42 2012
@@ -1,10 +1,17 @@
 package org.apache.cayenne.access;
 
+import static org.apache.cayenne.exp.ExpressionFactory.matchExp;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.ValueHolder;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.PrefetchTreeNode;
 import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.query.SortOrder;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Bag;
@@ -17,12 +24,6 @@ import org.apache.cayenne.unit.di.UnitTe
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.apache.cayenne.exp.ExpressionFactory.matchExp;
-
 @UseServerRuntime(ServerCase.TESTMAP_PROJECT)
 public class DataContextDisjointByIdPrefetchTest extends ServerCase {
 
@@ -186,14 +187,32 @@ public class DataContextDisjointByIdPref
         final SelectQuery query = new SelectQuery(Bag.class);
         query.addPrefetch(Bag.BOXES_PROPERTY).setSemantics(
                 PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
+        query.addOrdering("db:" + Bag.ID_PK_COLUMN, SortOrder.ASCENDING);
+
         query.setFetchLimit(2);
 
         // There will be only 2 bags in a result. The first bag has 5 boxes and
         // the second has 2. So we are expecting exactly 9 snapshots in the data
         // row store after performing the query.
-        context.performQuery(query);
+        final List<Bag> bags = context.performQuery(query);
+
+        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
 
-        assertEquals(9, context.getObjectStore().getDataRowCache().size());
+            public void execute() {
+
+                assertEquals(2, bags.size());
+
+                assertEquals(5, bags.get(0).getBoxes().size());
+                assertEquals(2, bags.get(1).getBoxes().size());
+
+                for (Bag b : bags) {
+                    b.getName();
+                    for (Box bx : b.getBoxes()) {
+                        bx.getName();
+                    }
+                }
+            }
+        });
     }
 
     public void testOneToOneRelationship() throws Exception {
@@ -209,7 +228,8 @@ public class DataContextDisjointByIdPref
                 assertFalse(result.isEmpty());
                 List<String> boxColors = new ArrayList<String>();
                 for (Box box : result) {
-                    BoxInfo info = (BoxInfo) box.readPropertyDirectly(Box.BOX_INFO_PROPERTY);
+                    BoxInfo info = (BoxInfo) box
+                            .readPropertyDirectly(Box.BOX_INFO_PROPERTY);
                     assertNotNull(info);
                     boxColors.add(info.getColor());
                     assertEquals(PersistenceState.COMMITTED, info.getPersistenceState());
@@ -232,7 +252,8 @@ public class DataContextDisjointByIdPref
             public void execute() {
                 assertFalse(result.isEmpty());
                 Bag b1 = result.get(0);
-                List<Ball> balls = (List<Ball>) b1.readPropertyDirectly(Bag.BALLS_PROPERTY);
+                List<Ball> balls = (List<Ball>) b1
+                        .readPropertyDirectly(Bag.BALLS_PROPERTY);
                 assertNotNull(balls);
                 assertFalse(((ValueHolder) balls).isFault());
                 assertEquals(6, balls.size());
@@ -251,8 +272,8 @@ public class DataContextDisjointByIdPref
         createBagWithTwoBoxesAndPlentyOfBallsDataSet();
 
         SelectQuery query = new SelectQuery(Bag.class);
-        query.addPrefetch(Bag.THINGS_PROPERTY)
-                .setSemantics(PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
+        query.addPrefetch(Bag.THINGS_PROPERTY).setSemantics(
+                PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
         final List<Bag> result = context.performQuery(query);
 
         queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
@@ -260,7 +281,8 @@ public class DataContextDisjointByIdPref
             public void execute() {
                 assertFalse(result.isEmpty());
                 Bag b1 = result.get(0);
-                List<Thing> things = (List<Thing>) b1.readPropertyDirectly(Bag.THINGS_PROPERTY);
+                List<Thing> things = (List<Thing>) b1
+                        .readPropertyDirectly(Bag.THINGS_PROPERTY);
                 assertNotNull(things);
                 assertFalse(((ValueHolder) things).isFault());
                 assertEquals(6, things.size());
@@ -283,11 +305,22 @@ public class DataContextDisjointByIdPref
                 matchExp(Ball.THING_WEIGHT_PROPERTY, 30)));
         query.orQualifier(matchExp(Ball.THING_VOLUME_PROPERTY, 20).andExp(
                 matchExp(Ball.THING_WEIGHT_PROPERTY, 10)));
+
         query.addPrefetch(Ball.THING_PROPERTY).setSemantics(
                 PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
-        context.performQuery(query);
 
-        assertEquals(4, context.getObjectStore().getDataRowCache().size());
+        final List<Ball> balls = context.performQuery(query);
+
+        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+
+                assertEquals(2, balls.size());
+
+              balls.get(0).getThing().getVolume();
+              balls.get(1).getThing().getVolume();
+            }
+        });
     }
 
     public void testFlattenedMultiColumnRelationship() throws Exception {
@@ -304,7 +337,8 @@ public class DataContextDisjointByIdPref
                 assertFalse(result.isEmpty());
                 List<Integer> volumes = new ArrayList<Integer>();
                 for (Box box : result) {
-                    List<Thing> things = (List<Thing>) box.readPropertyDirectly(Box.THINGS_PROPERTY);
+                    List<Thing> things = (List<Thing>) box
+                            .readPropertyDirectly(Box.THINGS_PROPERTY);
                     assertNotNull(things);
                     assertFalse(((ValueHolder) things).isFault());
                     for (Thing t : things) {
@@ -322,23 +356,29 @@ public class DataContextDisjointByIdPref
         createBagWithTwoBoxesAndPlentyOfBallsDataSet();
 
         SelectQuery query = new SelectQuery(Box.class);
-        query.addPrefetch(Box.BALLS_PROPERTY).setSemantics(PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS);
-        query.addPrefetch(Box.BALLS_PROPERTY + "." + Ball.THING_PROPERTY)
-                .setSemantics(PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
+        query.addPrefetch(Box.BALLS_PROPERTY).setSemantics(
+                PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS);
+        query.addPrefetch(Box.BALLS_PROPERTY + "." + Ball.THING_PROPERTY).setSemantics(
+                PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
         final List<Box> result = context.performQuery(query);
 
         queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
             public void execute() {
                 assertFalse(result.isEmpty());
                 List<Integer> volumes = new ArrayList<Integer>();
                 for (Box box : result) {
-                    List<Ball> balls = (List<Ball>) box.readPropertyDirectly(Box.BALLS_PROPERTY);
+                    List<Ball> balls = (List<Ball>) box
+                            .readPropertyDirectly(Box.BALLS_PROPERTY);
                     assertNotNull(balls);
                     assertFalse(((ValueHolder) balls).isFault());
                     for (Ball ball : balls) {
-                        Thing thing = (Thing) ball.readPropertyDirectly(Ball.THING_PROPERTY);
+                        Thing thing = (Thing) ball
+                                .readPropertyDirectly(Ball.THING_PROPERTY);
                         assertNotNull(thing);
-                        assertEquals(PersistenceState.COMMITTED, thing.getPersistenceState());
+                        assertEquals(
+                                PersistenceState.COMMITTED,
+                                thing.getPersistenceState());
                         volumes.add(thing.getVolume());
                     }
                 }
@@ -352,18 +392,20 @@ public class DataContextDisjointByIdPref
         createBagWithTwoBoxesAndPlentyOfBallsDataSet();
 
         SelectQuery query = new SelectQuery(Bag.class);
-        query.addPrefetch(Bag.BOXES_PROPERTY)
-                .setSemantics(PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
-        query.addPrefetch(Bag.BOXES_PROPERTY + "." + Box.BALLS_PROPERTY)
-                .setSemantics(PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS);
+        query.addPrefetch(Bag.BOXES_PROPERTY).setSemantics(
+                PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
+        query.addPrefetch(Bag.BOXES_PROPERTY + "." + Box.BALLS_PROPERTY).setSemantics(
+                PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS);
         final List<Bag> result = context.performQuery(query);
 
         queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
             public void execute() {
                 assertFalse(result.isEmpty());
 
                 Bag bag = result.get(0);
-                List<Box> boxes = (List<Box>) bag.readPropertyDirectly(Bag.BOXES_PROPERTY);
+                List<Box> boxes = (List<Box>) bag
+                        .readPropertyDirectly(Bag.BOXES_PROPERTY);
                 assertNotNull(boxes);
                 assertFalse(((ValueHolder) boxes).isFault());
                 assertEquals(2, boxes.size());
@@ -377,7 +419,8 @@ public class DataContextDisjointByIdPref
                 assertTrue(names.contains("small"));
 
                 Box box = boxes.get(0);
-                List<Ball> balls = (List<Ball>) box.readPropertyDirectly(Box.BALLS_PROPERTY);
+                List<Ball> balls = (List<Ball>) box
+                        .readPropertyDirectly(Box.BALLS_PROPERTY);
                 assertNotNull(balls);
                 assertFalse(((ValueHolder) balls).isFault());
                 assertEquals(2, balls.size());



Mime
View raw message