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.db.tests.common.Configuration;
28 import org.simantics.layer0.Layer0;
31 * Creates large amount of instances in multiple transactions
32 * and the tries to verify that instances are written into the database.
34 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
37 public class WriteAfterClusterCollectTest2 extends ExistingDatabaseTest {
38 private int LOOP = Configuration.get().collectedLoopCount;
40 public void test() throws Exception{
42 final String random = getRandomString();
44 final Resource rootLib = getSession().syncRequest(new WriteOnlyResultRequest<Resource>() {
46 public Resource perform(WriteOnlyGraph g) throws DatabaseException {
47 Resource rootLib = g.newResource();
48 for (int i = 0; i < 10; i++) {
49 for (int j = 0; j < LOOP; j++) {
50 Layer0 b = Layer0.getInstance(getSession());
51 String newInstanceName = random + i;
52 Resource instance = g.newResource();
53 g.claim(instance, b.InstanceOf, null, b.Type);
54 g.addLiteral(instance, b.HasName, b.NameOf, b.String, newInstanceName, Bindings.STRING);
55 g.claim(rootLib, b.ConsistsOf, b.PartOf, instance);
65 getSession().syncRequest(new TestReadRequest() {
67 public void run(ReadGraph g) throws Throwable {
68 Layer0 b = Layer0.getInstance(g);
69 Collection<Resource> resources = g.getObjects(rootLib, b.ConsistsOf);
70 for (Resource r : resources) {
71 String name = g.getPossibleRelatedValue(r, b.HasName);
73 System.out.println("Name is " + name);
78 ClusterControl support = getSession().getService(ClusterControl.class);
79 support.collectClusters(Integer.MAX_VALUE);
83 getSession().syncRequest(new WriteQuery(this) {
85 public void run(WriteGraph g) throws Throwable {
87 Layer0 b = Layer0.getInstance(g);
88 Collection<Resource> resources = g.getObjects(rootLib, b.ConsistsOf);
89 for (Resource r : resources) {
90 String name = g.getPossibleRelatedValue(r, b.HasName);
92 System.out.println("Name is " + name);
93 String newInstanceName = random;
94 Resource instance = g.newResource();
95 g.claimLiteral(instance, b.HasName, newInstanceName);
96 g.claim(r, b.ConsistsOf, b.PartOf, instance);
105 getSession().syncRequest(new TestReadRequest() {
107 public void run(ReadGraph g) throws Throwable {
108 Layer0 b = Layer0.getInstance(g);
109 Collection<Resource> resources = g.getObjects(rootLib, b.ConsistsOf);
110 for (Resource r : resources) {
111 String name = g.getPossibleRelatedValue(r, b.HasName);
113 System.out.println("Name is " + name);
120 support.collectClusters(Integer.MAX_VALUE);