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.Listener;
26 import org.simantics.db.procedure.Procedure;
27 import org.simantics.db.request.AsyncRead;
28 import org.simantics.db.request.Read;
29 import org.simantics.db.testing.base.ExistingDatabaseTest;
30 import org.simantics.layer0.Layer0;
32 public class SyncAsyncSyncTest2 extends ExistingDatabaseTest {
35 public void test() throws Exception {
37 Session session = getSession();
39 final ConcurrentSkipListSet<String> names = new ConcurrentSkipListSet<String>();
40 final ArrayList<Resource> resources = new ArrayList<Resource>();
41 final Resource root = SyncAsyncSyncUtils.createNames(session, names, resources);
43 session.syncRequest(new TestAsyncReadRequest() {
46 public void run(AsyncReadGraph graph) throws Throwable {
48 final Layer0 b = Layer0.getInstance(graph);
49 Collection<Resource> rs = graph.getObjects(root, b.ConsistsOf);
51 for(final Resource r : rs) {
53 final int i = index++;
55 graph.asyncRequest(new AsyncRead<String>() {
58 public void perform(AsyncReadGraph graph, AsyncProcedure<String> procedure) {
60 graph.asyncRequest(new Read<String>() {
63 public String perform(ReadGraph graph) throws DatabaseException {
64 return graph.getRelatedValue(r, b.HasName);
68 public String toString() {
77 public int threadHash() {
82 public int getFlags() {
86 }, new Procedure<String>() {
89 public void exception(Throwable t) {
94 public void execute(String result) {
104 }, new Listener<Object>() {
107 public void exception(Throwable t) {
112 public void execute(Object result) {
116 public boolean isDisposed() {
122 assert(names.isEmpty());