1 package org.simantics.db.tests.regression.bugs;
3 import java.util.Collection;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.Resource;
8 import org.simantics.db.WriteGraph;
9 import org.simantics.db.common.CommentMetadata;
10 import org.simantics.db.common.UndoMetadata;
11 import org.simantics.db.common.request.UniqueRead;
12 import org.simantics.db.common.request.WriteRequest;
13 import org.simantics.db.exception.DatabaseException;
14 import org.simantics.db.service.ManagementSupport;
15 import org.simantics.db.testing.base.ExistingDatabaseTest;
18 * I found a bug in the database client write requests that caused the following
22 * <li>Perform a write request (NOP) which inserts a comment into the metadata
23 * but does no changes to the database</li>
24 * <li>Perform another request (W) that writes both comment metadata and
25 * database changes</li>
26 * <li>The database revision history will contain a single new revision with the
27 * both comments from the NOP and W</li>
30 * The expected result is that the database only contains the comment metadata
31 * written in request W.
33 * @author Tuukka Lehtonen
35 public class CommentMetadataWriteTest extends ExistingDatabaseTest {
36 // Behavior of commit has been changed. Commits with only CommentMetadata are dropped.
37 private void addMetadata(WriteGraph wg, String s) throws DatabaseException {
38 CommentMetadata cm = wg.getMetadata(CommentMetadata.class);
39 wg.addMetadata(cm.add(s));
40 wg.addMetadata(new UndoMetadata(null, false, 0, 0));
43 public void test() throws Exception {
44 // Perform empty request, write comment
45 WriteRequest nop = new WriteRequest() {
47 public void perform(WriteGraph graph) throws DatabaseException {
48 addMetadata(graph, "NOP");
51 getSession().sync(nop);
53 // Perform non-empty request, write comment
54 WriteRequest w = new WriteRequest() {
56 public void perform(WriteGraph graph) throws DatabaseException {
57 Resource r = graph.newResource();
58 graph.claim(r, L0.InstanceOf, L0.String);
59 graph.claimValue(r, "FOO");
60 CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
61 graph.addMetadata(cm.add("W"));
65 assertTrue("Metadata from empty requests should not accumulate to following requests", getSession().sync(new UniqueRead<Boolean>() {
67 public Boolean perform(ReadGraph graph) throws DatabaseException {
68 ManagementSupport ms = graph.getService(ManagementSupport.class);
69 long cid = ms.getHeadRevisionId();
70 Collection<CommentMetadata> comments = ms.getMetadata(cid, cid, CommentMetadata.class);
71 if (comments.size() != 1)
73 CommentMetadata cm = comments.iterator().next();
74 String s = cm.toString();
75 // The line feed is added by the add operation.
76 if (!s.matches("W\n"))