]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest2.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 / RequestParentTest2.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.Set;
15
16 import org.junit.Test;
17 import org.simantics.db.AsyncReadGraph;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Session;
20 import org.simantics.db.impl.query.CacheEntry;
21 import org.simantics.db.impl.service.QueryDebug;
22 import org.simantics.db.procedure.AsyncListener;
23 import org.simantics.db.request.Read;
24 import org.simantics.db.testing.base.ExistingDatabaseTest;
25
26 public class RequestParentTest2 extends ExistingDatabaseTest {
27         
28         @Test
29         public void test() throws Exception {
30                 
31                 Session session = getSession();
32                 
33                 QueryDebug debug = session.getService(QueryDebug.class);
34                 
35         class Request implements Read<Object> {
36
37             @Override
38             public Object perform(ReadGraph graph) {
39                 return new Object();
40             }
41             
42         }
43                 
44         final Request request1 = new Request();
45         final Request request2 = new Request();
46         
47         session.syncRequest(request1, new AsyncListener<Object>() {
48
49             @Override
50             public void exception(AsyncReadGraph graph, Throwable t) {
51             }
52
53             @Override
54             public void execute(AsyncReadGraph graph, Object result) {
55                 graph.asyncRequest(request2);
56             }
57
58             @Override
59             public boolean isDisposed() {
60                 return false;
61             }
62
63         });
64                 
65                 Set<CacheEntry> parents1 = debug.getParents(request1);
66                 Set<CacheEntry> parents2 = debug.getParents(request2);
67 //              for(CacheEntry parent : parents) {
68 //                  if(parent.getOriginalRequest().equals(request1)) fail("Request1 should not be parent of Request2");
69 //              }
70                 if(!parents1.isEmpty()) fail("Request1 should not have parents");
71                 if(!parents2.isEmpty()) fail("Request2 should not have parents");
72                 
73         }
74
75 }