]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/CreateManyClustersTest2.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / scalability / CreateManyClustersTest2.java
diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/CreateManyClustersTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/CreateManyClustersTest2.java
new file mode 100644 (file)
index 0000000..1138c00
--- /dev/null
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * 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.scalability;
+
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.base.ExistingDatabaseTest;
+import org.simantics.db.testing.common.WriteQuery;
+import org.simantics.db.tests.common.Configuration;
+import org.simantics.layer0.Layer0;
+
+public class CreateManyClustersTest2 extends ExistingDatabaseTest {
+       
+       final static int ROUNDS = Configuration.get().cachedClusterRounds;
+       final static int CLUSTERS = Configuration.get().cachedClusterCount;
+       
+       private Throwable exception; 
+       private Resource rootResource = null;
+       
+       public void test() throws Exception {
+               
+               Session session = getSession();
+               
+               session.syncRequest(new WriteQuery(this) {
+                       @Override
+                       public void run(WriteGraph g) throws Throwable {
+                               Layer0 b = Layer0.getInstance(g);
+                               rootResource = g.newResource();
+                               g.claim(g.getRootLibrary(), b.ConsistsOf, rootResource);
+                       }
+               });
+
+               for(int j=0;j<ROUNDS;j++) {
+
+                       session.syncRequest(new WriteRequest() {
+       
+                               @Override
+                               public void perform(WriteGraph graph) throws DatabaseException {
+                                       
+                                       try {
+       
+                                               Layer0 b = Layer0.getInstance(graph);
+       
+                                               for(int i=0;i<CLUSTERS;i++) {
+                                                       
+                                                       graph.flushCluster();
+                                                       Resource newResource = graph.newResource();
+                                                       graph.claim(rootResource, b.ConsistsOf, newResource);
+                                                       
+                                               }
+                                               
+                                       } catch (Throwable t) {
+                                               exception = t;
+                                       }
+       
+                               }
+                               
+                       });
+                       
+               }
+               
+               if(exception != null) {
+                       fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through ");
+               }
+               
+       }
+
+}