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.Collection;
15 import java.util.concurrent.atomic.AtomicInteger;
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.WriteGraph;
22 import org.simantics.db.common.request.ReadRequest;
23 import org.simantics.db.common.request.ResourceRead;
24 import org.simantics.db.common.request.WriteRequest;
25 import org.simantics.db.common.request.WriteResultRequest;
26 import org.simantics.db.exception.DatabaseException;
27 import org.simantics.db.procedure.SyncListener;
28 import org.simantics.db.testing.base.ExistingDatabaseTest;
29 import org.simantics.layer0.Layer0;
31 public class GraphSupportTest extends ExistingDatabaseTest {
34 public void test() throws Exception {
36 final AtomicInteger runs = new AtomicInteger(0);
38 Session session = getSession();
40 final Resource test = session.syncRequest(new WriteResultRequest<Resource>() {
42 public Resource perform(WriteGraph graph) throws DatabaseException {
43 return graph.newResource();
47 class Request extends ResourceRead<Collection<Resource>> {
49 public Request(Resource resource) {
54 public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
55 return graph.getObjects(resource, Layer0.getInstance(graph).ConsistsOf);
60 session.syncRequest(new ReadRequest() {
63 public void run(ReadGraph graph) throws DatabaseException {
65 graph.syncRequest(new Request(test), new SyncListener<Collection<Resource>>() {
68 public void execute(ReadGraph graph, Collection<Resource> result) throws DatabaseException {
70 graph.syncRequest(new ReadRequest() {
73 public void run(ReadGraph graph) throws DatabaseException {
74 runs.incrementAndGet();
81 public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException {
85 public boolean isDisposed() {
94 assert(runs.get() == 1);
96 session.syncRequest(new WriteRequest() {
98 public void perform(WriteGraph graph) throws DatabaseException {
99 graph.claim(test, Layer0.getInstance(graph).ConsistsOf, graph.newResource());
103 assert(runs.get() == 2);