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.regression.bugs;
14 import java.util.Collection;
15 import java.util.UUID;
17 import org.junit.Test;
18 import org.simantics.databoard.Bindings;
19 import org.simantics.db.Resource;
20 import org.simantics.db.Session;
21 import org.simantics.db.VirtualGraph;
22 import org.simantics.db.WriteGraph;
23 import org.simantics.db.common.request.WriteRequest;
24 import org.simantics.db.common.request.WriteResultRequest;
25 import org.simantics.db.exception.DatabaseException;
26 import org.simantics.db.service.VirtualGraphSupport;
27 import org.simantics.db.testing.annotation.Fails;
28 import org.simantics.db.testing.cases.FreshDatabaseTest;
29 import org.simantics.layer0.Layer0;
30 import org.simantics.utils.DataContainer;
32 public class Issue2967Test1 extends FreshDatabaseTest {
34 private int N_RESOURCE = 10000;
35 private int N_STM = 100;
39 public void test() throws DatabaseException {
40 Session session = getSession();
41 session.syncRequest(new WriteRequest() {
43 public void perform(WriteGraph graph) throws DatabaseException {
44 Layer0 L0 = Layer0.getInstance(graph);
45 final Resource newResource = graph.syncRequest(new WriteResultRequest<Resource>() {
47 public Resource perform(WriteGraph graph) throws DatabaseException {
48 Layer0 L0 = Layer0.getInstance(graph);
49 Resource result = graph.newResource();
50 graph.addLiteral(result, L0.HasName, L0.NameOf, L0.String, "RootLibrary", Bindings.STRING);
51 Resource root = graph.getRootLibrary();
52 graph.claim(root, L0.ConsistsOf, result);
56 String rootName = graph.getRelatedValue(newResource, L0.HasName);
57 assertTrue("Failed to set resource name.", rootName.equals("RootLibrary"));
58 VirtualGraphSupport support = graph.getSession().getService(VirtualGraphSupport.class);
59 final String name = UUID.randomUUID().toString();
60 final VirtualGraph virtual = support.getMemoryPersistent(name);
61 graph.syncRequest(new WriteRequest(virtual) {
63 public void perform(WriteGraph graph) throws DatabaseException {
64 Layer0 L0 = Layer0.getInstance(graph);
65 for (int i=0; i<N_RESOURCE; ++i) {
66 Resource r = graph.newResource();
67 graph.addLiteral(r, L0.HasName, L0.NameOf, L0.String, "Resource" + i, Bindings.STRING);
68 graph.claim(newResource, L0.ConsistsOf, r);
69 for (int j=0; j<N_STM; ++j) {
70 Resource rr = graph.newResource();
71 graph.claim(rr, L0.InstanceOf, L0.Entity);
72 graph.claim(r, L0.HasComment, rr);
77 final DataContainer<Boolean> ok = new DataContainer<Boolean>();
79 Collection<Resource> resources = graph.getObjects(newResource, L0.ConsistsOf);
80 if (resources.size() != N_RESOURCE)
81 fail("Virtual graph data has changed. Object size mismatch. size=" + resources.size());
82 for (Resource r : resources) {
83 Collection<Resource> ress = graph.getObjects(r, L0.HasComment);
84 assertEquals("Virtual graph has changed.", N_STM, ress.size());
86 graph.syncRequest(new WriteRequest(virtual) {
88 public void perform(WriteGraph graph) throws DatabaseException {
89 for (int i=0; i<N_RESOURCE; ++i) {
90 Resource r = graph.getResource("http://RootLibrary/Resource" + i);
91 assertNotNull("Failed to find created resource.", r);
96 assertEquals("Virtual graph data has changed.", true, (boolean)ok.get());