]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.db.tests/src/org/simantics/db/tests/client/TransactionTest4.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / client / TransactionTest4.java
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 (file)
index 0000000..0ada095
--- /dev/null
@@ -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<Resource>() {
+            @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);
+            }
+        });
+    }
+}