X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fscalability%2FLargeDataTest.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fscalability%2FLargeDataTest.java;h=98a94cac4b64938e9157508fb080a9bae64e9c22;hb=67fd62f9c742337ec80eef658192db198a0efaac;hp=0000000000000000000000000000000000000000;hpb=cde82ba81327d5515fdca362f7f4c70f5103ae80;p=simantics%2Fplatform.git diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/LargeDataTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/LargeDataTest.java new file mode 100644 index 000000000..98a94cac4 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/LargeDataTest.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * 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 java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; + +/** + * Creates large amount of instances in multiple transactions + * and the tries to verify that instances are written into the database. + * + * @author Marko Luukkainen + * + */ +public class LargeDataTest extends ExistingDatabaseTest { + + private static int INSTANCE_COUNT = 1000; //100000 + private static int MAX_INSTANCE_COUNT_PER_TRANSACTION = 100; // 1000; + private static boolean OPTIMIZED = false; + + public void testLargeData() throws Exception{ + final Resource rootLib = getSession().getRootLibrary(); + final String random = getRandomString(); + if (DEBUG) + System.out.println("Test start"); + for (int j = 0; j < INSTANCE_COUNT; j += MAX_INSTANCE_COUNT_PER_TRANSACTION) { + final int base = j; + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + for (int i = 0; i < MAX_INSTANCE_COUNT_PER_TRANSACTION; i++) { + String newInstanceName = random + (base+i); + Resource instance = g.newResource(); + if(!OPTIMIZED) { + g.claim(instance, b.InstanceOf, null, b.Type); + g.claimLiteral(instance, b.HasName, newInstanceName); + g.claim(rootLib, b.ConsistsOf, instance); + } else { + Resource invName = g.getInverse(b.HasName); + g.claim(instance, b.HasName, invName, b.Type); + g.claimLiteral(instance, b.HasName, newInstanceName); + g.claim(rootLib, b.ConsistsOf, b.PartOf, instance); + } + } + + } + }); + if (DEBUG) + System.out.println(j + MAX_INSTANCE_COUNT_PER_TRANSACTION); + } + + checkException(); + if (DEBUG) + System.out.println("Reading stage"); + getSession().syncRequest(new TestReadRequest() { + @Override + public void run(ReadGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + List found = new ArrayList(INSTANCE_COUNT); + for (int i = 0; i < INSTANCE_COUNT; i++) { + found.add(false); + } + Collection resources = g.getObjects(rootLib, b.ConsistsOf); + for (Resource r : resources) { + String name = g.getPossibleRelatedValue(r, b.HasName); + if (null == name || !name.startsWith(random, 0)) + continue; + name = name.substring(random.length()); + try { + int i = Integer.parseInt(name); + found.set(i, true); + + } catch (NumberFormatException e) { + continue; // not a number + } + } + for (int i = 0; i < INSTANCE_COUNT; i++) { + if (!found.get(i)) + throw new Exception("Created resource " + i + " cannot be found"); + } + } + }); + if (DEBUG) + System.out.println("test done"); + checkException(); + } + +}