]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.tests.scalability;
13
14 import org.simantics.db.Resource;
15 import org.simantics.db.Session;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.common.request.WriteRequest;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.db.testing.base.ExistingDatabaseTest;
20 import org.simantics.db.testing.common.WriteQuery;
21 import org.simantics.db.tests.common.Configuration;
22 import org.simantics.layer0.Layer0;
23
24 public class CreateManyClustersTest2 extends ExistingDatabaseTest {
25         
26         final static int ROUNDS = Configuration.get().cachedClusterRounds;
27         final static int CLUSTERS = Configuration.get().cachedClusterCount;
28         
29         private Throwable exception; 
30         private Resource rootResource = null;
31         
32         public void test() throws Exception {
33                 
34                 Session session = getSession();
35                 
36                 session.syncRequest(new WriteQuery(this) {
37                         @Override
38                         public void run(WriteGraph g) throws Throwable {
39                                 Layer0 b = Layer0.getInstance(g);
40                                 rootResource = g.newResource();
41                                 g.claim(g.getRootLibrary(), b.ConsistsOf, rootResource);
42                         }
43                 });
44
45                 for(int j=0;j<ROUNDS;j++) {
46
47                         session.syncRequest(new WriteRequest() {
48         
49                                 @Override
50                                 public void perform(WriteGraph graph) throws DatabaseException {
51                                         
52                                         try {
53         
54                                                 Layer0 b = Layer0.getInstance(graph);
55         
56                                                 for(int i=0;i<CLUSTERS;i++) {
57                                                         
58                                                         graph.flushCluster();
59                                                         Resource newResource = graph.newResource();
60                                                         graph.claim(rootResource, b.ConsistsOf, newResource);
61                                                         
62                                                 }
63                                                 
64                                         } catch (Throwable t) {
65                                                 exception = t;
66                                         }
67         
68                                 }
69                                 
70                         });
71                         
72                 }
73                 
74                 if(exception != null) {
75                         fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through ");
76                 }
77                 
78         }
79
80 }