/******************************************************************************* * 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.AsyncReadGraph; import org.simantics.db.ReadGraph; import org.simantics.db.Session; import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.AsyncProcedure; import org.simantics.db.procedure.SyncProcedure; import org.simantics.db.request.AsyncRead; import org.simantics.db.testing.annotation.Fails; import org.simantics.db.testing.base.TestCommonPerf; import org.simantics.layer0.Layer0; public class SyncRequestTest extends TestCommonPerf { private static final int COUNT = 1000000; private static final int DEADLINE = 10000; @Test(timeout=5000) @Fails public void test() throws Exception { final Session session = getSession(); final Layer0 b = Layer0.getInstance(session); final HashSet check = new HashSet(); for(int i=0;i() { @Override public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { for(int i=0;i() { @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 int threadHash() { return hashCode(); } @Override public int getFlags() { return 0; } }); boolean success = s.tryAcquire(DEADLINE, TimeUnit.MILLISECONDS); assert(success); long end = System.nanoTime(); if (DEBUG) System.out.println("success in " + 1e-9*(double)(end-start) + " s."); } }