]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestParentTest6.java
Multiple reader thread support for db client
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / request / misc / RequestParentTest6.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.Resource;
20 import org.simantics.db.Session;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.impl.query.CacheEntry;
23 import org.simantics.db.impl.service.QueryDebug;
24 import org.simantics.db.procedure.AsyncMultiListener;
25 import org.simantics.db.request.Read;
26 import org.simantics.db.testing.base.SimpleBase;
27 import org.simantics.layer0.Layer0;
28
29 public class RequestParentTest6 extends SimpleBase {
30         
31         @Test
32         public void test() throws Exception {
33                 
34                 Session session = getSession();
35                 
36                 QueryDebug debug = session.getService(QueryDebug.class);
37                 
38         class Request implements Read<Object> {
39
40             @Override
41             public Object perform(ReadGraph graph) throws DatabaseException {
42                 return new Object();
43             }
44             
45         }
46                 
47         final Request request = new Request();
48         
49         session.syncRequest(new TestAsyncReadRequest() {
50
51             @Override
52             public void run(AsyncReadGraph graph) throws Throwable {
53                 Layer0 l0 = Layer0.getInstance(graph);
54                 graph.forEachObject(rl, l0.InstanceOf, new AsyncMultiListener<Resource>() {
55
56                     @Override
57                     public void exception(AsyncReadGraph graph, Throwable t) {
58                     }
59
60                     @Override
61                     public void execute(AsyncReadGraph graph, Resource result) {
62                         graph.asyncRequest(request);
63                     }
64
65                     @Override
66                     public boolean isDisposed() {
67                         return false;
68                     }
69
70                     @Override
71                     public void finished(AsyncReadGraph graph) {
72                     }
73
74                 });
75                 
76             }
77             
78         });
79                 
80                 Set<CacheEntry> parents = debug.getParents(request);
81                 if(!parents.isEmpty())fail("Request2 should not have parents");
82                 
83         }
84
85 }