+/*******************************************************************************
+ * 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.");
+ }
+ }
+}