/******************************************************************************* * 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 * */ 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 req = new Read() { @Override public Boolean perform(ReadGraph graph) { return true; } }; Procedure proc = new Procedure() { @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); } }