]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest3.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 / misc / SyncAsyncSyncTest3.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.common.request.AsyncReadRequest;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.db.procedure.Procedure;
25 import org.simantics.db.request.Read;
26 import org.simantics.db.testing.base.ExistingDatabaseTest;
27 import org.simantics.layer0.Layer0;
28
29 public class SyncAsyncSyncTest3 extends ExistingDatabaseTest {
30         
31         @Test
32         public void test() throws Exception {
33                 
34                 Session session = getSession();
35                 
36                 final ConcurrentSkipListSet<String> names = new ConcurrentSkipListSet<String>();
37                 final ArrayList<Resource> resources = new ArrayList<Resource>();
38                 final Resource root = SyncAsyncSyncUtils.createNames(session, names, resources);
39                 if (DEBUG)
40                     System.out.println("Root resource is " + root);
41
42                 session.syncRequest(new AsyncReadRequest() {
43
44             @Override
45             public void run(AsyncReadGraph graph) {
46
47                 for(final Resource r : resources) {
48
49                     graph.asyncRequest(new Read<String>() {
50
51                         @Override
52                         public String perform(ReadGraph graph) throws DatabaseException {
53                             Layer0 b = Layer0.getInstance(graph);
54                             return graph.getRelatedValue(r, b.HasName);
55                         }
56
57                         @Override
58                         public String toString() {
59                             return "Read " + r.getResourceId();
60                         }
61
62                     }, new Procedure<String>() {
63
64                         @Override
65                         public void exception(Throwable t) {
66                             t.printStackTrace();
67                         }
68
69                         @Override
70                         public void execute(String result) {
71                             names.remove(result);
72                         }
73
74                     });
75
76                 }
77
78             }
79
80                 });
81                 
82                 assert(names.isEmpty());
83                 
84         }
85
86 }