]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/GraphSyncAsyncReadPassesDatabaseException.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / request / exception / GraphSyncAsyncReadPassesDatabaseException.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.tests.api.request.exception;
13
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;
23
24 public class GraphSyncAsyncReadPassesDatabaseException extends ExistingDatabaseTest {
25         
26         private Exception exception; 
27         
28         @Test
29         public void testWriteException() throws Exception {
30                 
31                 Session session = getSession();
32                 
33                 session.syncRequest(new Read<Object>() {
34
35             @Override
36             public Object perform(ReadGraph graph) throws DatabaseException {
37                 
38                 try {
39
40                     graph.syncRequest(new AsyncRead<Object>() {
41
42                         @Override
43                         public void perform(AsyncReadGraph graph, AsyncProcedure<Object> procedure) {
44                             exception = new DatabaseException();
45                             procedure.exception(graph, exception);
46                         }
47
48                         @Override
49                             public int threadHash() {
50                                 return hashCode();
51                             }
52
53                         @Override
54                         public int getFlags() {
55                             return 0;
56                         }
57
58                     });
59                 
60                 } catch (Throwable e) {
61
62                     if(!e.equals(exception)) {
63                         fail("Write transaction threw an unknown exception " + e);
64                     }
65                     
66                                 if (DEBUG)
67                                         e.printStackTrace();
68                     
69                     return null;
70
71                 }
72                 
73                 fail("Write transaction did not throw an exception.");
74
75                 return null;
76
77             }
78                     
79                 });
80                 
81         }
82
83 }