/******************************************************************************* * 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.regression.bugs; import java.util.Collection; import java.util.UUID; import org.junit.Test; import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.VirtualGraph; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.request.WriteResultRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.service.VirtualGraphSupport; import org.simantics.db.testing.annotation.Fails; import org.simantics.db.testing.cases.FreshDatabaseTest; import org.simantics.layer0.Layer0; import org.simantics.utils.DataContainer; public class Issue2967Test1 extends FreshDatabaseTest { private int N_RESOURCE = 10000; private int N_STM = 100; @Test @Fails public void test() throws DatabaseException { Session session = getSession(); session.syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); final Resource newResource = graph.syncRequest(new WriteResultRequest() { @Override public Resource perform(WriteGraph graph) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); Resource result = graph.newResource(); graph.addLiteral(result, L0.HasName, L0.NameOf, L0.String, "RootLibrary", Bindings.STRING); Resource root = graph.getRootLibrary(); graph.claim(root, L0.ConsistsOf, result); return result; } }); String rootName = graph.getRelatedValue(newResource, L0.HasName); assertTrue("Failed to set resource name.", rootName.equals("RootLibrary")); VirtualGraphSupport support = graph.getSession().getService(VirtualGraphSupport.class); final String name = UUID.randomUUID().toString(); final VirtualGraph virtual = support.getMemoryPersistent(name); graph.syncRequest(new WriteRequest(virtual) { @Override public void perform(WriteGraph graph) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); for (int i=0; i ok = new DataContainer(); ok.set(false); Collection resources = graph.getObjects(newResource, L0.ConsistsOf); if (resources.size() != N_RESOURCE) fail("Virtual graph data has changed. Object size mismatch. size=" + resources.size()); for (Resource r : resources) { Collection ress = graph.getObjects(r, L0.HasComment); assertEquals("Virtual graph has changed.", N_STM, ress.size()); } graph.syncRequest(new WriteRequest(virtual) { @Override public void perform(WriteGraph graph) throws DatabaseException { for (int i=0; i