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.request.exception;
14 import org.junit.Test;
15 import org.simantics.db.AsyncReadGraph;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Session;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.db.procedure.AsyncProcedure;
20 import org.simantics.db.request.AsyncRead;
21 import org.simantics.db.request.Read;
22 import org.simantics.db.testing.base.ExistingDatabaseTest;
24 public class GraphSyncAsyncReadPassesDatabaseException extends ExistingDatabaseTest {
26 private Exception exception;
29 public void testWriteException() throws Exception {
31 Session session = getSession();
33 session.syncRequest(new Read<Object>() {
36 public Object perform(ReadGraph graph) throws DatabaseException {
40 graph.syncRequest(new AsyncRead<Object>() {
43 public void perform(AsyncReadGraph graph, AsyncProcedure<Object> procedure) {
44 exception = new DatabaseException();
45 procedure.exception(graph, exception);
49 public int threadHash() {
54 public int getFlags() {
60 } catch (Throwable e) {
62 if(!e.equals(exception)) {
63 fail("Write transaction threw an unknown exception " + e);
73 fail("Write transaction did not throw an exception.");