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;
16 import org.junit.Test;
17 import org.simantics.db.AsyncReadGraph;
18 import org.simantics.db.Session;
19 import org.simantics.db.impl.query.CacheEntry;
20 import org.simantics.db.impl.service.QueryDebug;
21 import org.simantics.db.procedure.AsyncListener;
22 import org.simantics.db.procedure.AsyncProcedure;
23 import org.simantics.db.request.AsyncRead;
24 import org.simantics.db.testing.base.ExistingDatabaseTest;
26 public class RequestParentTest extends ExistingDatabaseTest {
29 public void test() throws Exception {
31 Session session = getSession();
33 QueryDebug debug = session.getService(QueryDebug.class);
35 class Request implements AsyncRead<Object> {
38 public void perform(AsyncReadGraph graph, AsyncProcedure<Object> procedure) {
39 procedure.execute(graph, new Object());
43 public int threadHash() {
48 public int getFlags() {
54 final Request request1 = new Request();
55 final Request request2 = new Request();
57 session.syncRequest(request1, new AsyncListener<Object>() {
60 public void exception(AsyncReadGraph graph, Throwable t) {
64 public void execute(AsyncReadGraph graph, Object result) {
65 graph.asyncRequest(request2);
69 public boolean isDisposed() {
75 Set<CacheEntry> parents = debug.getParents(request2);
76 for(CacheEntry parent : parents) {
77 if(parent.getOriginalRequest().equals(request1)) fail("Request1 should not be parent of Request2");
79 if(!parents.isEmpty())fail("Request2 should not have parents");