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 java.util.Arrays;
16 import org.junit.Test;
17 import org.simantics.databoard.Bindings;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.Session;
21 import org.simantics.db.WriteGraph;
22 import org.simantics.db.common.request.ReadRequest;
23 import org.simantics.db.common.request.WriteRequest;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.db.service.UndoRedoSupport;
26 import org.simantics.db.testing.base.ExistingDatabaseTest;
27 import org.simantics.layer0.Layer0;
28 import org.simantics.utils.DataContainer;
31 * Tests undo of deletion of large literal when done twice in sequence.
32 * This was added because of Bug #4591.
34 public class UndoTest20 extends ExistingDatabaseTest {
35 private void initValue(byte[] value) {
36 for (int i=0; i<value.length; ++i)
41 public void testUndo20() throws Exception {
42 Session session = getSession();
43 final byte[] value = new byte[100000];
45 final DataContainer<Resource> subject1 = new DataContainer<Resource>();
47 session.syncRequest(new WriteRequest() {
49 public void perform(WriteGraph graph) throws DatabaseException {
50 graph.markUndoPoint();
51 Layer0 b = Layer0.getInstance(graph);
52 Resource s1 = graph.newResource();
53 graph.claim(s1, b.InstanceOf, b.Entity);
54 graph.claimValue(s1, value);
58 } catch (Throwable e) {
59 fail("Write transaction threw an unknown exception ", e);
61 testUndo(session, value, subject1);
62 testUndo(session, value, subject1);
64 public void testUndo(final Session session, final byte[] value, final DataContainer<Resource> subject1)
66 final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
68 session.syncRequest(new ReadRequest() {
70 public void run(ReadGraph graph) throws DatabaseException {
71 Resource s1 = subject1.get();
72 byte[] t1 = graph.getValue(s1, Bindings.BYTE_ARRAY);
73 if (!Arrays.equals(t1, value))
74 fail("Failed to verify value.");
77 } catch (Throwable e) {
78 fail("Read transaction threw an unexpected exception ", e);
81 session.syncRequest(new WriteRequest() {
83 public void perform(WriteGraph graph) throws DatabaseException {
84 graph.markUndoPoint();
85 Resource s1 = subject1.get();
89 } catch (Throwable e) {
90 fail("Write transaction threw an unknown exception ", e);
93 session.syncRequest(new ReadRequest() {
95 public void run(ReadGraph graph) throws DatabaseException {
96 Resource s1 = subject1.get();
97 byte[] t1 = graph.getPossibleValue(s1, Bindings.BYTE_ARRAY);
99 fail("Failed to verify delettion of value.");
102 } catch (Throwable e) {
103 fail("Read transaction threw an unexpected exception ", e);
106 support.undo(session, 1);
107 } catch (Throwable e) {
108 fail("Undo operation threw an unexpected exception.", e);
111 session.syncRequest(new ReadRequest() {
113 public void run(ReadGraph graph) throws DatabaseException {
114 Resource s1 = subject1.get();
115 byte[] t1 = graph.getValue(s1, Bindings.BYTE_ARRAY);
116 if (!Arrays.equals(t1, value))
117 fail("Failed to verify value1.");
120 } catch (Throwable e) {
121 fail("Read transaction threw an unexpected exception ", e);