X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fregression%2Fbugs%2FSimanticsFeature4007Test1.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fregression%2Fbugs%2FSimanticsFeature4007Test1.java;h=f92bc2d0472fce24454ee1460cd74ff566e29982;hb=67fd62f9c742337ec80eef658192db198a0efaac;hp=0000000000000000000000000000000000000000;hpb=cde82ba81327d5515fdca362f7f4c70f5103ae80;p=simantics%2Fplatform.git diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsFeature4007Test1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsFeature4007Test1.java new file mode 100644 index 000000000..f92bc2d04 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsFeature4007Test1.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.regression.bugs; + +import org.junit.Test; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.ManagementSupport; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; + +/** + * Tests that using virtual graph during write request does not interfere with + * generation of core change sets. + * + * See https://www.simulationsite.net/redmine/issues/4007. + */ +public class SimanticsFeature4007Test1 extends ExistingDatabaseTest { + @Test + public void testSimanticsFeature4007() throws Exception { + final Session session = getSession(); + final VirtualGraphSupport vgSupport = session.getService(VirtualGraphSupport.class); + final ManagementSupport mg = session.getService(ManagementSupport.class); + long id1 = mg.getHeadRevisionId(); + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + + Resource r1 = graph.newResource(); + graph.claim(r1, L0.InstanceOf, null, L0.Library); + graph.claimLiteral(r1, L0.HasName, "r1"); + + VirtualGraph vg = vgSupport.getWorkspacePersistent("vg"); + graph.syncRequest(new WriteRequest(vg) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource r = graph.newResource(); + graph.claim(r, L0.InstanceOf, null, L0.Library); + graph.claimLiteral(r, L0.HasName, "rv"); + } + }); + + Resource r2 = graph.newResource(); + graph.claim(r2, L0.InstanceOf, null, L0.Library); + graph.claimLiteral(r2, L0.HasName, "r2"); + } + }); + long id2 = mg.getHeadRevisionId(); + assertTrue(getName() + " failed!", id2 == id1 + 1); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception " + e); + } + } +}