X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fscalability%2FLargeCommitTest.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fscalability%2FLargeCommitTest.java;h=53bb61325db101001b77df3698c6efcdbbcbe7d7;hb=67fd62f9c742337ec80eef658192db198a0efaac;hp=0000000000000000000000000000000000000000;hpb=cde82ba81327d5515fdca362f7f4c70f5103ae80;p=simantics%2Fplatform.git diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/LargeCommitTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/LargeCommitTest.java new file mode 100644 index 000000000..53bb61325 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/scalability/LargeCommitTest.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * 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.Collection; +import java.util.UUID; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; + +public class LargeCommitTest extends ExistingDatabaseTest { + + private static final int OUTER_INSTANCE_COUNT = 10; // these go to the root library + private static final int INNER_INSTANCE_COUNT = 100; // these are for each outer instance + + /** + * Creates new type and new instance of it. Then tries to find the instance and the type, and verifies that inheritance is correct. + * @throws Exception + */ + @Test + public void testCommit() throws Exception{ + Session session = getSession(); + final Resource rootLib = getSession().getRootLibrary(); + final String random = UUID.randomUUID().toString(); + final String newTypeName = "New Type" + random; + session.syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + Resource newType = g.newResource(); + g.claim(newType, b.InstanceOf, null, b.Type); + g.claim(newType, b.Inherits, b.SupertypeOf, b.Type); + g.claimLiteral(newType, b.HasName, newTypeName); + g.claim(rootLib, b.ConsistsOf, newType); + + for (int i=0; i resources = g.getObjects(rootLib, b.ConsistsOf); + Resource newType = null; + Resource newInstance[] = new Resource[OUTER_INSTANCE_COUNT]; + for (Resource r : resources) { + String name = g.getPossibleRelatedValue(r, b.HasName); + if (null == name) + continue; + if (name.equals(newTypeName)) { + newType = r; + } + if (!name.startsWith(random, 0)) + continue; + name = name.substring(random.length()); + int index = 0; + try { + index = Integer.parseInt(name); + } catch (NumberFormatException e) { + continue; // not a number + } + if (index > 0 && index < OUTER_INSTANCE_COUNT+1) { + newInstance[index-1] = r; + } + } + if (newType == null) + throw new Exception("Could not find created type"); + for (int i=0; i