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.api.request.external;
14 import java.util.concurrent.Executors;
15 import java.util.concurrent.ScheduledExecutorService;
16 import java.util.concurrent.Semaphore;
17 import java.util.concurrent.TimeUnit;
19 import org.junit.Test;
20 import org.simantics.db.ReadGraph;
21 import org.simantics.db.Session;
22 import org.simantics.db.procedure.Listener;
23 import org.simantics.db.request.ExternalRead;
24 import org.simantics.db.testing.annotation.Fails;
25 import org.simantics.db.testing.base.ExistingDatabaseTest;
27 public class ExternalRequestTest extends ExistingDatabaseTest {
29 private Error exception;
34 public void test() throws Exception {
36 Session session = getSession();
38 final ScheduledExecutorService exec = Executors.newScheduledThreadPool(1);
40 final Semaphore s = new Semaphore(-9);
42 session.syncRequest(new ExternalRead<String>() {
45 public void register(ReadGraph graph, final Listener<String> procedure) {
47 procedure.execute("String" + (counter++));
49 for(int i=1;i<10;i++) {
50 exec.schedule(new Runnable() {
54 procedure.execute("String" + (counter++));
57 }, i*500, TimeUnit.MILLISECONDS);
63 public void unregistered() {
66 }, new Listener<String>() {
69 public void exception(Throwable t) {
73 public void execute(String result) {
78 public boolean isDisposed() {
86 if(exception != null) {
87 fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through ");