]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug1659Test1.java
Multiple reader thread support for db client
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / regression / bugs / SimanticsBug1659Test1.java
index 768ebf73a8256dbb5629bd0acc432a6139edfca8..1673c89f16f606335d211f39a2193811bd6290aa 100644 (file)
@@ -1,12 +1,13 @@
 package org.simantics.db.tests.regression.bugs;
 
 import org.junit.Test;
+import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.primitiverequest.PossibleObject;
-import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.common.request.AsyncReadRequest;
 import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.SyncListener;
@@ -103,51 +104,55 @@ public class SimanticsBug1659Test1 extends ExistingDatabaseTest {
             }
         }
     }
-    class Query extends ReadRequest {
+    class Query extends AsyncReadRequest {
         @Override
-        public void run(ReadGraph g) throws DatabaseException {
-            Layer0 l0 = Layer0.getInstance(g);
-            for (Resource r : g.getObjects(testRoot, l0.ConsistsOf)) {
-                if (DEBUG)
-                    System.out.println("Resource " + r);
-                for (Resource rr : g.getObjects(r, l0.ConsistsOf)) {
-//                    if (DEBUG)
-//                        System.out.println("Resource " + rr);
-                       if (!g.isInstanceOf(rr, type))
-                               fail("Resource " + rr + " is not instance of type.");
-                       if (!g.isInstanceOf(rr, l0.Entity))
-                               fail("Resource " + rr + " is not instance of Entity.");
-                       if (USE_LISTENER)
-                           g.forPossibleObject(rr, l0.InstanceOf, new SyncListener<Resource>() {
-       
-                               @Override
-                               public void execute(ReadGraph graph, Resource resource) throws DatabaseException {
-                                       if (DEBUG_LISTENER)
-                                               System.out.println("change " + resource);
-                               }
-       
-                                               @Override
-                                               public void exception(ReadGraph graph, Throwable t)
-                                                               throws DatabaseException {
-                                                       t.printStackTrace();
-                                       fail("Listener got exception: " + t);
-                                               }
-       
-                                               @Override
-                                               public boolean isDisposed() {
-                                                       if (DEBUG_LISTENER)
-                                                               System.out.println("Asked if disposed.");
-                                                       return true;
-                                               }
-                           });
-                    if (USE_LISTENER2) {
-                        g.forPossibleObject(rr, l0.InstanceOf, new Listener(loopCount, listenerCount));
-                    }
-                    if (USE_LISTENER3) {
-                       g.syncRequest(new PossibleObject(rr, l0.InstanceOf), new Listener(loopCount, listenerCount));
-                    }
-                }
-            }
+        public void run(AsyncReadGraph g) {
+               try {
+                       Layer0 l0 = Layer0.getInstance(g);
+                       for (Resource r : g.getObjects(testRoot, l0.ConsistsOf)) {
+                               if (DEBUG)
+                                       System.out.println("Resource " + r);
+                               for (Resource rr : g.getObjects(r, l0.ConsistsOf)) {
+                                       //                    if (DEBUG)
+                                       //                        System.out.println("Resource " + rr);
+                                       if (!g.isInstanceOf(rr, type))
+                                               fail("Resource " + rr + " is not instance of type.");
+                                       if (!g.isInstanceOf(rr, l0.Entity))
+                                               fail("Resource " + rr + " is not instance of Entity.");
+                                       if (USE_LISTENER)
+                                               g.forPossibleObject(rr, l0.InstanceOf, new SyncListener<Resource>() {
+
+                                                       @Override
+                                                       public void execute(ReadGraph graph, Resource resource) throws DatabaseException {
+                                                               if (DEBUG_LISTENER)
+                                                                       System.out.println("change " + resource);
+                                                       }
+
+                                                       @Override
+                                                       public void exception(ReadGraph graph, Throwable t)
+                                                                       throws DatabaseException {
+                                                               t.printStackTrace();
+                                                               fail("Listener got exception: " + t);
+                                                       }
+
+                                                       @Override
+                                                       public boolean isDisposed() {
+                                                               if (DEBUG_LISTENER)
+                                                                       System.out.println("Asked if disposed.");
+                                                               return true;
+                                                       }
+                                               });
+                                       if (USE_LISTENER2) {
+                                               g.forPossibleObject(rr, l0.InstanceOf, new Listener(loopCount, listenerCount));
+                                       }
+                                       if (USE_LISTENER3) {
+                                               g.syncRequest(new PossibleObject(rr, l0.InstanceOf), new Listener(loopCount, listenerCount));
+                                       }
+                               }
+                       }
+               } catch (DatabaseException e) {
+                       e.printStackTrace();
+               }
         }
     }
     class Listener implements SyncListener<Resource> {