X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fclient%2FCleanShutdownTest2.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fclient%2FCleanShutdownTest2.java;h=6dfff02c8913b965560bb166d33c17558c2c1f49;hb=67fd62f9c742337ec80eef658192db198a0efaac;hp=0000000000000000000000000000000000000000;hpb=cde82ba81327d5515fdca362f7f4c70f5103ae80;p=simantics%2Fplatform.git diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CleanShutdownTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CleanShutdownTest2.java new file mode 100644 index 000000000..6dfff02c8 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CleanShutdownTest2.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * 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"); + } + +}