]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/CachedDirectPredicatesWithNoCluster.java
a9698e744f946a3a14daa61fd92bb43d3d61ab2a
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / support / clusterControl / CachedDirectPredicatesWithNoCluster.java
1 package org.simantics.db.tests.api.support.clusterControl;
2
3 import org.junit.Test;
4 import org.simantics.db.AsyncReadGraph;
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.Session;
7 import org.simantics.db.common.procedure.adapter.AsyncProcedureAdapter;
8 import org.simantics.db.common.procedure.adapter.ListenerAdapter;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.db.procedure.AsyncProcedure;
11 import org.simantics.db.request.AsyncRead;
12 import org.simantics.db.request.Read;
13 import org.simantics.db.service.ClusterControl;
14 import org.simantics.db.testing.base.ExistingDatabaseTest;
15 import org.simantics.layer0.Layer0;
16
17 public class CachedDirectPredicatesWithNoCluster extends ExistingDatabaseTest {
18     
19     @Test
20     public void test() throws DatabaseException {
21         
22         Session session = getSession();
23         
24         final Layer0 L0 = Layer0.getInstance(session);
25         
26         session.syncRequest(new Read<Boolean>() {
27
28             @Override
29             public Boolean perform(ReadGraph graph) throws DatabaseException {
30                 Layer0 L0 = Layer0.getInstance(graph);
31                 return graph.hasStatement(L0.Entity);
32             }
33             
34         }, new ListenerAdapter<Boolean>() {
35             @Override
36             public boolean isDisposed() {
37                 return false;
38             }
39         });
40         
41         ClusterControl support = getSession().getService(ClusterControl.class);
42         support.collectClusters(Integer.MAX_VALUE);
43         
44         session.syncRequest(new AsyncRead<Boolean>() {
45
46             @Override
47             public void perform(AsyncReadGraph graph, AsyncProcedure<Boolean> procedure) {
48                 graph.forHasStatement(L0.Entity, procedure);
49             }
50             
51             @Override
52             public int threadHash() {
53                 return hashCode();
54             }
55
56             @Override
57             public int getFlags() {
58                 return 0;
59             }
60             
61         }, new AsyncProcedureAdapter<Boolean>() {
62
63             @Override
64             public void execute(AsyncReadGraph graph, Boolean result) {
65                 if (DEBUG)
66                     System.err.println("exec: " + result);
67             }
68             
69             @Override
70             public void exception(AsyncReadGraph graph, Throwable t) {
71                 if (DEBUG)
72                     System.err.println("exception: " + t);
73             }
74             
75         });
76
77     }
78     
79 }