]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest5.java
Multiple reader thread support for db client
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / request / misc / SyncAsyncSyncTest5.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.misc;
13
14 import java.util.ArrayList;
15 import java.util.concurrent.ConcurrentSkipListSet;
16
17 import org.junit.Test;
18 import org.simantics.db.AsyncReadGraph;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.Session;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.db.procedure.SyncSetListener;
24 import org.simantics.db.testing.base.ExistingDatabaseTest;
25 import org.simantics.layer0.Layer0;
26
27 public class SyncAsyncSyncTest5 extends ExistingDatabaseTest {
28         
29         @Test
30         public void test() throws Exception {
31                 
32                 Session session = getSession();
33                 
34                 final ConcurrentSkipListSet<String> names = new ConcurrentSkipListSet<String>();
35                 final ArrayList<Resource> resources = new ArrayList<Resource>();
36                 final Resource root = SyncAsyncSyncUtils.createNames(session, names, resources);
37
38         session.syncRequest(new TestAsyncReadRequest() {
39
40             @Override
41             public void run(AsyncReadGraph graph) {
42                 
43                 Layer0 b = Layer0.getInstance(graph);
44                 graph.forObjectSet(root, b.ConsistsOf, new SyncSetListener<Resource>() {
45                     
46                     @Override
47                     public void add(ReadGraph graph, final Resource resource) throws DatabaseException {
48
49                         graph.syncRequest(new TestAsyncReadRequest() {
50
51                             @Override
52                             public void run(AsyncReadGraph graph) throws DatabaseException {
53                                 Layer0 b = Layer0.getInstance(graph);
54                                 graph.forObjectSet(resource, b.HasName, new SyncSetListener<Resource>() {
55                                     
56                                     @Override
57                                     public void add(ReadGraph graph, final Resource resource) throws DatabaseException {
58
59                                         names.remove(graph.getPossibleValue(resource));
60
61                                     }
62
63                                     @Override
64                                     public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException {
65                                     }
66
67                                     @Override
68                                     public void remove(ReadGraph graph, Resource result) throws DatabaseException {
69                                     }
70
71                                     @Override
72                                     public boolean isDisposed() {
73                                         return false;
74                                     }
75                                     
76                                     @Override
77                                     public String toString() {
78                                         return "Inner procedure for " + resource.getResourceId();
79                                     }
80                                     
81                                 });
82
83                                 
84                             }
85                             
86                             @Override
87                             public String toString() {
88                                 return "Inner request for " + resource.getResourceId();
89                             }
90                             
91                         });
92                         
93                         
94                         
95                     }
96
97                     @Override
98                     public void remove(ReadGraph graph, Resource result) throws DatabaseException {
99                     }
100
101                     @Override
102                     public void exception(ReadGraph graph, Throwable t) {
103                     }
104
105                     @Override
106                     public boolean isDisposed() {
107                         return false;
108                     }
109                     
110                     @Override
111                     public String toString() {
112                         return "Outer procedure for RootLibrary";
113                     }
114                     
115                 });
116                 
117             }
118             
119         });
120                 
121                 assert(names.isEmpty());
122                 
123         }
124
125 }