1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.tests.api.write.request;
14 import org.junit.Test;
15 import org.simantics.db.Resource;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.common.request.WriteRequest;
18 import org.simantics.db.exception.CancelTransactionException;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.testing.base.ExistingDatabaseTest;
21 import org.simantics.layer0.Layer0;
24 * Checks that unexpected write callback failures do not crash the session and
25 * that the write request results were correctly committed.
27 * @author Tuukka Lehtonen
29 public class WriteCancelTest extends ExistingDatabaseTest {
31 private static final String AN_ENTITY = "An entity";
36 public void testWriteCancel() throws DatabaseException{
39 getSession().syncRequest(new WriteRequest() {
41 public void perform(WriteGraph graph) throws DatabaseException {
42 Layer0 b = Layer0.getInstance(graph);
43 written = graph.newResource();
44 writtenName = graph.newResource();
45 graph.claim(written, b.InstanceOf, null, b.Entity);
46 graph.claim(writtenName, b.InstanceOf, null, b.String);
47 graph.claimValue(writtenName, AN_ENTITY);
48 graph.claim(written, b.HasName, writtenName);
50 //throw new DatabaseException("Intentional write request cancellation by unexpected exception");
51 throw new CancelTransactionException("Intentional write request cancellation");
54 } catch (DatabaseException e) {
59 // Make sure that we can at least start a new transaction after the
60 // cancelled one, but don't do anything yet.
61 getSession().syncRequest(new WriteRequest() {
63 public void perform(WriteGraph graph) throws DatabaseException {
67 // Ensure that the previously written data does not exist.
68 getSession().syncRequest(new WriteRequest() {
70 public void perform(WriteGraph graph) throws DatabaseException {
71 Layer0 b = Layer0.getInstance(graph);
72 assertTrue(!graph.hasStatement(written, b.InstanceOf, b.Entity));
73 assertTrue(!graph.hasStatement(written, b.HasName, writtenName));
74 assertTrue(!graph.hasStatement(writtenName, b.InstanceOf, b.String));
75 assertTrue(!graph.hasValue(writtenName));