X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fclient%2FTransactionTest4.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fclient%2FTransactionTest4.java;h=0ada0951f727f7f0581a91408e272549eb3642e9;hb=67fd62f9c742337ec80eef658192db198a0efaac;hp=0000000000000000000000000000000000000000;hpb=cde82ba81327d5515fdca362f7f4c70f5103ae80;p=simantics%2Fplatform.git diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/TransactionTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/TransactionTest4.java new file mode 100644 index 000000000..0ada0951f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/TransactionTest4.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * 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 org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.XSupport; +import org.simantics.db.testing.annotation.Fails; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.TestBase; +import org.simantics.layer0.Layer0; + +public class TransactionTest4 extends ExistingDatabaseTest { + @Test + @Fails + public void testTransaction4() + throws DatabaseException { + breakConnectionDuringTransaction(); + } + void breakConnectionDuringTransaction() throws DatabaseException { + TransactionTest4Client client = new TransactionTest4Client(this); + try { + client.syntheticBreakDuringCreateResource(); + } catch (Throwable t) { + if (DEBUG) + t.printStackTrace(); + } finally { + if (null != client) + client.close(); + } + TransactionTest4Client client2 = new TransactionTest4Client(this); + try { + client2.readQuery(); + } finally { + if (null != client2) + client2.close(); + } + } +} + +class TransactionTest4Client extends TransctionCommon { + TransactionTest4Client(ExistingDatabaseTest testCommon) + throws DatabaseException { + super(testCommon); + } + public Resource syntheticBreakDuringCreateResource() + throws DatabaseException { + return session.syncRequest(new WriteResultRequest() { + @Override + public Resource perform(WriteGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + Resource r = g.newResource(); + g.claim(r, b.InstanceOf, b.Entity); + session.getService(XSupport.class).flushCluster(r); + try { + Thread.sleep(1000); // millisecond + } catch (InterruptedException e) { + if (DEBUG) + e.printStackTrace(); + } + session.getService(XSupport.class).breakConnection(); + return r; + } + }); + } + public void readQuery() + throws DatabaseException { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + Resource rl = g.getResource(TestBase.ROOT_LIBRARY_URI); + for (Resource r : g.getObjects(rl, l0.ConsistsOf)) + if (DEBUG) + System.out.println("Root library " + rl + " consists of " + r); + } + }); + } +}