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.Semaphore;
16 import org.junit.Test;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Session;
19 import org.simantics.db.common.request.SingletonPrimitiveRead;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.procedure.Listener;
22 import org.simantics.db.request.Read;
23 import org.simantics.db.testing.annotation.Fails;
24 import org.simantics.db.testing.base.ExistingDatabaseTest;
25 import org.simantics.layer0.Layer0;
27 public class ExternalRequestTest3 extends ExistingDatabaseTest {
29 private Error exception;
33 public void test() throws Exception {
35 Session session = getSession();
37 final Semaphore s = new Semaphore(-4);
39 session.syncRequest(new Read<String>() {
42 public String perform(ReadGraph graph) throws DatabaseException {
44 class Primitive extends SingletonPrimitiveRead<String> {
47 public void register(ReadGraph graph, Listener<String> procedure) {
49 procedure.execute(" Appendix 1");
50 procedure.execute(" Appendix 2");
51 procedure.execute(" Appendix 3");
52 procedure.execute(" Appendix 4");
53 procedure.execute(" Appendix 5");
59 Layer0 b = Layer0.getInstance(graph);
60 String base = graph.getRelatedValue(graph.getRootLibrary(), b.HasName);
61 String appendix = graph.syncRequest(new Primitive());
62 return base + appendix;
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 ");