]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/client/TransactionTest4.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / client / TransactionTest4.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.client;
13
14 import org.junit.Test;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.WriteGraph;
18 import org.simantics.db.common.request.ReadRequest;
19 import org.simantics.db.common.request.WriteResultRequest;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.service.XSupport;
22 import org.simantics.db.testing.annotation.Fails;
23 import org.simantics.db.testing.base.ExistingDatabaseTest;
24 import org.simantics.db.testing.common.TestBase;
25 import org.simantics.layer0.Layer0;
26
27 public class TransactionTest4 extends ExistingDatabaseTest {
28         @Test
29         @Fails
30         public void testTransaction4()
31         throws DatabaseException {
32             breakConnectionDuringTransaction();
33         }
34         void breakConnectionDuringTransaction() throws DatabaseException {
35             TransactionTest4Client client = new TransactionTest4Client(this);
36         try {
37             client.syntheticBreakDuringCreateResource();
38         } catch (Throwable t) {
39                 if (DEBUG)
40                         t.printStackTrace();
41         } finally {
42             if (null != client)
43                 client.close();
44         }
45             TransactionTest4Client client2 = new TransactionTest4Client(this);
46         try {
47             client2.readQuery();
48         } finally {
49             if (null != client2)
50                 client2.close();
51         }
52         }
53 }
54
55 class TransactionTest4Client extends TransctionCommon {
56     TransactionTest4Client(ExistingDatabaseTest testCommon)
57     throws DatabaseException {
58         super(testCommon);
59     }
60     public Resource syntheticBreakDuringCreateResource()
61     throws DatabaseException {
62         return session.syncRequest(new WriteResultRequest<Resource>() {
63             @Override
64             public Resource perform(WriteGraph g) throws DatabaseException {
65                 Layer0 b = Layer0.getInstance(g);
66                 Resource r = g.newResource();
67                 g.claim(r, b.InstanceOf, b.Entity);
68                 session.getService(XSupport.class).flushCluster(r);
69                 try {
70                                         Thread.sleep(1000); // millisecond
71                                 } catch (InterruptedException e) {
72                                         if (DEBUG)
73                                                 e.printStackTrace();
74                                 }
75                 session.getService(XSupport.class).breakConnection();
76                 return r;
77             }
78         });
79     }
80     public void readQuery()
81     throws DatabaseException {
82         session.syncRequest(new ReadRequest() {
83             @Override
84             public void run(ReadGraph g) throws DatabaseException {
85                 Layer0 l0 = Layer0.getInstance(g);
86                 Resource rl = g.getResource(TestBase.ROOT_LIBRARY_URI);
87                 for (Resource r : g.getObjects(rl, l0.ConsistsOf))
88                         if (DEBUG)
89                                 System.out.println("Root library " + rl + " consists  of " + r);
90             }
91         });
92     }
93 }