]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue2967Test1.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / regression / bugs / Issue2967Test1.java
diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue2967Test1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue2967Test1.java
new file mode 100644 (file)
index 0000000..b0b96d0
--- /dev/null
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * 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<Resource>() {
+                    @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<N_RESOURCE; ++i) {
+                            Resource r = graph.newResource();
+                            graph.addLiteral(r, L0.HasName, L0.NameOf, L0.String, "Resource" + i, Bindings.STRING);
+                            graph.claim(newResource, L0.ConsistsOf, r);
+                            for (int j=0; j<N_STM; ++j) {
+                                Resource rr = graph.newResource();
+                                graph.claim(rr, L0.InstanceOf, L0.Entity);
+                                graph.claim(r, L0.HasComment, rr);
+                            }
+                        }
+                    }
+                });
+                final DataContainer<Boolean> ok = new DataContainer<Boolean>();
+                ok.set(false);
+                Collection<Resource> 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<Resource> 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<N_RESOURCE; ++i) {
+                            Resource r = graph.getResource("http://RootLibrary/Resource" + i);
+                            assertNotNull("Failed to find created resource.", r);
+                        }
+                        ok.set(true);
+                    }
+                });
+                assertEquals("Virtual graph data has changed.", true, (boolean)ok.get());
+            }
+        });
+    }
+
+}