X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fregression%2Fbugs%2FIssue3176Test1.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fregression%2Fbugs%2FIssue3176Test1.java;h=ecf0c7779bc5d608dcbe3c039619a281c9cfba92;hp=0000000000000000000000000000000000000000;hb=67fd62f9c742337ec80eef658192db198a0efaac;hpb=cde82ba81327d5515fdca362f7f4c70f5103ae80 diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3176Test1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3176Test1.java new file mode 100644 index 000000000..ecf0c7779 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3176Test1.java @@ -0,0 +1,318 @@ +/******************************************************************************* + * 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.regression.bugs; + +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ExternalValueSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ExternalValueException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.impl.Configuration; +import org.simantics.layer0.Layer0; + +public class Issue3176Test1 extends ExistingDatabaseTest { + static final boolean DEBUG = false; + @Test + public void testRaw() + throws DatabaseException { + try{ + int nBlocks = Configuration.get().i3176BlockCount; + int[] blockSize = { 1024, 0xFFFF, 1<<20 }; + final int LENGTH = blockSize.length; + for (int i=0; i() { + @Override + public Resource perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + Layer0 b = Layer0.getInstance(g); + Resource resource = g.newResource(); + g.claim(resource, b.InstanceOf, b.Entity); + return resource; + } + }); + } + protected void checkLiteralValue(final Resource resource) + throws DatabaseException { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + Resource literal = graph.getSingleObject(resource, l0.Literal); + // Note that graph.hasValue actually fetches the value from server. + // This is highly inefficient and thus do not use this kind of code! + if (!graph.hasValue(literal)) + throw new DatabaseException("Graph resource " + resource + " has no value."); + } + }); + } + protected void undoModi(final Resource resource, int n) + throws DatabaseException { + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + support.undo(session, n); + } + protected byte[] createBlock(int size, int inc) { + final byte block[] = new byte[size]; + for (int i = 0; i < block.length; ++i) + block[i] = (byte)(i+inc); + return block; + } + protected void removeLiteralValue(final Resource resource) + throws DatabaseException { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 l0 = Layer0.getInstance(graph); + Resource literal = graph.getSingleObject(resource, l0.Literal); + graph.denyValue(literal); + } + }); + } +} +class RawTest extends Issue3176Test { + private final ExternalValueSupport rds; + RawTest(final Session session, boolean DEBUG, int blockSize, int nBlocks) + throws DatabaseException { + super(session, DEBUG, blockSize, nBlocks); + this.rds = session.getService(ExternalValueSupport.class); + } + void createRaw(final Resource resource, final int inc, int aBlocks) + throws DatabaseException { + if (aBlocks < 0) + aBlocks = N_BLOCKS; + final int T_BLOCKS = aBlocks; + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 b = Layer0.getInstance(graph); + graph.claimLiteral(resource, b.Literal, new byte[0], Bindings.BYTE_ARRAY); + Resource literal = graph.getSingleObject(resource, b.Literal); + long count = 0; + for (int i=0, j=inc; i