1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.tests.scalability;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.List;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.testing.base.ExistingDatabaseTest;
22 import org.simantics.db.testing.common.WriteQuery;
23 import org.simantics.layer0.Layer0;
26 * Creates large amount of instances in multiple transactions
27 * and the tries to verify that instances are written into the database.
29 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
32 public class LargeDataTest extends ExistingDatabaseTest {
34 private static int INSTANCE_COUNT = 1000; //100000
35 private static int MAX_INSTANCE_COUNT_PER_TRANSACTION = 100; // 1000;
36 private static boolean OPTIMIZED = false;
38 public void testLargeData() throws Exception{
39 final Resource rootLib = getSession().getRootLibrary();
40 final String random = getRandomString();
42 System.out.println("Test start");
43 for (int j = 0; j < INSTANCE_COUNT; j += MAX_INSTANCE_COUNT_PER_TRANSACTION) {
45 getSession().syncRequest(new WriteQuery(this) {
47 public void run(WriteGraph g) throws Throwable {
48 Layer0 b = Layer0.getInstance(g);
49 for (int i = 0; i < MAX_INSTANCE_COUNT_PER_TRANSACTION; i++) {
50 String newInstanceName = random + (base+i);
51 Resource instance = g.newResource();
53 g.claim(instance, b.InstanceOf, null, b.Type);
54 g.claimLiteral(instance, b.HasName, newInstanceName);
55 g.claim(rootLib, b.ConsistsOf, instance);
57 Resource invName = g.getInverse(b.HasName);
58 g.claim(instance, b.HasName, invName, b.Type);
59 g.claimLiteral(instance, b.HasName, newInstanceName);
60 g.claim(rootLib, b.ConsistsOf, b.PartOf, instance);
67 System.out.println(j + MAX_INSTANCE_COUNT_PER_TRANSACTION);
72 System.out.println("Reading stage");
73 getSession().syncRequest(new TestReadRequest() {
75 public void run(ReadGraph g) throws Throwable {
76 Layer0 b = Layer0.getInstance(g);
77 List<Boolean> found = new ArrayList<Boolean>(INSTANCE_COUNT);
78 for (int i = 0; i < INSTANCE_COUNT; i++) {
81 Collection<Resource> resources = g.getObjects(rootLib, b.ConsistsOf);
82 for (Resource r : resources) {
83 String name = g.getPossibleRelatedValue(r, b.HasName);
84 if (null == name || !name.startsWith(random, 0))
86 name = name.substring(random.length());
88 int i = Integer.parseInt(name);
91 } catch (NumberFormatException e) {
92 continue; // not a number
95 for (int i = 0; i < INSTANCE_COUNT; i++) {
97 throw new Exception("Created resource " + i + " cannot be found");
102 System.out.println("test done");