]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/ExternalRequestTest3.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / request / external / ExternalRequestTest3.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.tests.api.request.external;
13
14 import java.util.concurrent.Semaphore;
15
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;
26
27 public class ExternalRequestTest3 extends ExistingDatabaseTest {
28         
29         private Error exception;
30         
31         @Test
32         @Fails
33         public void test() throws Exception {
34                 
35                 Session session = getSession();
36                 
37                 final Semaphore s = new Semaphore(-4);
38                 
39                 session.syncRequest(new Read<String>() {
40
41             @Override
42             public String perform(ReadGraph graph) throws DatabaseException {
43                 
44                 class Primitive extends SingletonPrimitiveRead<String> {
45
46                     @Override
47                     public void register(ReadGraph graph, Listener<String> procedure) {
48
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");
54                         
55                     }
56                     
57                 }
58                 
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;
63                 
64             }
65                         
66                 }, new Listener<String>() {
67
68             @Override
69             public void exception(Throwable t) {
70             }
71
72             @Override
73             public void execute(String result) {
74                 s.release();
75             }
76
77             @Override
78             public boolean isDisposed() {
79                 return false;
80             }
81                     
82                 });
83                 
84                 s.acquire();
85                 
86                 if(exception != null) {
87                         fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through ");
88                 }
89                 
90         }
91
92 }