--- /dev/null
+/*******************************************************************************
+ * 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.performance.read;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.VirtualGraph;
+import org.simantics.db.WriteOnlyGraph;
+import org.simantics.db.common.TransactionPolicyKeep;
+import org.simantics.db.common.WriteBindings;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.common.request.WriteOnlyResultRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.Read;
+import org.simantics.db.request.WriteOnlyResult;
+import org.simantics.db.service.TransactionPolicySupport;
+import org.simantics.db.testing.base.ExistingDatabaseTest;
+import org.simantics.layer0.Layer0;
+
+public class WriteReadBigLiteral extends ExistingDatabaseTest {
+
+ private static final int _100MB = 100000000;
+ private static final int _250MB = 250000000;
+ private static final int _500MB = 500000000;
+ private static final int _1000MB = 1000000000;
+ private static final int _2000MB = 2000000000;
+
+ private Resource time(String label, WriteOnlyResult<Resource> request) throws DatabaseException {
+
+ long start = System.nanoTime();
+ Resource result = getSession().syncRequest(request);
+ long duration = System.nanoTime() - start;
+ System.out.println(label + " = " + 1e-9*duration);
+ return result;
+
+ }
+
+ private void time(String label, Read<Object> request) throws DatabaseException {
+
+ long start = System.nanoTime();
+ getSession().syncRequest(request);
+ long duration = System.nanoTime() - start;
+ System.out.println(label + " = " + 1e-9*duration);
+
+ }
+
+ public static WriteOnlyResult<Resource> writeOnly(final int size, VirtualGraph graph) throws DatabaseException {
+
+ final byte[] literal = new byte[size];
+
+ return new WriteOnlyResultRequest<Resource>(graph) {
+
+ @Override
+ public Resource perform(WriteOnlyGraph graph) throws DatabaseException {
+ Resource res = graph.newResource();
+ graph.claimValue(res, literal, WriteBindings.BYTE_ARRAY);
+ return res;
+ }
+
+ };
+
+ }
+
+ public static Read<Object> read(final Resource resource) {
+
+ return new ReadRequest() {
+
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+
+ byte[] value = graph.getValue(resource, WriteBindings.BYTE_ARRAY);
+ System.err.println("value: " + value.length);
+
+ }
+
+ };
+
+ }
+
+ public void test() throws Exception {
+
+ Layer0.getInstance(getSession());
+
+ getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyKeep());
+
+ Resource root = time("write 100MB", writeOnly(_100MB, null));
+ time("response 100MB", read(root));
+ Resource root2 = time("write 250MB", writeOnly(_250MB, null));
+ time("response 250MB", read(root2));
+ Resource root3 = time("write 500MB", writeOnly(_500MB, null));
+ time("response 500MB", read(root3));
+ Resource root4 = time("write 1000MB", writeOnly(_1000MB, null));
+ time("response 1000MB", read(root4));
+ Resource root5 = time("write 2000MB", writeOnly(_2000MB, null));
+ time("response 2000MB", read(root5));
+
+
+//// System.out.println("wait");
+//// Thread.sleep(3000);
+//// System.out.println("wait done");
+//
+// // Read everything after write
+// time("response", HierarchicalNames.readAsync(root));
+//
+//// System.out.println("wait");
+//// Thread.sleep(3000);
+//// System.out.println("wait done");
+//
+// // Clusters are now loaded
+// time("async", HierarchicalNames.readAsync(root));
+//// time("async2", HierarchicalNames.readAsync2(root));
+//// time("sync", HierarchicalNames.readSync(root));
+//// listenTime("listenSync", HierarchicalNames.readSync(root));
+
+ }
+
+}