]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/CreateManyClustersTest.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / scalability / CreateManyClustersTest.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 CreateManyClustersTest extends ExistingDatabaseTest {
25         
26         final static int CLUSTERS = Configuration.get().cachedClusterCount;
27         
28         private Throwable exception; 
29         private Resource rootResource = null;
30         
31         public void test() throws Exception {
32                 
33                 Session session = getSession();
34                 
35                 session.syncRequest(new WriteQuery(this) {
36                         @Override
37                         public void run(WriteGraph g) throws Throwable {
38                                 Layer0 b = Layer0.getInstance(g);
39                                 rootResource = g.newResource();
40                                 g.claim(g.getRootLibrary(), b.ConsistsOf, rootResource);
41                         }
42                 });
43
44                 session.syncRequest(new WriteRequest() {
45
46                         @Override
47                         public void perform(WriteGraph graph) throws DatabaseException {
48                                 
49                                 
50
51                                 try {
52
53                                         Layer0 b = Layer0.getInstance(graph);
54
55                                         for(int i=0;i<CLUSTERS;i++) {
56                                                 
57                                                 graph.flushCluster();
58                                                 Resource newResource = graph.newResource();
59                                                 graph.claim(rootResource, b.ConsistsOf, newResource);
60                                                 
61                                         }
62                                         
63                                 } catch (Throwable t) {
64                                         exception = t;
65                                 }
66
67                         }
68                         
69                 });
70                 
71                 if(exception != null) {
72                         exception.printStackTrace();
73                         fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through ");
74                 }
75                 
76         }
77
78 }