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.client;
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;
27 public class TransactionTest4 extends ExistingDatabaseTest {
30 public void testTransaction4()
31 throws DatabaseException {
32 breakConnectionDuringTransaction();
34 void breakConnectionDuringTransaction() throws DatabaseException {
35 TransactionTest4Client client = new TransactionTest4Client(this);
37 client.syntheticBreakDuringCreateResource();
38 } catch (Throwable t) {
45 TransactionTest4Client client2 = new TransactionTest4Client(this);
55 class TransactionTest4Client extends TransctionCommon {
56 TransactionTest4Client(ExistingDatabaseTest testCommon)
57 throws DatabaseException {
60 public Resource syntheticBreakDuringCreateResource()
61 throws DatabaseException {
62 return session.syncRequest(new WriteResultRequest<Resource>() {
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);
70 Thread.sleep(1000); // millisecond
71 } catch (InterruptedException e) {
75 session.getService(XSupport.class).breakConnection();
80 public void readQuery()
81 throws DatabaseException {
82 session.syncRequest(new ReadRequest() {
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))
89 System.out.println("Root library " + rl + " consists of " + r);