]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest3.java
2bec7c21eb3666dedbf9a68a573daee4c77354c6
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / request / misc / RequestParentTest3.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.Session;
19 import org.simantics.db.impl.query.CacheEntry;
20 import org.simantics.db.impl.service.QueryDebug;
21 import org.simantics.db.procedure.AsyncMultiListener;
22 import org.simantics.db.procedure.AsyncMultiProcedure;
23 import org.simantics.db.request.AsyncMultiRead;
24 import org.simantics.db.testing.base.ExistingDatabaseTest;
25
26 public class RequestParentTest3 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 AsyncMultiRead<Object> {
36
37                         @Override
38                         public int threadHash() {
39                                 return hashCode();
40                         }
41                         
42             @Override
43             public void perform(AsyncReadGraph graph, AsyncMultiProcedure<Object> callback) {
44                 callback.execute(graph, new Object());
45                 callback.finished(graph);
46             }
47             
48         }
49                 
50         final Request request1 = new Request();
51         final Request request2 = new Request();
52         
53         session.syncRequest(request1, new AsyncMultiListener<Object>() {
54
55             @Override
56             public void exception(AsyncReadGraph graph, Throwable t) {
57             }
58
59             @Override
60             public void execute(AsyncReadGraph graph, Object result) {
61                 graph.asyncRequest(request2);
62             }
63
64             @Override
65             public boolean isDisposed() {
66                 return false;
67             }
68
69             @Override
70             public void finished(AsyncReadGraph graph) {
71             }
72
73         });
74                 
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");
78                 }
79                 if(!parents.isEmpty())fail("Request2 should not have parents");
80                 
81         }
82
83 }