]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/LogTest.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / performance / read / LogTest.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.tests.performance.read;
13
14 import java.util.UUID;
15
16 import org.simantics.databoard.Bindings;
17 import org.simantics.datatypes.utils.LogUtils;
18 import org.simantics.db.Resource;
19 import org.simantics.db.Session;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.common.request.WriteResultRequest;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.db.service.VirtualGraphSupport;
24 import org.simantics.db.testing.base.ExistingDatabaseTest;
25
26
27 public class LogTest extends ExistingDatabaseTest {
28
29         public static final int NODE_SIZE = 2;
30         public static final int TEN = 10;
31         public static final int THOUSAND = 1000;
32         public static final int MILLION = 1000000;
33         
34         public static final int KEY_SIZE = TEN * 1000;
35         
36         public void test() throws Exception {
37                 
38                 Session session = getSession();
39                 
40                 VirtualGraphSupport vgss = session.getService(VirtualGraphSupport.class);
41
42                 long start = System.nanoTime();
43                 
44                 session.sync(new WriteResultRequest<Resource>(vgss.getMemoryPersistent(UUID.randomUUID().toString())) {
45
46                         @Override
47                         public Resource perform(WriteGraph graph) throws DatabaseException {
48                                 
49                                 LogUtils lu = new LogUtils(graph);
50                                 Resource log = lu.create(graph, NODE_SIZE, 0);
51                                 for(int i=0;i<KEY_SIZE;i++) {
52                                         Resource value = graph.newResource();
53                                         graph.claim(value, L0.InstanceOf, null, L0.String);
54                                         graph.claimValue(value, "Value" + i, Bindings.STRING);
55                                         lu.insert(graph, log, i, value);
56                                 }
57                                 return log;
58                                 
59                         }
60                         
61                 });
62                 
63                 long duration = System.nanoTime()-start;
64                 System.err.println("WRITE at " + 1e-9*duration + "s.");
65                 
66         }
67
68 }