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.support.undoRedoSupport;
14 import org.junit.Test;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.Session;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.common.request.ReadRequest;
20 import org.simantics.db.common.request.WriteRequest;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.exception.NoSingleResultException;
23 import org.simantics.db.service.UndoRedoSupport;
24 import org.simantics.db.testing.base.ExistingDatabaseTest;
25 import org.simantics.layer0.Layer0;
26 import org.simantics.utils.DataContainer;
29 * Tests cases where a non-functional relation uses
30 * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)}
34 * Should throw {@link NoSingleResultException}, at the time of writing this
35 * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck.
37 public class RedoTest1 extends ExistingDatabaseTest {
40 public void test() throws Exception {
42 Session session = getSession();
43 final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
44 final DataContainer<Resource> subject = new DataContainer<Resource>();
47 session.syncRequest(new WriteRequest() {
49 public void perform(WriteGraph graph) throws DatabaseException {
50 // Use any non-functional relation
51 Layer0 b = Layer0.getInstance(graph);
52 Resource s = graph.newResource();
53 graph.claim(s, b.InstanceOf, b.Entity);
57 } catch (Throwable e) {
58 fail("Write transaction threw an unknown exception " + e);
62 session.syncRequest(new ReadRequest() {
64 public void run(ReadGraph graph) throws DatabaseException {
65 assert(graph.hasStatement(subject.get()));
68 } catch (Throwable e) {
69 fail("Could not validate statement. Read transaction threw an unexpected exception " + e);
72 support.undo(session, 1);
75 session.syncRequest(new ReadRequest() {
77 public void run(ReadGraph graph) throws DatabaseException {
78 assert(!graph.hasStatement(subject.get()));
81 } catch (Throwable e) {
82 fail("Read transaction threw an unexpected exception " + e);
86 session.syncRequest(new ReadRequest() {
88 public void run(ReadGraph graph) throws DatabaseException {
89 assert(!graph.hasStatement(subject.get()));
92 } catch (Throwable e) {
93 fail("Could not validate statement's undo. Read transaction threw an unexpected exception " + e);
96 support.redo(session, 1);
99 session.syncRequest(new ReadRequest() {
101 public void run(ReadGraph graph) throws DatabaseException {
102 assert(graph.hasStatement(subject.get()));
105 } catch (Throwable e) {
106 fail("Could not validate statement's redo. Read transaction threw an unexpected exception " + e);