--- /dev/null
+/*******************************************************************************
+ * 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);
+ }
+ }
+}