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