X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fapi%2Fwrite%2FclaimValue%2FDataBlobTest.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fapi%2Fwrite%2FclaimValue%2FDataBlobTest.java;h=d80ddc1755d987896afe2c0d9852e8dd9189b751;hb=67fd62f9c742337ec80eef658192db198a0efaac;hp=0000000000000000000000000000000000000000;hpb=cde82ba81327d5515fdca362f7f4c70f5103ae80;p=simantics%2Fplatform.git diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimValue/DataBlobTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimValue/DataBlobTest.java new file mode 100644 index 000000000..d80ddc175 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimValue/DataBlobTest.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * 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.api.write.claimValue; + +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.WriteGraph; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.WriteQuery; +import org.simantics.layer0.Layer0; + +/** + * Creates large data array and stores it into the database. + * + * @author Marko Luukkainen + * + */ +public class DataBlobTest extends ExistingDatabaseTest { + + private static int ARRAY_SIZE = 1*1024*1024; // 60*1024*1024; + + @Test + public void testDataBlob() throws Exception{ + final Resource rootLib = getSession().getRootLibrary(); + final String random = UUID.randomUUID().toString(); + final String newInstanceName = "New Instance" + random; + if (DEBUG) + System.out.println("Test start"); + getSession().syncRequest(new WriteQuery(this) { + @Override + public void run(WriteGraph g) throws Throwable { + Layer0 b = Layer0.getInstance(g); + byte data[] = new byte[ARRAY_SIZE]; + for (int i = 0; i < data.length; i++) { + data[i] = (byte)(i % 2); + } + Resource instance = g.newResource(); + g.claim(instance, b.InstanceOf, null, b.Type); + g.claimLiteral(instance, b.HasName, newInstanceName); + g.claim(rootLib, b.ConsistsOf, instance); + + Resource prop = g.newResource(); + g.claim(prop, b.InstanceOf, b.ByteArray); + g.claimValue(prop, data); + + // Link it to the thing + g.claim(instance, b.HasProperty, prop); + } + }); + + + 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); + Collection resources = g.getObjects(rootLib, b.ConsistsOf); + for (Resource r : resources) { + String value = g.getPossibleRelatedValue(r, b.HasName); + if (null != value && value.equals(newInstanceName)) { + for (Resource p : g.getObjects(r, b.HasProperty)) + if (g.isInstanceOf(p, b.ByteArray)) { + byte[] data = g.getValue(p); + if (data.length != ARRAY_SIZE) + fail("Data blob lenght does not match."); + for (int i = 0; i < data.length; i++) { + if (data[i] != (byte)(i % 2)) + fail("Data blob content does not match."); + } + return; + } + } + } + fail("Data blob not found."); + } + }); + if (DEBUG) + System.out.println("test done"); + checkException(); + } + +}