1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.tests.api.support.clusterControl;
14 import java.util.Collection;
16 import org.junit.Test;
17 import org.simantics.databoard.Bindings;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.WriteOnlyGraph;
22 import org.simantics.db.common.request.WriteOnlyResultRequest;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.db.service.ClusterControl;
25 import org.simantics.db.testing.base.ExistingDatabaseTest;
26 import org.simantics.db.testing.common.WriteQuery;
27 import org.simantics.layer0.Layer0;
30 * Creates large amount of instances in multiple transactions
31 * and the tries to verify that instances are written into the database.
33 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
36 public class WriteAfterClusterCollectTest extends ExistingDatabaseTest {
38 public void test() throws Exception{
40 // final Resource rootLib = getRootLibrary();
41 final String random = getRandomString();
43 final Resource rootLib = getSession().syncRequest(new WriteOnlyResultRequest<Resource>() {
45 public Resource perform(WriteOnlyGraph g) throws DatabaseException {
46 Resource rootLib = g.newResource();
47 for (int i = 0; i < 1000; i++) {
48 Layer0 b = Layer0.getInstance(getSession());
49 String newInstanceName = random + i;
50 Resource instance = g.newResource();
51 g.claim(instance, b.InstanceOf, null, b.Type);
52 g.addLiteral(instance, b.HasName, b.NameOf, b.String, newInstanceName, Bindings.STRING);
53 g.claim(rootLib, b.ConsistsOf, b.PartOf, instance);
61 getSession().syncRequest(new TestReadRequest() {
63 public void run(ReadGraph g) throws Throwable {
64 Layer0 b = Layer0.getInstance(g);
65 Collection<Resource> resources = g.getObjects(rootLib, b.ConsistsOf);
66 for (Resource r : resources) {
67 String name = g.getPossibleRelatedValue(r, b.HasName);
69 System.out.println("Resource=" + r + " name=" + name);
74 ClusterControl support = getSession().getService(ClusterControl.class);
75 support.collectClusters(Integer.MAX_VALUE);
79 getSession().syncRequest(new WriteQuery(this) {
81 public void run(WriteGraph g) throws Throwable {
83 Layer0 b = Layer0.getInstance(g);
84 Collection<Resource> resources = g.getObjects(rootLib, b.ConsistsOf);
85 for (Resource r : resources) {
86 String name = g.getPossibleRelatedValue(r, b.HasName);
88 System.out.println("Resource=" + r + " name=" + name);
89 String newInstanceName = random;
90 Resource instance = g.newResource();
91 g.claimLiteral(instance, b.HasName, newInstanceName);
92 g.claim(r, b.ConsistsOf, b.PartOf, instance);