X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fregression%2Fbugs%2FIssue3422Test1.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fregression%2Fbugs%2FIssue3422Test1.java;h=4d82714faf9a49c319fa21867d69e60a01e27f55;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/Issue3422Test1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3422Test1.java new file mode 100644 index 000000000..4d82714fa --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3422Test1.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * 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.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ImmutableException; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.service.XSupport; +import org.simantics.db.testing.cases.FreshDatabaseTest; +import org.simantics.db.testing.common.TestBase; +import org.simantics.layer0.Layer0; + +/** + * Tests that commit which changes only meta data will create revision. + */ +public class Issue3422Test1 extends FreshDatabaseTest { + private Resource testRoot; + @Test + public void test() throws DatabaseException { + Session session = getSession(); + session.syncRequest(new Init()); + session.syncRequest(new Modify()); + } + class Init extends WriteRequest { + @Override + public void perform(WriteGraph g) throws DatabaseException { + ClusterControl cc = (ClusterControl)g.getService(ClusterControl.class); + cc.collectClusters(Integer.MAX_VALUE); + int nClusters = cc.flushClusters(); + Layer0 l0 = Layer0.getInstance(g); + g.flushCluster(); // Starts new cluster. + Resource rl = g.getResource(TestBase.ROOT_LIBRARY_URI); + testRoot = g.newResource(); + g.claim(testRoot, l0.InstanceOf, l0.Library); + g.claim(rl, l0.ConsistsOf, testRoot); + XSupport xs = (XSupport)g.getService(XSupport.class); + assertFalse("GetImmutable did not work.", xs.getImmutable(testRoot)); + xs.setImmutable(testRoot, true); + assertTrue("SetImmutable did not work.", xs.getImmutable(testRoot)); + cc.collectClusters(Integer.MAX_VALUE); + int nClusters2 = cc.flushClusters(); + assertTrue("Could not relase clusters.", nClusters + 1 == nClusters2); + } + } + class Modify extends WriteRequest { + @Override + public void perform(WriteGraph g) throws DatabaseException { + ClusterControl cc = (ClusterControl)g.getService(ClusterControl.class); + cc.collectClusters(Integer.MAX_VALUE); + int nClusters = cc.flushClusters(); + System.out.println("clusters count=" + nClusters); + Layer0 l0 = Layer0.getInstance(getSession()); + XSupport xs = (XSupport)g.getService(XSupport.class); + assertTrue("SetImmutable did not work.", xs.getImmutable(testRoot)); + try { + g.claim(testRoot, l0.InstanceOf, l0.Relation); + } catch (ImmutableException e) { + return; + } + fail("Immutable check did not work."); + } + } +}