1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.tests.performance.read;
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Session;
16 import org.simantics.db.procedure.Procedure;
17 import org.simantics.db.request.Read;
18 import org.simantics.db.testing.base.TestCommonPerf;
22 * Tests for CachedQueryTest
24 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
27 public class CachedQueryTest extends TestCommonPerf {
29 final static int QUERIES = 5000;
30 final static double TIME = 1.0;
34 public void testTransactions() throws Exception {
36 Session session = getSession();
38 Read<Boolean> req = new Read<Boolean>() {
41 public Boolean perform(ReadGraph graph) {
47 Procedure<Boolean> proc = new Procedure<Boolean>() {
50 public void execute(Boolean result) {
56 public void exception(Throwable t) {
57 System.out.print("CachedQueryTest request failed: ");
63 session.syncRequest(req, proc);
65 long start = System.nanoTime();
67 for(int i = 0; i < QUERIES ; i++) {
68 session.syncRequest(req, proc);
71 if(counter != (QUERIES + 1)) throw new Error("Invalid amount of notifications (got " + counter + ", expexted " + (QUERIES + 1) + ").");
75 long end = System.nanoTime();
77 double time = (double)(end-start) * (double)(1e-9);
79 String t = "CachedQueryTest finished with time " + time + ". Limit was < " + TIME;
80 System.out.println(t);