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 java.util.Collection;
16 import org.junit.Test;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.WriteGraph;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.testing.annotation.Fails;
22 import org.simantics.db.testing.common.TestBase;
23 import org.simantics.db.testing.common.Tests;
24 import org.simantics.db.testing.common.WriteQuery;
25 import org.simantics.layer0.Layer0;
27 * Tests if session can be closed after core crash.
28 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
31 public class CleanShutdownTest2 extends TestBase {
32 private boolean completed = false;
35 public void testShutdown() throws Exception {
37 Thread t = new Thread() {
41 Tests.getTestHandler().getSession().syncRequest(new WriteQuery(CleanShutdownTest2.this) {
43 public void run(WriteGraph g) throws DatabaseException {
44 Layer0 b = Layer0.getInstance(g);
45 Resource instance = g.newResource();
46 g.claim(g.getRootLibrary(), b.ConsistsOf, instance);
47 g.claim(instance, b.InstanceOf, null, b.Type);
48 g.claimLiteral(instance, b.HasName, "Name");
51 } catch (DatabaseException e1) {
56 Tests.getTestHandler().getSession().syncRequest(new TestReadRequest() {
58 public void run(ReadGraph g) throws DatabaseException {
59 Layer0 b = Layer0.getInstance(g);
60 Collection<Resource> resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf);
61 // kill the core in the middle of a read transaction
63 for (Resource r : resources) {
64 g.getRelatedValue(r, b.HasName);
68 } catch (Exception e) {
69 // this is the correct behavior for this test
72 Tests.closeSession(Tests.getTestHandler().getSession());
73 } catch (DatabaseException e) {
81 for (int i = 0; i < 30; i++) {
84 } catch (InterruptedException e) {
91 throw new Exception("Core did not shutdown in 30 seconds");