]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SyncWriteReadTest1.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / regression / bugs / SyncWriteReadTest1.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.regression.bugs;
13
14 import org.junit.After;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.Session;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.common.request.ReadRequest;
22 import org.simantics.db.common.request.WriteRequest;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.db.testing.annotation.Fails;
25 import org.simantics.db.testing.base.ExistingDatabaseTest;
26 import org.simantics.db.testing.common.Terminator;
27
28 /**
29  * Tests that sync read within sync write causes exception.
30  * Currently this tests causes deadlock.
31  */
32 public class SyncWriteReadTest1 extends ExistingDatabaseTest {
33     final boolean DEBUG = true;
34     final String resourceName = "r1";
35     
36     private Terminator terminator;
37     
38     @Before
39     @Override
40     public void setUp() throws Exception {
41         super.setUp();
42         terminator = new Terminator(3);
43     }
44
45     @After
46     @Override
47     public void tearDown() throws Exception {
48         terminator.disarm();
49         super.tearDown();
50     }
51     
52     @Test
53     @Fails
54     public void testSyncWriteReadTest1() throws Exception {
55         final Session session = getSession();
56         try {
57             session.syncRequest(new WriteRequest() {
58                 @Override
59                 public void perform(WriteGraph graph) throws DatabaseException {
60                     try {
61                         session.sync(new ReadRequest() {
62                             @Override
63                             public void run(ReadGraph graph) throws DatabaseException {
64                                 Resource root = graph.getResource(ROOT_LIBRARY_URI);
65                                 assertTrue("Failed to get root library.", null == root);
66                              }
67                         });
68                         fail("Missing exception during read request.");
69                     } catch (DatabaseException e) {
70                         if (DEBUG)
71                             System.out.println("Catched DatabaseException as expected.");
72                     }
73                 }
74             });
75         } catch (DatabaseException e) {
76             if (DEBUG)
77                 System.out.println("Catched DatabaseException as excepected:" + e.getMessage());
78             return;
79         }
80         fail("Sync write failed to throw exception as expected.");
81     }
82 }