]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/ObjectsWithNoClusterWithCachedRelationInfo.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / support / clusterControl / ObjectsWithNoClusterWithCachedRelationInfo.java
diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/ObjectsWithNoClusterWithCachedRelationInfo.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/ObjectsWithNoClusterWithCachedRelationInfo.java
new file mode 100644 (file)
index 0000000..0596f76
--- /dev/null
@@ -0,0 +1,49 @@
+package org.simantics.db.tests.api.support.clusterControl;
+
+import org.junit.Test;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.primitiverequest.PossibleObject;
+import org.simantics.db.common.procedure.adapter.ListenerAdapter;
+import org.simantics.db.common.request.WriteResultRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.service.ClusterControl;
+import org.simantics.db.testing.base.ExistingDatabaseTest;
+import org.simantics.layer0.Layer0;
+
+public class ObjectsWithNoClusterWithCachedRelationInfo extends ExistingDatabaseTest {
+    
+    @Test
+    public void test() throws DatabaseException {
+        
+       Session session = getSession();
+       
+               final Layer0 L0 = Layer0.getInstance(session);
+               
+               // Create resource in new cluster (not 1)
+        final Resource res = session.syncRequest(new WriteResultRequest<Resource>() {
+
+                       @Override
+                       public Resource perform(WriteGraph graph) throws DatabaseException {
+
+                               Resource res = graph.newResource();
+                               graph.claim(res, L0.HasName, L0.NameOf, res);
+                               return res;
+                               
+                       }
+               
+        });
+       
+        // Cache RelationInfo for HasName
+        session.syncRequest(new PossibleObject(L0.Entity, L0.HasName), new ListenerAdapter<Resource>());
+
+        // Flush clusters
+               ClusterControl support = getSession().getService(ClusterControl.class);
+               support.collectClusters(Integer.MAX_VALUE);
+               
+               // Request objects for res, now relationinfo is in cache and res has no cluster
+        session.syncRequest(new PossibleObject(res, L0.HasName));
+               
+    }
+}