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 CleanShutdownTest extends TestBase {
32 private boolean completed = false;
36 public void testShutdown() throws Exception {
38 Thread t = new Thread() {
42 Tests.getTestHandler().getSession().syncRequest(new WriteQuery(CleanShutdownTest.this) {
44 public void run(WriteGraph g) throws DatabaseException {
45 Layer0 b = Layer0.getInstance(g);
46 Resource instance = g.newResource();
47 g.claim(g.getRootLibrary(), b.ConsistsOf, instance);
48 g.claim(instance, b.InstanceOf, null, b.Type);
49 g.claimLiteral(instance, b.HasName, "Name");
52 } catch (DatabaseException e1) {
56 Tests.killCore(); // kill the core before read transaction
57 } catch (DatabaseException e1) {
58 fail("Killing core failed: " + e1.getMessage());
61 Tests.getTestHandler().getSession().syncRequest(new TestReadRequest() {
63 public void run(ReadGraph g) throws DatabaseException {
64 Layer0 b = Layer0.getInstance(g);
65 Collection<Resource> resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf);
66 for (Resource r : resources) {
67 g.getRelatedValue(r, b.HasName);
71 } catch (Exception e) {
72 // this is the correct behavior for this test
75 Tests.closeSession(Tests.getTestHandler().getSession());
76 } catch (DatabaseException e) {
84 for (int i = 0; i < 30; i++) {
87 } catch (InterruptedException e) {
94 throw new Exception("Core did not shutdown in 30 seconds");