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 GraphSyncAsyncReadThrowsRuntimeException extends ExistingDatabaseTest {
26 private RuntimeException 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 IllegalArgumentException();
49 public int threadHash() {
54 public int getFlags() {
60 } catch (Throwable e) {
62 if(!(e instanceof DatabaseException)) {
63 fail("Request did not throw DatabaseException but " + e);
67 DatabaseException ex = (DatabaseException)e;
69 if(!exception.equals(ex.getCause())) {
70 fail("Request did not report the correct cause but " + e);
81 fail("Request did not throw an exception.");