Author: aadamchik
Date: Sat Oct 20 22:39:43 2012
New Revision: 1400527

URL: http://svn.apache.org/viewvc?rev=1400527&view=rev
Log:
allowing for slower hardware to finish the deadlock test

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

Modified: 
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContext_DeadlockTest.java
URL: 
http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContext_DeadlockTest.java?rev=1400527&r1=1400526&r2=1400527&view=diff
==============================================================================
--- 
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContext_DeadlockTest.java
 (original)
+++ 
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContext_DeadlockTest.java
 Sat Oct 20 22:39:43 2012
@@ -24,7 +24,7 @@ import java.util.Random;
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.query.EJBQLQuery;
+import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.test.parallel.ParallelTestContainer;
@@ -35,94 +35,94 @@ import org.apache.cayenne.unit.di.server
 @UseServerRuntime(ServerCase.TESTMAP_PROJECT)
 public class NestedDataContext_DeadlockTest extends ServerCase {
 
-       @Inject
-       private DataContext parent;
+    @Inject
+    private DataContext parent;
 
-       @Inject
-       private ServerRuntime runtime;
+    @Inject
+    private ServerRuntime runtime;
 
-       @Inject
-       protected DBHelper dbHelper;
+    @Inject
+    protected DBHelper dbHelper;
 
-       protected TableHelper tArtist;
-
-       @Override
-       protected void setUpAfterInjection() throws Exception {
-               dbHelper.deleteAll("PAINTING_INFO");
-               dbHelper.deleteAll("PAINTING");
-               dbHelper.deleteAll("ARTIST_EXHIBIT");
-               dbHelper.deleteAll("ARTIST_GROUP");
-               dbHelper.deleteAll("ARTIST");
-
-               tArtist = new TableHelper(dbHelper, "ARTIST");
-               tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
-       }
-
-       private void createArtists() throws Exception {
-               for (int i = 0; i < 300; i++) {
-                       tArtist.insert(i + 1, "X" + i);
-               }
-       }
-
-       public void testDeadlock() throws Exception {
-
-               createArtists();
-
-               final Thread[] threads = new Thread[2];
-
-               Random rnd = new Random(System.currentTimeMillis());
-               for (int i = 0; i < threads.length; i++) {
-                       threads[i] = new UpdateThread("UpdateThread-" + i,
-                                       runtime.getContext(parent), rnd);
-               }
-
-               for (int i = 0; i < threads.length; i++) {
-                       threads[i].start();
-               }
-
-               new ParallelTestContainer() {
-
-                       @Override
-                       protected void assertResult() throws Exception {
-                               for (int i = 0; i < threads.length; i++) {
-                                       // unfortunately here we'll have to 
leave some dead threads
-                                       // behind... Of course if there's no 
deadlock, there won't
-                                       // be a leak either
-                                       assertTrue("Deadlocked thread", 
!threads[i].isAlive());
-                               }
-                       }
-               }.runTest(2000);
-
-       }
-
-       static class UpdateThread extends Thread {
-
-               protected ObjectContext nestedContext;
-               protected Random rnd;
-
-               UpdateThread(String name, ObjectContext nestedContext, Random 
rnd) {
-                       super(name);
-                       setDaemon(true);
-                       this.nestedContext = nestedContext;
-                       this.rnd = rnd;
-               }
-
-               @Override
-               public void run() {
-
-                       List<Artist> artists = nestedContext.performQuery(new 
EJBQLQuery(
-                                       "select a FROM Artist a"));
-
-                       for (int i = 0; i < 100; i++) {
-
-                               for (int j = 0; j < 5; j++) {
-                                       int index = rnd.nextInt(artists.size());
-                                       Artist a = artists.get(index);
-                                       a.setArtistName("Y" + rnd.nextInt());
-                               }
-
-                               nestedContext.commitChanges();
-                       }
-               }
-       }
+    protected TableHelper tArtist;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST_GROUP");
+        dbHelper.deleteAll("ARTIST");
+
+        tArtist = new TableHelper(dbHelper, "ARTIST");
+        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+    }
+
+    private void createArtists() throws Exception {
+        for (int i = 0; i < 300; i++) {
+            tArtist.insert(i + 1, "X" + i);
+        }
+    }
+
+    public void testDeadlock() throws Exception {
+
+        createArtists();
+
+        final Thread[] threads = new Thread[2];
+
+        Random rnd = new Random(System.currentTimeMillis());
+        for (int i = 0; i < threads.length; i++) {
+            threads[i] = new UpdateThread("UpdateThread-" + i,
+                    runtime.getContext(parent), rnd);
+        }
+
+        for (int i = 0; i < threads.length; i++) {
+            threads[i].start();
+        }
+
+        new ParallelTestContainer() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                for (int i = 0; i < threads.length; i++) {
+                    // unfortunately here we'll have to leave some dead threads
+                    // behind... Of course if there's no deadlock, there won't
+                    // be a leak either
+                    assertFalse("Deadlocked thread", threads[i].isAlive());
+                }
+            }
+        }.runTest(10000);
+
+    }
+
+    static class UpdateThread extends Thread {
+
+        protected ObjectContext nestedContext;
+        protected Random rnd;
+
+        UpdateThread(String name, ObjectContext nestedContext, Random rnd) {
+            super(name);
+            setDaemon(true);
+            this.nestedContext = nestedContext;
+            this.rnd = rnd;
+        }
+
+        @Override
+        public void run() {
+
+            List<Artist> artists = nestedContext.performQuery(new SelectQuery(
+                    Artist.class));
+
+            for (int i = 0; i < 100; i++) {
+
+                for (int j = 0; j < 5; j++) {
+                    int index = rnd.nextInt(artists.size());
+                    Artist a = artists.get(index);
+                    a.setArtistName("Y" + rnd.nextInt());
+                }
+
+                nestedContext.commitChanges();
+            }
+        }
+    }
 }


Reply via email to