]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/external/ExternalRequestTest2.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 / ExternalRequestTest2.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.procedure.Listener;
20 import org.simantics.db.request.ExternalRead;
21 import org.simantics.db.testing.annotation.Fails;
22 import org.simantics.db.testing.base.ExistingDatabaseTest;
23
24 public class ExternalRequestTest2 extends ExistingDatabaseTest {
25         
26     int COUNT = 50;
27     
28         private Error exception;
29         
30         int counter = 0;
31         
32         @Test
33         @Fails
34         public void test() throws Exception {
35                 
36                 Session session = getSession();
37                 
38                 final Semaphore s = new Semaphore(1-COUNT);
39                 
40                 session.syncRequest(new ExternalRead<String>() {
41
42             @Override
43             public void register(ReadGraph graph, final Listener<String> procedure) {
44
45                 for(int i=0;i<COUNT;i++) {
46                         System.err.println("execute: " + "String" + counter);
47                         procedure.execute("String" + counter);
48                         counter++;
49                 }
50                 
51             }
52
53             @Override
54             public void unregistered() {
55                 System.err.println("unregistered");
56             }
57                         
58                 }, new Listener<String>() {
59
60             @Override
61             public void exception(Throwable t) {
62             }
63
64             @Override
65             public void execute(String result) {
66                 new Exception("execute2 " + result).printStackTrace();
67                 s.release();
68             }
69
70             @Override
71             public boolean isDisposed() {
72                 return false;
73             }
74                     
75                 });
76                 
77                 s.acquire();
78                 
79                 if(exception != null) {
80                         fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through ");
81                 }
82                 
83         }
84
85 }