/******************************************************************************* * 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.api.request.misc; import java.util.HashSet; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import org.junit.Test; import org.simantics.db.ReadGraph; import org.simantics.db.Session; import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.SyncListener; import org.simantics.db.request.Read; import org.simantics.db.testing.base.TestCommonPerf; import org.simantics.layer0.Layer0; public class SyncRequestTest3 extends TestCommonPerf { private static final int COUNT = 10000; private static final int DEADLINE = 1000; @Test public void test() throws Exception { final Session session = getSession(); final HashSet check = new HashSet(); for(int i=0;i() { @Override public String perform(ReadGraph graph) throws DatabaseException { Layer0 l0 = Layer0.getInstance(graph); return graph.getPossibleRelatedValue(rl, l0.HasName); } }, new SyncListener() { @Override public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException { throwable.printStackTrace(); } @Override public void execute(ReadGraph graph, String result) throws DatabaseException { synchronized(check) { check.remove(index); if(check.isEmpty()) s.release(); } } @Override public boolean isDisposed() { return false; } }); } boolean success = s.tryAcquire(DEADLINE, TimeUnit.MILLISECONDS); long end = System.nanoTime(); String t = "SyncRequestTest3 finished in " + 1e-9*(double)(end-start) + " s." + " Limit was < " + (double)DEADLINE / 1000.0 + " s."; System.out.println(t); if (!success) fail(t); } }