/******************************************************************************* * 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 * */ public class CleanShutdownTest2 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(CleanShutdownTest2.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.getTestHandler().getSession().syncRequest(new TestReadRequest() { @Override public void run(ReadGraph g) throws DatabaseException { Layer0 b = Layer0.getInstance(g); Collection resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf); // kill the core in the middle of a read transaction Tests.killCore(); 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"); } }