X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fapi%2Fsupport%2FundoRedoSupport%2FUndoTest18.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fapi%2Fsupport%2FundoRedoSupport%2FUndoTest18.java;h=63a2f42a63aaa28c8510942356a35d43d23c2f13;hb=67fd62f9c742337ec80eef658192db198a0efaac;hp=0000000000000000000000000000000000000000;hpb=cde82ba81327d5515fdca362f7f4c70f5103ae80;p=simantics%2Fplatform.git diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest18.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest18.java new file mode 100644 index 000000000..63a2f42a6 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest18.java @@ -0,0 +1,187 @@ +/******************************************************************************* + * 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.api.support.undoRedoSupport; + +import java.util.Arrays; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Tests undo of two changes sets with values modified in multiple cluster change sets. + * The binary values will cause two cluster change sets per modification. + * (By the way the above-mentioned behavior will cause serious fragmentation in server + * because the size of cluster change sets are ridiculously small and server does not + * process cluster change sets but stores them as is. The payload is just about the same + * as the bookkeeping structures. TODO: fix the aforementioned fragmentation) + */ +public class UndoTest18 extends ExistingDatabaseTest { + private void initValue(byte[] value) { + for (int i=0; i subject1 = new DataContainer(); + final DataContainer subject2 = new DataContainer(); + final byte[] value10 = new byte[100000]; + final byte[] value20 = new byte[100001]; + final byte[] value11 = new byte[100002]; + final byte[] value21 = new byte[100003]; + + try { + initValue(value10); + initValue(value11); + initValue(value20); + initValue(value21); + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 b = Layer0.getInstance(graph); + Resource s1 = graph.newResource(); + graph.claim(s1, b.InstanceOf, b.Entity); + graph.claimValue(s1, value10); + subject1.set(s1); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 b = Layer0.getInstance(graph); + Resource s2 = graph.newResource(); + graph.claim(s2, b.InstanceOf, b.Entity); + graph.claimValue(s2, value20); + subject2.set(s2); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s1 = subject1.get(); + byte[] t1 = graph.getValue(s1, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t1, value10)) + fail("Failed to verify value1."); + Resource s2 = subject2.get(); + byte[] t2 = graph.getValue(s2, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t2, value20)) + fail("Failed to verify value2."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + graph.newResource(); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 b = Layer0.getInstance(graph); + Resource s1 = subject1.get(); + graph.claim(s1, b.InstanceOf, b.Entity); + graph.claimValue(s1, value11); + subject1.set(s1); + Resource s2 = subject2.get(); + graph.claim(s2, b.InstanceOf, b.Entity); + graph.claimValue(s2, value21); + subject2.set(s2); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s1 = subject1.get(); + byte[] t1 = graph.getValue(s1, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t1, value11)) + fail("Failed to verify value11."); + Resource s2 = subject2.get(); + byte[] t2 = graph.getValue(s2, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t2, value21)) + fail("Failed to verify value21."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + + try { + support.undo(session, 2); + } catch (Throwable e) { + fail("Undo operation threw an unexpected exception.", e); + } + + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s1 = subject1.get(); + byte[] t1 = graph.getValue(s1, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t1, value10)) + fail("Failed to verify value1."); + Resource s2 = subject2.get(); + byte[] t2 = graph.getValue(s2, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t2, value20)) + fail("Failed to verify value2."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + + } + +} +