]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/ObjectsWithNoClusterWithCachedRelationInfo.java
Made DB ListenerAdapter abstract to force isDisposed implementation
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / support / clusterControl / ObjectsWithNoClusterWithCachedRelationInfo.java
1 package org.simantics.db.tests.api.support.clusterControl;
2
3 import org.junit.Test;
4 import org.simantics.db.Resource;
5 import org.simantics.db.Session;
6 import org.simantics.db.WriteGraph;
7 import org.simantics.db.common.primitiverequest.PossibleObject;
8 import org.simantics.db.common.procedure.adapter.ListenerAdapter;
9 import org.simantics.db.common.request.WriteResultRequest;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.service.ClusterControl;
12 import org.simantics.db.testing.base.ExistingDatabaseTest;
13 import org.simantics.layer0.Layer0;
14
15 public class ObjectsWithNoClusterWithCachedRelationInfo extends ExistingDatabaseTest {
16     
17     @Test
18     public void test() throws DatabaseException {
19         
20         Session session = getSession();
21         
22                 final Layer0 L0 = Layer0.getInstance(session);
23                 
24                 // Create resource in new cluster (not 1)
25         final Resource res = session.syncRequest(new WriteResultRequest<Resource>() {
26
27                         @Override
28                         public Resource perform(WriteGraph graph) throws DatabaseException {
29
30                                 Resource res = graph.newResource();
31                                 graph.claim(res, L0.HasName, L0.NameOf, res);
32                                 return res;
33                                 
34                         }
35                 
36         });
37         
38         // Cache RelationInfo for HasName
39         session.syncRequest(new PossibleObject(L0.Entity, L0.HasName), new ListenerAdapter<Resource>() {
40             @Override
41             public boolean isDisposed() {
42                 return false;
43             }
44         });
45
46         // Flush clusters
47                 ClusterControl support = getSession().getService(ClusterControl.class);
48                 support.collectClusters(Integer.MAX_VALUE);
49                 
50                 // Request objects for res, now relationinfo is in cache and res has no cluster
51         session.syncRequest(new PossibleObject(res, L0.HasName));
52                 
53     }
54 }