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%2FCommentMetadataWriteTest.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fregression%2Fbugs%2FCommentMetadataWriteTest.java;h=a072fcedb9318aaca72e9f8ec768ceb6650c4c19;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/CommentMetadataWriteTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/CommentMetadataWriteTest.java new file mode 100644 index 000000000..a072fcedb --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/CommentMetadataWriteTest.java @@ -0,0 +1,84 @@ +package org.simantics.db.tests.regression.bugs; + +import java.util.Collection; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.CommentMetadata; +import org.simantics.db.common.UndoMetadata; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.ManagementSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; + +/** + * I found a bug in the database client write requests that caused the following + * to happen: + * + *
    + *
  1. Perform a write request (NOP) which inserts a comment into the metadata + * but does no changes to the database
  2. + *
  3. Perform another request (W) that writes both comment metadata and + * database changes
  4. + *
  5. The database revision history will contain a single new revision with the + * both comments from the NOP and W
  6. + *
+ * + * The expected result is that the database only contains the comment metadata + * written in request W. + * + * @author Tuukka Lehtonen + */ +public class CommentMetadataWriteTest extends ExistingDatabaseTest { + // Behavior of commit has been changed. Commits with only CommentMetadata are dropped. + private void addMetadata(WriteGraph wg, String s) throws DatabaseException { + CommentMetadata cm = wg.getMetadata(CommentMetadata.class); + wg.addMetadata(cm.add(s)); + wg.addMetadata(new UndoMetadata(null, false, 0, 0)); + } + @Test + public void test() throws Exception { + // Perform empty request, write comment + WriteRequest nop = new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + addMetadata(graph, "NOP"); + } + }; + getSession().sync(nop); + + // Perform non-empty request, write comment + WriteRequest w = new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Resource r = graph.newResource(); + graph.claim(r, L0.InstanceOf, L0.String); + graph.claimValue(r, "FOO"); + CommentMetadata cm = graph.getMetadata(CommentMetadata.class); + graph.addMetadata(cm.add("W")); + } + }; + getSession().sync(w); + assertTrue("Metadata from empty requests should not accumulate to following requests", getSession().sync(new UniqueRead() { + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + ManagementSupport ms = graph.getService(ManagementSupport.class); + long cid = ms.getHeadRevisionId(); + Collection comments = ms.getMetadata(cid, cid, CommentMetadata.class); + if (comments.size() != 1) + return false; + CommentMetadata cm = comments.iterator().next(); + String s = cm.toString(); + // The line feed is added by the add operation. + if (!s.matches("W\n")) + return false; + else + return true; + } + })); + } + +}