]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/CachedQueryTest.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / performance / read / CachedQueryTest.java
diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/CachedQueryTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/CachedQueryTest.java
new file mode 100644 (file)
index 0000000..7a7132a
--- /dev/null
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.tests.performance.read;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Session;
+import org.simantics.db.procedure.Procedure;
+import org.simantics.db.request.Read;
+import org.simantics.db.testing.base.TestCommonPerf;
+
+
+/**
+ * Tests for CachedQueryTest
+ * 
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ *
+ */
+public class CachedQueryTest extends TestCommonPerf {
+
+       final static int QUERIES = 5000;
+       final static double TIME = 1.0;
+       
+       int counter = 0;
+       
+       public void testTransactions() throws Exception {
+               
+               Session session = getSession();
+               
+               Read<Boolean> req = new Read<Boolean>() {
+
+                       @Override
+                       public Boolean perform(ReadGraph graph) {
+                               return true;
+                       }
+                       
+               };
+               
+               Procedure<Boolean> proc = new Procedure<Boolean>() {
+                       
+                       @Override
+                       public void execute(Boolean result) {
+                               synchronized(this) {
+                                       counter++;
+                               }
+                       }
+
+               public void exception(Throwable t) {
+               System.out.print("CachedQueryTest request failed: ");
+               t.printStackTrace();
+            }
+
+               };
+               
+               session.syncRequest(req, proc);
+
+               long start = System.nanoTime();
+
+               for(int i = 0; i < QUERIES ; i++) {
+                       session.syncRequest(req, proc);
+               }
+               
+               if(counter != (QUERIES + 1)) throw new Error("Invalid amount of notifications (got " + counter + ", expexted " + (QUERIES + 1) + ").");
+               
+               checkException();
+
+               long end = System.nanoTime();
+               
+               double time = (double)(end-start) * (double)(1e-9);
+               
+               String t = "CachedQueryTest finished with time " + time + ". Limit was < " + TIME;
+               System.out.println(t);
+               if (time > TIME)
+                       fail(t); 
+       }
+
+}