X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fapi%2FdelayedWrite%2FDelayedWriteGraphVirtualGraphHandling.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fapi%2FdelayedWrite%2FDelayedWriteGraphVirtualGraphHandling.java;h=9ffb5dd7d69312613e5237c22bfce006222c717a;hb=67fd62f9c742337ec80eef658192db198a0efaac;hp=0000000000000000000000000000000000000000;hpb=cde82ba81327d5515fdca362f7f4c70f5103ae80;p=simantics%2Fplatform.git 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 index 000000000..9ffb5dd7d --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/delayedWrite/DelayedWriteGraphVirtualGraphHandling.java @@ -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 transientName = new AtomicReference(); + final AtomicReference persistentDescription = new AtomicReference(); + + 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(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(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); + } + }); + } + +}