]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestBase.java
Multiple reader thread support for db client
[simantics/platform.git] / bundles / org.simantics.db.testing / src / org / simantics / db / testing / common / TestBase.java
index 574ab95f6ab7a09b876ba7098a5f4027f0a05156..1068fc2f50366ae19a72f8a3029534b86f2c7993 100644 (file)
@@ -20,6 +20,7 @@ import org.eclipse.core.runtime.Platform;
 import org.junit.After;
 import org.junit.Before;
 import org.simantics.SimanticsPlatform;
+import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
@@ -30,6 +31,8 @@ import org.simantics.db.common.utils.Logger;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.ServiceNotFoundException;
 import org.simantics.db.management.SessionContext;
+import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.db.request.AsyncRead;
 import org.simantics.db.request.Read;
 import org.simantics.db.service.LifecycleSupport;
 import org.simantics.db.testing.impl.Configuration;
@@ -145,9 +148,46 @@ abstract public class TestBase /*extends TestCase*/ {
 
     }
 
+    protected abstract class AsyncReadQuery<Result> implements AsyncRead<Result> {
+        protected Result result = null;
+
+        public abstract void run(AsyncReadGraph graph) throws Throwable;
+
+        @Override
+        public void perform(AsyncReadGraph graph, AsyncProcedure<Result> procedure) {
+            try {
+                run(graph);
+            } catch(Throwable t) {
+                if (DEBUG) {
+                    new Exception().printStackTrace();
+                    t.printStackTrace();
+                }
+                if (null == exception2)
+                    exception2 = t;
+            }
+        }
+
+    }
+
     protected abstract class TestReadRequest extends ReadQuery<Object> {
     }
 
+    protected abstract class TestAsyncReadRequest extends AsyncReadQuery<Object> {
+
+               @Override
+               public int getFlags() {
+                       // TODO Auto-generated method stub
+                       return 0;
+               }
+
+               @Override
+               public int threadHash() {
+                       // TODO Auto-generated method stub
+                       return 0;
+               }
+
+    }
+
     protected abstract class WriteOnlyQuery
     extends WriteOnlyRequest
     {