]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/DelayedWriteGraphVirtualGraphHandling.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / delayedWrite / DelayedWriteGraphVirtualGraphHandling.java
diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/DelayedWriteGraphVirtualGraphHandling.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/DelayedWriteGraphVirtualGraphHandling.java
new file mode 100644 (file)
index 0000000..9ffb5dd
--- /dev/null
@@ -0,0 +1,75 @@
+package org.simantics.db.tests.api.delayedWrite;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.junit.Test;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.VirtualGraph;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.DelayedWriteRequest;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.common.request.WriteResultRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.service.VirtualGraphSupport;
+import org.simantics.db.testing.annotation.Fails;
+import org.simantics.db.testing.base.ExistingDatabaseTest;
+
+/**
+ * This originated from Apros issue #3296.
+ * 
+ * @author Tuukka Lehtonen
+ */
+public class DelayedWriteGraphVirtualGraphHandling extends ExistingDatabaseTest {
+
+    @Test
+    @Fails
+    public void test() throws Exception {
+        final VirtualGraphSupport vgs = getSession().getService(VirtualGraphSupport.class);
+        final VirtualGraph mem = getSession().getService(VirtualGraphSupport.class).getMemoryPersistent("MEM");
+        final VirtualGraph ws = getSession().getService(VirtualGraphSupport.class).getWorkspacePersistent("WS");
+
+        final AtomicReference<Resource> transientName = new AtomicReference<Resource>();
+        final AtomicReference<Resource> persistentDescription = new AtomicReference<Resource>();
+
+        DelayedWriteRequest r = new DelayedWriteRequest() {
+            @Override
+            public void perform(WriteGraph graph) throws DatabaseException {
+                final Resource r = graph.newResource();
+                graph.claim(r, L0.InstanceOf, null, L0.Entity);
+
+                transientName.set( graph.sync(new WriteResultRequest<Resource>(mem) {
+                    @Override
+                    public Resource perform(WriteGraph graph) throws DatabaseException {
+                        Resource vr = graph.newResource();
+                        graph.claim(vr, L0.InstanceOf, null, L0.String);
+                        graph.claim(r, L0.HasName, vr);
+                        return vr;
+                    }
+                }) );
+                persistentDescription.set( graph.sync(new WriteResultRequest<Resource>(ws) {
+                    @Override
+                    public Resource perform(WriteGraph graph) throws DatabaseException {
+                        Resource vr = graph.newResource();
+                        graph.claim(vr, L0.InstanceOf, null, L0.String);
+                        graph.claim(r, L0.HasDescription, vr);
+                        return vr;
+                    }
+                }) );
+            }
+        };
+        getSession().sync(r);
+
+        // Validate that the data was actually written into virtual graphs.
+        getSession().sync(new ReadRequest() {
+            @Override
+            public void run(ReadGraph graph) throws DatabaseException {
+                VirtualGraph nameVg = vgs.getGraph(graph, transientName.get());
+                VirtualGraph descVg = vgs.getGraph(graph, persistentDescription.get());
+                assertEquals(nameVg, mem);
+                assertEquals(descVg, ws);
+            }
+        });
+    }
+
+}