--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.tests.client;
+
+import java.util.Collection;
+
+import org.junit.Test;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.annotation.Fails;
+import org.simantics.db.testing.common.TestBase;
+import org.simantics.db.testing.common.Tests;
+import org.simantics.db.testing.common.WriteQuery;
+import org.simantics.layer0.Layer0;
+/**
+ * Tests if session can be closed after core crash.
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ *
+ */
+public class CleanShutdownTest extends TestBase {
+ private boolean completed = false;
+
+ @Test
+ @Fails
+ public void testShutdown() throws Exception {
+ completed = false;
+ Thread t = new Thread() {
+ @Override
+ public void run() {
+ try {
+ Tests.getTestHandler().getSession().syncRequest(new WriteQuery(CleanShutdownTest.this) {
+ @Override
+ public void run(WriteGraph g) throws DatabaseException {
+ Layer0 b = Layer0.getInstance(g);
+ Resource instance = g.newResource();
+ g.claim(g.getRootLibrary(), b.ConsistsOf, instance);
+ g.claim(instance, b.InstanceOf, null, b.Type);
+ g.claimLiteral(instance, b.HasName, "Name");
+ }
+ });
+ } catch (DatabaseException e1) {
+ e1.printStackTrace();
+ }
+ try {
+ Tests.killCore(); // kill the core before read transaction
+ } catch (DatabaseException e1) {
+ fail("Killing core failed: " + e1.getMessage());
+ }
+ try {
+ Tests.getTestHandler().getSession().syncRequest(new TestReadRequest() {
+ @Override
+ public void run(ReadGraph g) throws DatabaseException {
+ Layer0 b = Layer0.getInstance(g);
+ Collection<Resource> resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf);
+ for (Resource r : resources) {
+ g.getRelatedValue(r, b.HasName);
+ }
+ }
+ });
+ } catch (Exception e) {
+ // this is the correct behavior for this test
+ }
+ try {
+ Tests.closeSession(Tests.getTestHandler().getSession());
+ } catch (DatabaseException e) {
+ e.printStackTrace();
+ }
+ completed = true;
+ }
+ };
+ t.start();
+
+ for (int i = 0; i < 30; i++) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+
+ }
+ if (completed)
+ break;
+ }
+ if (!completed)
+ throw new Exception("Core did not shutdown in 30 seconds");
+ }
+
+}