1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.tests.api.request.misc;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.concurrent.ConcurrentSkipListSet;
18 import org.junit.Test;
19 import org.simantics.db.AsyncReadGraph;
20 import org.simantics.db.ReadGraph;
21 import org.simantics.db.Resource;
22 import org.simantics.db.Session;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.db.procedure.AsyncProcedure;
25 import org.simantics.db.procedure.Procedure;
26 import org.simantics.db.request.AsyncRead;
27 import org.simantics.db.request.Read;
28 import org.simantics.db.testing.base.ExistingDatabaseTest;
29 import org.simantics.layer0.Layer0;
31 public class SyncAsyncSyncTest extends ExistingDatabaseTest {
34 public void test() throws Exception {
36 Session session = getSession();
38 final ConcurrentSkipListSet<String> names = new ConcurrentSkipListSet<String>();
39 final ArrayList<Resource> resources = new ArrayList<Resource>();
40 final Resource root = SyncAsyncSyncUtils.createNames(session, names, resources);
42 session.syncRequest(new TestReadRequest() {
45 public void run(ReadGraph graph) throws Throwable {
47 final Layer0 b = Layer0.getInstance(graph);
48 Collection<Resource> rs = graph.getObjects(root, b.ConsistsOf);
49 for(final Resource r : rs) {
51 graph.asyncRequest(new AsyncRead<String>() {
54 public void perform(AsyncReadGraph graph, AsyncProcedure<String> procedure) {
56 graph.asyncRequest(new Read<String>() {
59 public String perform(ReadGraph graph) throws DatabaseException {
60 return graph.getRelatedValue(r, b.HasName);
68 public int threadHash() {
73 public int getFlags() {
77 }, new Procedure<String>() {
80 public void exception(Throwable t) {
85 public void execute(String result) {
97 assert(names.isEmpty());