Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2006-10-27 17:55:15 -0400
committerEike Stepper2006-10-27 17:55:15 -0400
commitd58e62c0c8163cc0f578afdb3554ec00899c2e82 (patch)
tree7eb156695f289eb877b50527c2f9350a9c7df882 /plugins/org.eclipse.emf.cdo.tests/src
parent1b1109017d317774d076718344291828938034cc (diff)
downloadcdo-d58e62c0c8163cc0f578afdb3554ec00899c2e82.tar.gz
cdo-d58e62c0c8163cc0f578afdb3554ec00899c2e82.tar.xz
cdo-d58e62c0c8163cc0f578afdb3554ec00899c2e82.zip
Initial provisioning for v0.8.0
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.tests/src')
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllSuites.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFDetachTest.java131
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/IOHelper.java119
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/internal/CDOTestPlugin.java13
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AbstractModel1Test.java13
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AllTests.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/BidiReferencesTest.java283
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/Bugzilla154389Test.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/Bugzilla162017Test.java63
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/NotificationTest.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/SerializationTest.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/AbstractTopology.java92
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/AbstractTopologyTest.java116
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ClientSeparatedServerTopology.java103
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ClientServerTopology.java186
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ClientTopology.java31
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/EmbeddedTopology.java44
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ITopology.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ITopologyConstants.java18
19 files changed, 1015 insertions, 221 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllSuites.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllSuites.java
index 83ad15b56e..f5a5736b74 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllSuites.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllSuites.java
@@ -47,6 +47,7 @@ public class AllSuites extends TestSuite
protected void populateSuite()
{
+ // String mode = ITopologyConstants.EMBEDDED_MODE;
for (String mode : ITopologyConstants.SELF_CONTAINED_MODES)
{
TestSuite topologySuite = new TestSuite("Mode " + mode);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFDetachTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFDetachTest.java
new file mode 100644
index 0000000000..b10eafaf49
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFDetachTest.java
@@ -0,0 +1,131 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.tests;
+
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EFactory;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.change.ChangeDescription;
+import org.eclipse.emf.ecore.change.util.ChangeRecorder;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
+
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+
+public class EMFDetachTest extends TestCase
+{
+ private EClass treeNodeClass;
+
+ private EAttribute nameAttribute;
+
+ private EReference childrenReference;
+
+ private EPackage modelPackage;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ treeNodeClass = EcoreFactory.eINSTANCE.createEClass();
+ treeNodeClass.setName("TreeNode");
+
+ nameAttribute = EcoreFactory.eINSTANCE.createEAttribute();
+ nameAttribute.setName("nameAttribute");
+ nameAttribute.setEType(EcorePackage.eINSTANCE.getEString());
+
+ childrenReference = EcoreFactory.eINSTANCE.createEReference();
+ childrenReference.setName("childrenReference");
+ childrenReference.setEType(treeNodeClass);
+ childrenReference.setContainment(true);
+ childrenReference.setLowerBound(0);
+ childrenReference.setUpperBound(-1);
+
+ treeNodeClass.getEStructuralFeatures().add(nameAttribute);
+ treeNodeClass.getEStructuralFeatures().add(childrenReference);
+
+ modelPackage = EcoreFactory.eINSTANCE.createEPackage();
+ modelPackage.setName("modelPackage");
+ modelPackage.setNsPrefix("modelPackage");
+ modelPackage.setNsURI("http://modelPackage");
+ modelPackage.getEClassifiers().add(treeNodeClass);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ modelPackage = null;
+ childrenReference = null;
+ nameAttribute = null;
+ treeNodeClass = null;
+ super.tearDown();
+ }
+
+ public void testDetachSingle()
+ {
+ EObject root = createNode("root", null);
+ for (int i = 0; i < 5; i++)
+ {
+ createNode("child" + i, root);
+ }
+
+ Resource resource = new ResourceImpl();
+ resource.getContents().add(root);
+
+ System.out.println();
+ ChangeRecorder recorder = new ChangeRecorder(root);
+ removeNode(root, 2);
+ ChangeDescription changeDescription = recorder.endRecording();
+
+ System.out.println();
+ EList objectsToAttach = changeDescription.getObjectsToAttach();
+ for (Iterator it = objectsToAttach.iterator(); it.hasNext();)
+ {
+ EObject node = (EObject) it.next();
+ System.out.println("Node to attach: " + node.eGet(nameAttribute));
+
+ }
+
+ assertEquals(1, objectsToAttach.size());
+ }
+
+ private EObject createNode(String name, EObject parent)
+ {
+ EFactory factory = modelPackage.getEFactoryInstance();
+ EObject node = factory.create(treeNodeClass);
+ node.eSet(nameAttribute, name);
+
+ if (parent != null)
+ {
+ EList children = (EList) parent.eGet(childrenReference);
+ children.add(node);
+ }
+
+ System.out.println("Created node " + name);
+ return node;
+ }
+
+ private void removeNode(EObject parent, int index)
+ {
+ EList children = (EList) parent.eGet(childrenReference);
+ EObject child = (EObject) children.remove(index);
+ System.out.println("Removed node " + child.eGet(nameAttribute));
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/IOHelper.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/IOHelper.java
new file mode 100644
index 0000000000..096661aae7
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/IOHelper.java
@@ -0,0 +1,119 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.tests;
+
+
+import org.eclipse.net4j.util.IOUtil;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+
+
+public class IOHelper
+{
+ /**
+ * Copy chars from a <code>Reader</code> to a <code>Writer</code>.
+ *
+ * @param bufferSize
+ * Size of internal buffer to use.
+ */
+ public static void copy(Reader input, Writer output, int bufferSize) throws IOException
+ {
+ char buffer[] = new char[bufferSize];
+ int n = 0;
+ while ((n = input.read(buffer)) != -1)
+ {
+ output.write(buffer, 0, n);
+ }
+ }
+
+ public static void copy(InputStream input, OutputStream output, byte buffer[]) throws IOException
+ {
+ int n = 0;
+ while ((n = input.read(buffer)) != -1)
+ {
+ output.write(buffer, 0, n);
+ }
+ }
+
+ public static void copy(InputStream input, OutputStream output, int bufferSize)
+ throws IOException
+ {
+ copy(input, output, new byte[bufferSize]);
+ }
+
+ public static void copy(InputStream input, OutputStream output) throws IOException
+ {
+ copy(input, output, 4096);
+ }
+
+ public static void copy(File input, File output) throws IOException
+ {
+ FileInputStream fis = null;
+ FileOutputStream fos = null;
+ try
+ {
+ fis = new FileInputStream(input);
+ fos = new FileOutputStream(output);
+
+ copy(fis, fos);
+ }
+ finally
+ {
+ IOUtil.closeSilent(fis);
+ IOUtil.closeSilent(fos);
+ }
+ }
+
+ /**
+ * Read fully from reader
+ */
+ public static String readFully(Reader reader) throws IOException
+ {
+ StringWriter writer = new StringWriter();
+ copy(reader, writer, 1024);
+ return writer.toString();
+ }
+
+ /**
+ * Read fully from stream
+ */
+ public static String readFully(InputStream input) throws IOException
+ {
+ InputStreamReader reader = new InputStreamReader(input);
+ return readFully(reader);
+ }
+
+ /**
+ * Read fully from file
+ */
+ public static String readFully(File file) throws IOException
+ {
+ FileInputStream stream = null;
+ try
+ {
+ stream = new FileInputStream(file);
+ return readFully(stream);
+ }
+ finally
+ {
+ IOUtil.closeSilent(stream);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/internal/CDOTestPlugin.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/internal/CDOTestPlugin.java
index fa86dcf44d..dceb8de298 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/internal/CDOTestPlugin.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/internal/CDOTestPlugin.java
@@ -11,10 +11,11 @@
package org.eclipse.emf.cdo.tests.internal;
-import org.eclipse.net4j.util.eclipse.AbstractPlugin;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
-public class CDOTestPlugin extends AbstractPlugin
+public class CDOTestPlugin implements BundleActivator
{
private static CDOTestPlugin instance;
@@ -28,4 +29,12 @@ public class CDOTestPlugin extends AbstractPlugin
{
return instance;
}
+
+ public void start(BundleContext context) throws Exception
+ {
+ }
+
+ public void stop(BundleContext context) throws Exception
+ {
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AbstractModel1Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AbstractModel1Test.java
index 4894da5286..d64151f0f8 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AbstractModel1Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AbstractModel1Test.java
@@ -177,6 +177,19 @@ public abstract class AbstractModel1Test extends AbstractTopologyTest
return node;
}
+ protected void createTree(ExtendedNode root, int levels, int children)
+ {
+ String name = root.getStringFeature();
+ for (int i = 0; i < children; i++)
+ {
+ ExtendedNode child = createExtended(name + (i + 1), root);
+ if (levels > 1)
+ {
+ createTree(child, levels - 1, children);
+ }
+ }
+ }
+
protected TreeNode findChild(String name, TreeNode parent)
{
return findNode(name, parent.getChildren());
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AllTests.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AllTests.java
index 4b5fdd1b27..cf250fcd48 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AllTests.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AllTests.java
@@ -28,7 +28,10 @@ public class AllTests
suite.addTestSuite(XRefsTest.class);
suite.addTestSuite(ExtentTest.class);
suite.addTestSuite(OCLTest.class);
+ suite.addTestSuite(BidiReferencesTest.class);
suite.addTestSuite(Bugzilla154389Test.class);
+ suite.addTestSuite(Bugzilla155899Test.class);
+ suite.addTestSuite(Bugzilla162017Test.class);
return suite;
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/BidiReferencesTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/BidiReferencesTest.java
new file mode 100644
index 0000000000..3ab026f6f4
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/BidiReferencesTest.java
@@ -0,0 +1,283 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.tests.model1;
+
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+
+import testmodel1.ExtendedNode;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+
+public class BidiReferencesTest extends AbstractModel1Test
+{
+ private static final int LEVELS = 3;
+
+ private static final int CHILDREN = 4;
+
+ private static final int NODECOUNT = getNodeCount(LEVELS, CHILDREN);
+
+ private static final int CHILDCOUNT = NODECOUNT - 1;
+
+ public void testBasicTree() throws Exception
+ {
+ ExtendedNode created = createExtended("node");
+ createTree(created, LEVELS, CHILDREN);
+ saveRoot(created, "/test/resource");
+
+ ExtendedNode loaded = (ExtendedNode) loadRoot("/test/resource");
+ assertTree("node", loaded, LEVELS, CHILDREN);
+
+ assertEquals(1, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_RESOURCE"));
+ assertEquals(NODECOUNT, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_OBJECT"));
+ assertEquals(NODECOUNT, jdbc().queryForInt("SELECT COUNT(*) FROM EXTENDED_NODE"));
+ assertEquals(CHILDCOUNT * 2, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE"));
+ assertEquals(CHILDCOUNT, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE WHERE CONTENT"));
+ }
+
+ public void testBasicBidis() throws Exception
+ {
+ ExtendedNode created = createExtended("node");
+ createTree(created, LEVELS, CHILDREN);
+ createBidi(created, "111", "211");
+ createBidi(created, "111", "212");
+ createBidi(created, "111", "213");
+ createBidi(created, "111", "311");
+ createBidi(created, "111", "312");
+ createBidi(created, "111", "313");
+ saveRoot(created, "/test/resource");
+
+ ExtendedNode loaded = (ExtendedNode) loadRoot("/test/resource");
+ assertTree("node", loaded, LEVELS, CHILDREN);
+ assertBidi(loaded, "111", "211");
+ assertBidi(loaded, "111", "212");
+ assertBidi(loaded, "111", "213");
+ assertBidi(loaded, "111", "311");
+ assertBidi(loaded, "111", "312");
+ assertBidi(loaded, "111", "313");
+
+ assertEquals(1, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_RESOURCE"));
+ assertEquals(NODECOUNT, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_OBJECT"));
+ assertEquals(NODECOUNT, jdbc().queryForInt("SELECT COUNT(*) FROM EXTENDED_NODE"));
+ assertEquals(CHILDCOUNT * 2 + 6 * 2, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE"));
+ assertEquals(CHILDCOUNT, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE WHERE CONTENT"));
+ }
+
+ public void testDetachCount() throws Exception
+ {
+ ExtendedNode created = createExtended("node"); // root node
+ createTree(created, LEVELS, CHILDREN); // tree of degree 4, height = root + 3
+ saveRoot(created, "/test/resource"); // commit
+ int expected = NODECOUNT;
+ assertEquals(expected, getNodeCount(created));
+ created.cdoGetResource().getResourceManager().close();
+
+ ExtendedNode loaded = (ExtendedNode) loadRoot("/test/resource"); // load another copy
+ assertEquals(expected, getNodeCount(loaded));
+ detachNode(loaded, "211"); // delete a leaf node
+ loaded.eResource().save(null); // commit
+ expected -= 1;
+ assertEquals(expected, getNodeCount(loaded));
+
+ detachNode(loaded, "4"); // delete a subtree
+ loaded.eResource().save(null); // commit
+ expected -= getNodeCount(LEVELS - 1, CHILDREN);
+ assertEquals(expected, getNodeCount(loaded));
+ }
+
+ public void testDetachWithoutBidi() throws Exception
+ {
+ ExtendedNode created = createExtended("node"); // root node
+ createTree(created, LEVELS, CHILDREN); // tree of degree 4, height = root + 3
+ saveRoot(created, "/test/resource"); // commit
+ int refs = CHILDCOUNT * 2; // expect num of refs = 2 per child
+ assertEquals(refs, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE"));
+ created.cdoGetResource().getResourceManager().close();
+
+ ExtendedNode loaded = (ExtendedNode) loadRoot("/test/resource"); // load another copy
+ detachNode(loaded, "211"); // delete a leaf node
+ loaded.eResource().save(null); // commit
+ refs -= 2; // expect -2 containment refs
+ assertEquals(refs, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE"));
+
+ detachNode(loaded, "4"); // delete a subtree
+ loaded.eResource().save(null); // commit
+ refs -= getNodeCount(LEVELS - 1, CHILDREN) * 2;
+ assertEquals(refs, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE"));
+ }
+
+ public void testDetachWithBidiSimple() throws Exception
+ {
+ ExtendedNode node = createExtended("node"); // root node
+ ExtendedNode node1 = createExtended("node1", node); // child node 1
+ ExtendedNode node2 = createExtended("node2", node); // child node 2
+
+ saveRoot(node, "/test/resource"); // commit
+ assertEquals(4, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE"));
+
+ node1.getBidiSource().add(node2);
+ node.eResource().save(null); // commit
+ assertEquals(6, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE"));
+
+ node.getChildren().remove(node1);
+ EList bidiTarget = node2.getBidiTarget();
+ assertTrue(bidiTarget.isEmpty());
+ node.eResource().save(null); // commit
+ assertEquals(2, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE"));
+ }
+
+ public void testDetachWithBidi() throws Exception
+ {
+ ExtendedNode created = createExtended("node"); // root node
+ createTree(created, LEVELS, CHILDREN); // tree of degree 4, height = root + 3
+ saveRoot(created, "/test/resource"); // commit
+ int refs = CHILDCOUNT * 2; // expect num of refs = 2 per child
+ assertEquals(refs, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE"));
+
+ // create 12 bidi refs
+ createBidi(created, "111", "211");
+ createBidi(created, "111", "212");
+ createBidi(created, "111", "213");
+ createBidi(created, "111", "214");
+ createBidi(created, "111", "311");
+ createBidi(created, "111", "312");
+ createBidi(created, "111", "313");
+ createBidi(created, "111", "314");
+ createBidi(created, "111", "411");
+ createBidi(created, "111", "412");
+ createBidi(created, "111", "413");
+ createBidi(created, "111", "414");
+ created.eResource().save(null); // commit
+ refs += 12 * 2; // expect 24 additional refs
+ assertEquals(refs, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE"));
+ created.cdoGetResource().getResourceManager().close();
+
+ ExtendedNode loaded = (ExtendedNode) loadRoot("/test/resource"); // load another copy
+ detachNode(loaded, "211"); // delete a leaf node with 1 bidi ref
+ loaded.eResource().save(null); // commit
+ refs -= 2 + 2; // expect -2 containment refs, -2 bidi refs
+ assertEquals(refs, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE"));
+ }
+
+ public void testRemoveBidi() throws Exception
+ {
+ ExtendedNode created = createExtended("node"); // root node
+ createTree(created, LEVELS, CHILDREN); // tree of degree 4, height = root + 3
+ saveRoot(created, "/test/resource"); // commit
+ int refs = CHILDCOUNT * 2; // expect num of refs = 2 per child
+ assertEquals(refs, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE"));
+
+ // create 12 bidi refs
+ createBidi(created, "111", "211");
+ createBidi(created, "111", "212");
+ createBidi(created, "111", "213");
+ createBidi(created, "111", "214");
+ createBidi(created, "111", "311");
+ createBidi(created, "111", "312");
+ createBidi(created, "111", "313");
+ createBidi(created, "111", "314");
+ createBidi(created, "111", "411");
+ createBidi(created, "111", "412");
+ createBidi(created, "111", "413");
+ createBidi(created, "111", "414");
+ created.eResource().save(null); // commit
+ refs += 12 * 2; // expect 24 additional refs
+ assertEquals(refs, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE"));
+ created.cdoGetResource().getResourceManager().close();
+
+ ExtendedNode loaded = (ExtendedNode) loadRoot("/test/resource"); // load another copy
+ ExtendedNode node211 = findPath(loaded, "211");
+ node211.getBidiSource().clear();
+ loaded.eResource().save(null); // commit
+ refs -= 2; // expect -2 bidi refs
+ assertEquals(refs, jdbc().queryForInt("SELECT COUNT(*) FROM CDO_REFERENCE"));
+ }
+
+ private void detachNode(ExtendedNode root, String path)
+ {
+ ExtendedNode node = findPath(root, path);
+ EList children = node.getParent().getChildren();
+ int size = children.size();
+ children.remove(node);
+ assertEquals(size - 1, children.size());
+ }
+
+ private void createBidi(ExtendedNode root, String path1, String path2)
+ {
+ ExtendedNode src = findPath(root, path1);
+ ExtendedNode dst = findPath(root, path2);
+ dst.getBidiSource().add(src);
+ }
+
+ private void assertBidi(ExtendedNode root, String path1, String path2)
+ {
+ ExtendedNode src = findPath(root, path1);
+ ExtendedNode dst = findPath(root, path2);
+ assertTrue(dst.getBidiSource().contains(src));
+ assertTrue(src.getBidiTarget().contains(dst));
+ }
+
+ private ExtendedNode findPath(ExtendedNode root, String path)
+ {
+ String name = "node";
+ List<String> list = new ArrayList<String>();
+ for (int i = 0; i < path.length(); i++)
+ {
+ name += path.charAt(i);
+ list.add(name);
+ }
+
+ return (ExtendedNode) findPath(list.toArray(new String[list.size()]), root);
+ }
+
+ private void assertTree(String name, ExtendedNode root, int levels, int children)
+ {
+ assertNode(name, root);
+ if (levels > 1)
+ {
+ assertEquals(children, root.getChildren().size());
+ for (int i = 0; i < children; i++)
+ {
+ assertTree(name + (i + 1), (ExtendedNode) root.getChildren().get(i), levels - 1, children);
+ }
+ }
+ }
+
+ private static int getNodeCount(EObject root)
+ {
+ int count = 1;
+ for (Iterator it = EcoreUtil.getAllContents(root, true); it.hasNext();)
+ {
+ it.next();
+ ++count;
+ }
+
+ return count;
+ }
+
+ private static int getNodeCount(int levels, int children)
+ {
+ int level = children;
+ int result = level;
+ for (int i = 1; i < levels; i++)
+ {
+ level *= children;
+ result += level;
+ }
+
+ return result + 1;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/Bugzilla154389Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/Bugzilla154389Test.java
index ef34403810..e6ed88f42b 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/Bugzilla154389Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/Bugzilla154389Test.java
@@ -29,8 +29,6 @@ import testmodel1.TreeNode;
*
* So, it looks like the client and server don't match here.
*
- * Both client and server are current with CVS as of today.
- *
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=154389
*/
public class Bugzilla154389Test extends AbstractModel1Test
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/Bugzilla162017Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/Bugzilla162017Test.java
new file mode 100644
index 0000000000..4c5f5252fa
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/Bugzilla162017Test.java
@@ -0,0 +1,63 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.tests.model1;
+
+
+import testmodel1.ExtendedNode;
+
+
+/**
+ * transmit object change using incorrect EClass for attributes.
+ *
+ * When an attribute is changed in an EClass with a super class, and that
+ * attribute happens to be in the super class definition, the changes transmitted
+ * to the CDO server include the super class EClass, not the class that was modified.
+ *
+ * To temporarily fix this I added an new argument to the rememberAttributeChange()
+ * method. I added the EClass returned from the classInfo.getEClass() method.
+ * In this way rememberAttributeChange() does not depend of finding the EClass
+ * from the feature itself. A patch follows.
+ *
+ * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=162017
+ */
+public class Bugzilla162017Test extends AbstractModel1Test
+{
+ public void testChangeSuperClassAttribute() throws Exception
+ {
+ {
+ ExtendedNode node = createExtended("extended");
+ node.setBooleanFeature(true);
+ node.setIntFeature(4711);
+ node.setStringFeature("tree node feature");
+ node.setStringFeature2("extended node feature");
+ saveRoot(node, "/test/res");
+ }
+
+ {
+ ExtendedNode node = (ExtendedNode) loadRoot("/test/res");
+ assertEquals(true, node.isBooleanFeature());
+ assertEquals(4711, node.getIntFeature());
+ assertEquals("tree node feature", node.getStringFeature());
+ assertEquals("extended node feature", node.getStringFeature2());
+
+ node.setStringFeature("changed tree node feature");
+ node.eResource().save(null);
+ }
+
+ {
+ ExtendedNode node = (ExtendedNode) loadRoot("/test/res");
+ assertEquals(true, node.isBooleanFeature());
+ assertEquals(4711, node.getIntFeature());
+ assertEquals("changed tree node feature", node.getStringFeature());
+ assertEquals("extended node feature", node.getStringFeature2());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/NotificationTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/NotificationTest.java
index 234083c543..8207bbc234 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/NotificationTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/NotificationTest.java
@@ -30,7 +30,7 @@ public class NotificationTest extends AbstractModel1Test
final String RESOURCE = "/test/res";
final String ROOT = "root";
final String NEW_ROOT = "new root";
- final long TIME_LIMIT = 1000;
+ final long TIME_LIMIT = 10000;
// Client1 creates resource
TreeNode root = createNode(ROOT);
@@ -64,7 +64,7 @@ public class NotificationTest extends AbstractModel1Test
final String ROOT = "root";
final String CHILD = "a";
final String NEW_NAME = "a2";
- final long TIME_LIMIT = 1000;
+ final long TIME_LIMIT = 10000;
// Client1 creates resource
TreeNode root = createNode(ROOT);
@@ -100,7 +100,7 @@ public class NotificationTest extends AbstractModel1Test
final String ROOT = "root";
final String CHILD = "a";
final String NEW_NAME = "a2";
- final long TIME_LIMIT = 1000;
+ final long TIME_LIMIT = 10000;
// Client1 creates resource
TreeNode root = createNode(ROOT);
@@ -137,7 +137,7 @@ public class NotificationTest extends AbstractModel1Test
final String ROOT = "root";
final String CHILD = "a";
final String NEW_NAME = "a2";
- final long TIME_LIMIT = 1000;
+ final long TIME_LIMIT = 10000;
final boolean[] notificationReceived = { false};
// Client1 creates resource
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/SerializationTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/SerializationTest.java
index 1fd4876e68..1bfb44a97b 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/SerializationTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/SerializationTest.java
@@ -11,6 +11,8 @@
package org.eclipse.emf.cdo.tests.model1;
+import org.eclipse.emf.cdo.tests.IOHelper;
+
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
@@ -20,7 +22,7 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
-import org.eclipse.net4j.util.IOHelper;
+import org.eclipse.net4j.util.IOUtil;
import testmodel1.TreeNode;
@@ -200,8 +202,8 @@ public class SerializationTest extends AbstractModel1Test
}
finally
{
- IOHelper.close(is);
- IOHelper.close(os);
+ IOUtil.closeSilent(is);
+ IOUtil.closeSilent(os);
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/AbstractTopology.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/AbstractTopology.java
deleted file mode 100644
index 299f443539..0000000000
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/AbstractTopology.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
- * 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:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.emf.cdo.tests.topology;
-
-
-import org.eclipse.emf.cdo.client.ResourceManager;
-import org.eclipse.emf.cdo.tests.internal.CDOTestPlugin;
-
-import org.eclipse.emf.ecore.resource.ResourceSet;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.net4j.spring.Container;
-import org.eclipse.net4j.spring.impl.ContainerImpl;
-
-import org.osgi.framework.Bundle;
-
-import java.net.URL;
-
-
-public abstract class AbstractTopology implements ITopology
-{
- protected static final String NET4J_LOCATION = "META-INF/net4j/net4j.xml";
-
- protected static final String NET4J_CLIENT_LOCATION = "META-INF/net4j/client/net4j-client.xml";
-
- protected static final String NET4J_SERVER_LOCATION = "META-INF/net4j/server/net4j-server.xml";
-
- protected static final String NET4J_EMBEDDED_LOCATION = "META-INF/net4j/embedded/net4j-embedded.xml";
-
- protected static final String CDO_CLIENT_LOCATION = "META-INF/cdo/client/cdo-client.xml";
-
- protected static final String CDO_SERVER_LOCATION = "META-INF/cdo/server/cdo-server.xml";
-
- private String bundleLocation;
-
- private Container cdoClient;
-
- protected AbstractTopology()
- {
- }
-
- public void start() throws Exception
- {
- CDOTestPlugin plugin = CDOTestPlugin.getPlugin();
- Bundle bundle = plugin.getBundle();
- URL url = bundle.getEntry("/");
- bundleLocation = FileLocator.toFileURL(url).getFile();
- }
-
- public void stop() throws Exception
- {
- cdoClient.stop();
- cdoClient = null;
- }
-
- public ResourceManager createResourceManager(ResourceSet resourceSet)
- {
- ResourceManager resourceManager = (ResourceManager) cdoClient.getBean("resourceManager");
- resourceManager.setResourceSet(resourceSet);
-
- try
- {
- resourceManager.start();
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- return null;
- }
-
- return resourceManager;
- }
-
- protected void createCDOClient(String name, Container parent)
- {
- cdoClient = createContainer(name, CDO_CLIENT_LOCATION, parent);
- }
-
- protected ContainerImpl createContainer(String name, String location, Container parent)
- {
- return new ContainerImpl(bundleLocation, location, name, parent, CDOTestPlugin.class
- .getClassLoader());
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/AbstractTopologyTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/AbstractTopologyTest.java
index ab505cb1f0..7337c1d8ff 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/AbstractTopologyTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/AbstractTopologyTest.java
@@ -20,9 +20,11 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.springframework.jdbc.core.JdbcTemplate;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.PrintStreamLogHandler;
+import org.eclipse.net4j.util.om.PrintStreamTraceHandler;
-import java.io.IOException;
+import org.springframework.jdbc.core.JdbcTemplate;
import javax.sql.DataSource;
@@ -35,6 +37,12 @@ public abstract class AbstractTopologyTest extends TestCase implements ITopology
private ITopology topology;
+ private long startMemory;
+
+ private String label;
+
+ private static int run;
+
public String getMode()
{
return mode;
@@ -58,9 +66,17 @@ public abstract class AbstractTopologyTest extends TestCase implements ITopology
@Override
protected void setUp() throws Exception
{
+ OMPlatform.INSTANCE.addLogHandler(PrintStreamLogHandler.CONSOLE);
+ OMPlatform.INSTANCE.addTraceHandler(PrintStreamTraceHandler.CONSOLE);
+ OMPlatform.INSTANCE.setDebugging(true);
+
+ System.gc();
+ startMemory = getUsedMemory();
+
if (topology == null) topology = createTopology();
+ label = getName() + " [" + topology.getName() + "]";
System.out.println("=========================================================================");
- System.out.println("TC_START " + getName() + " [" + topology.getName() + "]");
+ System.out.println("TC_START " + label);
System.out.println("=========================================================================");
super.setUp();
@@ -70,19 +86,37 @@ public abstract class AbstractTopologyTest extends TestCase implements ITopology
@Override
protected void tearDown() throws Exception
{
- JdbcTemplate jdbc = getJdbcTemplate();
+ Thread.sleep(200);
+ JdbcTemplate jdbc = jdbc();
wipeDatabase(jdbc);
topology.stop();
+ topology = null;
super.tearDown();
+ System.gc();
+ long endMemory = getUsedMemory();
+
+ System.out.println("Memory-Delta " + getRun() + "\t " + (endMemory - startMemory));
System.out.println("=========================================================================");
- System.out.println("TC_END " + getName() + " [" + topology.getName() + "]");
+ System.out.println("TC_END " + label);
System.out.println("=========================================================================");
System.out.println();
System.out.println();
System.out.println();
System.out.println();
+ label = null;
+ mode = null;
+ }
+
+ private static long getUsedMemory()
+ {
+ return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
+ }
+
+ private static String getRun()
+ {
+ return String.format("%4d", new Object[] { ++run});
}
protected void wipeDatabase(JdbcTemplate jdbc)
@@ -113,20 +147,19 @@ public abstract class AbstractTopologyTest extends TestCase implements ITopology
return topology.getDataSource();
}
- protected JdbcTemplate getJdbcTemplate()
+ protected JdbcTemplate jdbc()
{
return new JdbcTemplate(getDataSource());
}
- protected ResourceManager createResourceManager(ResourceSet resourceSet)
+ protected ResourceManager createResourceManager(ResourceSet resourceSet) throws Exception
{
return topology.createResourceManager(resourceSet);
}
- protected ResourceManager createResourceManager()
+ protected ResourceManager createResourceManager() throws Exception
{
- ResourceSet resourceSet = new ResourceSetImpl();
- return topology.createResourceManager(resourceSet);
+ return createResourceManager(new ResourceSetImpl());
}
protected CDOResource createResource(String path, ResourceManager resourceManager)
@@ -135,7 +168,7 @@ public abstract class AbstractTopologyTest extends TestCase implements ITopology
return (CDOResource) resourceManager.createResource(uri);
}
- protected CDOResource createResource(String path)
+ protected CDOResource createResource(String path) throws Exception
{
return createResource(path, createResourceManager());
}
@@ -146,18 +179,18 @@ public abstract class AbstractTopologyTest extends TestCase implements ITopology
return (CDOResource) resourceManager.getResource(uri, true);
}
- protected CDOResource getResource(String path)
+ protected CDOResource getResource(String path) throws Exception
{
return getResource(path, createResourceManager());
}
- protected EObject loadRoot(String path) throws IOException
+ protected EObject loadRoot(String path) throws Exception
{
CDOResource resource = getResource(path);
return (EObject) resource.getContents().get(0);
}
- protected CDOResource saveRoot(EObject root, String path) throws IOException
+ protected CDOResource saveRoot(EObject root, String path) throws Exception
{
CDOResource resource = createResource(path);
resource.getContents().add(root);
@@ -167,33 +200,34 @@ public abstract class AbstractTopologyTest extends TestCase implements ITopology
protected ITopology createTopology()
{
- if (mode == null)
- {
- mode = System.getProperty(CDO_TEST_MODE_KEY, DEFAULT_MODE);
- }
-
- if (EMBEDDED_MODE.equalsIgnoreCase(mode))
- {
- return new EmbeddedTopology();
- }
-
- if (CLIENT_MODE.equalsIgnoreCase(mode))
- {
- return new ClientTopology();
- }
-
- if (CLIENT_SERVER_MODE.equalsIgnoreCase(mode))
- {
- return new ClientServerTopology();
- }
-
- if (CLIENT_SEPARATED_SERVER_MODE.equalsIgnoreCase(mode))
- {
- return new ClientSeparatedServerTopology();
- }
-
- fail("Topology not recognized: " + mode);
- return null; // Make compiler happy
+ return new ClientServerTopology();
+ // if (mode == null)
+ // {
+ // mode = System.getProperty(CDO_TEST_MODE_KEY, DEFAULT_MODE);
+ // }
+ //
+ // if (EMBEDDED_MODE.equalsIgnoreCase(mode))
+ // {
+ // return new EmbeddedTopology();
+ // }
+ //
+ // if (CLIENT_MODE.equalsIgnoreCase(mode))
+ // {
+ // return new ClientTopology();
+ // }
+ //
+ // if (CLIENT_SERVER_MODE.equalsIgnoreCase(mode))
+ // {
+ // return new ClientServerTopology();
+ // }
+ //
+ // if (CLIENT_SEPARATED_SERVER_MODE.equalsIgnoreCase(mode))
+ // {
+ // return new ClientSeparatedServerTopology();
+ // }
+ //
+ // fail("Topology not recognized: " + mode);
+ // return null; // Make compiler happy
}
protected void assertTrue(Object object)
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ClientSeparatedServerTopology.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ClientSeparatedServerTopology.java
index e4dede0c07..bf6046913b 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ClientSeparatedServerTopology.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ClientSeparatedServerTopology.java
@@ -11,26 +11,11 @@
package org.eclipse.emf.cdo.tests.topology;
-import org.eclipse.net4j.core.Acceptor;
-import org.eclipse.net4j.spring.Container;
-
import javax.sql.DataSource;
public class ClientSeparatedServerTopology extends AbstractTopology
{
- private Container serverNet4j;
-
- private Container net4jServer;
-
- private Container cdoServer;
-
- private Container clientNet4j;
-
- private Container net4jClient;
-
- private Acceptor acceptor;
-
public ClientSeparatedServerTopology()
{
}
@@ -62,17 +47,83 @@ public class ClientSeparatedServerTopology extends AbstractTopology
{
super.stop();
- //Stop client
- net4jClient.stop();
- clientNet4j.stop();
-
- //Stop server
- acceptor.stop();
- acceptor = null;
-
- cdoServer.stop();
- net4jServer.stop();
- serverNet4j.stop();
+ try
+ {
+ net4jClient.stop();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ net4jClient = null;
+ }
+
+ try
+ {
+ clientNet4j.stop();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ clientNet4j = null;
+ }
+
+ try
+ {
+ acceptor.stop();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ acceptor = null;
+ }
+
+ try
+ {
+ cdoServer.stop();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ cdoServer = null;
+ }
+
+ try
+ {
+ net4jServer.stop();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ net4jServer = null;
+ }
+
+ try
+ {
+ serverNet4j.stop();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ serverNet4j = null;
+ }
}
public DataSource getDataSource()
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ClientServerTopology.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ClientServerTopology.java
index c15bdc1d76..5258788e34 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ClientServerTopology.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ClientServerTopology.java
@@ -11,23 +11,76 @@
package org.eclipse.emf.cdo.tests.topology;
-import org.eclipse.net4j.core.Acceptor;
-import org.eclipse.net4j.spring.Container;
+import org.eclipse.emf.cdo.client.ResourceManager;
+import org.eclipse.emf.cdo.client.impl.AttributeConverterImpl;
+import org.eclipse.emf.cdo.client.impl.PackageManagerImpl;
+import org.eclipse.emf.cdo.client.impl.ResourceManagerImpl;
+import org.eclipse.emf.cdo.client.protocol.ClientCDOProtocolImpl;
+import org.eclipse.emf.cdo.client.protocol.ClientCDOResProtocolImpl;
+import org.eclipse.emf.cdo.core.impl.OIDEncoderImpl;
+import org.eclipse.emf.cdo.server.impl.ColumnConverterImpl;
+import org.eclipse.emf.cdo.server.impl.MapperImpl;
+import org.eclipse.emf.cdo.server.protocol.ServerCDOProtocolImpl;
+import org.eclipse.emf.cdo.server.protocol.ServerCDOResProtocolImpl;
+
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+import org.eclipse.net4j.transport.BufferProvider;
+import org.eclipse.net4j.transport.Connector;
+import org.eclipse.net4j.transport.ProtocolFactory;
+import org.eclipse.net4j.transport.tcp.TCPAcceptor;
+import org.eclipse.net4j.transport.tcp.TCPSelector;
+import org.eclipse.net4j.util.Net4jUtil;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.registry.HashMapRegistry;
+import org.eclipse.net4j.util.registry.IRegistry;
+
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.jdbc.datasource.DriverManagerDataSource;
+import org.springframework.transaction.support.TransactionTemplate;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import javax.sql.DataSource;
-public class ClientServerTopology extends AbstractTopology
+public class ClientServerTopology implements ITopology
{
- private Container net4j;
+ public static final ExecutorService THREAD_POOL = Executors.newCachedThreadPool();
- private Container net4jServer;
+ private AttributeConverterImpl attributeConverter;
- private Container cdoServer;
+ private OIDEncoderImpl oidEncoder;
- private Container net4jClient;
+ private PackageManagerImpl clientPackageManager;
- private Acceptor acceptor;
+ private IRegistry<String, ProtocolFactory> clientRegistry;
+
+ private IRegistry<String, ProtocolFactory> serverRegistry;
+
+ private BufferProvider bufferPool;
+
+ private TCPSelector selector;
+
+ private TCPAcceptor acceptor;
+
+ private Connector connector;
+
+ private org.eclipse.emf.cdo.server.impl.PackageManagerImpl serverPackageManager;
+
+ private org.eclipse.emf.cdo.server.impl.ResourceManagerImpl serverResourceManager;
+
+ private ColumnConverterImpl columnConverter;
+
+ private DriverManagerDataSource dataSource;
+
+ private DataSourceTransactionManager transactionManager;
+
+ private TransactionTemplate transactionTemplate;
+
+ private JdbcTemplate jdbcTemplate;
public ClientServerTopology()
{
@@ -40,40 +93,111 @@ public class ClientServerTopology extends AbstractTopology
public void start() throws Exception
{
- super.start();
- net4j = createContainer("net4j", NET4J_LOCATION, null);
-
- // Start server
- net4jServer = createContainer("server", NET4J_SERVER_LOCATION, net4j);
- cdoServer = createContainer("cdo", CDO_SERVER_LOCATION, net4jServer);
-
- acceptor = (Acceptor) cdoServer.getBean("acceptor", Acceptor.class);
- acceptor.start();
-
- // Start client
- net4jClient = createContainer("client", NET4J_CLIENT_LOCATION, net4j);
- createCDOClient("cdo", net4jClient);
+ bufferPool = Net4jUtil.createBufferPool();
+ LifecycleUtil.activate(bufferPool);
+
+ selector = Net4jUtil.createTCPSelector();
+ LifecycleUtil.activate(selector);
+
+ oidEncoder = new OIDEncoderImpl();
+ oidEncoder.setFragmentBits(48);
+ LifecycleUtil.activate(oidEncoder);
+
+ // Server
+ columnConverter = new ColumnConverterImpl();
+ LifecycleUtil.activate(columnConverter);
+
+ serverPackageManager = new org.eclipse.emf.cdo.server.impl.PackageManagerImpl();
+ LifecycleUtil.activate(serverPackageManager);
+
+ serverResourceManager = new org.eclipse.emf.cdo.server.impl.ResourceManagerImpl();
+ LifecycleUtil.activate(serverResourceManager);
+
+ dataSource = new DriverManagerDataSource();
+ dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
+ dataSource.setUrl("jdbc:hsqldb:.");
+ dataSource.setUsername("sa");
+
+ jdbcTemplate = new JdbcTemplate();
+ jdbcTemplate.setDataSource(dataSource);
+
+ MapperImpl mapper = new MapperImpl();
+ mapper.setColumnConverter(columnConverter);
+ mapper.setDataSource(dataSource);
+ mapper.setJdbcTemplate(jdbcTemplate);
+ mapper.setOidEncoder(oidEncoder);
+ mapper.setPackageManager(serverPackageManager);
+ mapper.setResourceManager(serverResourceManager);
+ mapper.setSqlDialectName("HSQLDB");
+ LifecycleUtil.activate(mapper);
+
+ transactionManager = new DataSourceTransactionManager();
+ transactionManager.setDataSource(dataSource);
+
+ transactionTemplate = new TransactionTemplate();
+
+ serverRegistry = new HashMapRegistry();
+ serverRegistry.register(new ServerCDOResProtocolImpl.Factory(mapper, transactionTemplate));
+ serverRegistry.register(new ServerCDOProtocolImpl.Factory(mapper, transactionTemplate));
+
+ acceptor = Net4jUtil.createTCPAcceptor(bufferPool, selector);
+ acceptor.setProtocolFactoryRegistry(serverRegistry);
+ acceptor.setReceiveExecutor(THREAD_POOL);
+ LifecycleUtil.activate(acceptor);
+
+ // Client
+ attributeConverter = new AttributeConverterImpl();
+ LifecycleUtil.activate(attributeConverter);
+
+ clientPackageManager = new PackageManagerImpl();
+ clientPackageManager.setAttributeConverter(attributeConverter);
+ clientPackageManager.setOidEncoder(oidEncoder);
+ clientPackageManager.setAutoPersistent(true);
+ LifecycleUtil.activate(clientPackageManager);
+
+ clientRegistry = new HashMapRegistry();
+ clientRegistry.register(new ClientCDOProtocolImpl.Factory());
+ clientRegistry.register(new ClientCDOResProtocolImpl.Factory());
+
+ connector = Net4jUtil.createTCPConnector(bufferPool, selector, "localhost");
+ connector.setProtocolFactoryRegistry(clientRegistry);
+ connector.setReceiveExecutor(THREAD_POOL);
+ LifecycleUtil.activate(connector);
}
public void stop() throws Exception
{
- super.stop();
+ LifecycleUtil.deactivate(connector);
+ connector = null;
- //Stop client
- net4jClient.stop();
+ LifecycleUtil.deactivate(selector);
+ selector = null;
- //Stop server
- acceptor.stop();
- acceptor = null;
+ LifecycleUtil.deactivate(bufferPool);
+ bufferPool = null;
- cdoServer.stop();
- net4jServer.stop();
+ LifecycleUtil.deactivate(clientPackageManager);
+ clientPackageManager = null;
- net4j.stop();
+ LifecycleUtil.deactivate(oidEncoder);
+ oidEncoder = null;
+
+ LifecycleUtil.deactivate(attributeConverter);
+ attributeConverter = null;
+ }
+
+ public ResourceManager createResourceManager(ResourceSet resourceSet) throws Exception
+ {
+ ResourceManagerImpl resourceManager = new ResourceManagerImpl();
+ resourceManager.setConnector(connector);
+ resourceManager.setPackageManager(clientPackageManager);
+ resourceManager.setResourceSet(resourceSet);
+ LifecycleUtil.activate(resourceManager);
+ return resourceManager;
}
public DataSource getDataSource()
{
- return (DataSource) cdoServer.getBean("dataSource");
+ return dataSource;
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ClientTopology.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ClientTopology.java
index 80fd02dab4..1dcf97fd0c 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ClientTopology.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ClientTopology.java
@@ -11,10 +11,9 @@
package org.eclipse.emf.cdo.tests.topology;
-import org.eclipse.net4j.spring.Container;
-
import javax.sql.DataSource;
+
/*
* TODO Test this topology (need external server for that)
*/
@@ -47,9 +46,31 @@ public class ClientTopology extends AbstractTopology
{
super.stop();
- //Stop client
- net4jClient.stop();
- net4j.stop();
+ try
+ {
+ net4jClient.stop();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ net4jClient = null;
+ }
+
+ try
+ {
+ net4j.stop();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ net4j = null;
+ }
}
public DataSource getDataSource()
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/EmbeddedTopology.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/EmbeddedTopology.java
index 1c0e12ff90..fb0040dd03 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/EmbeddedTopology.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/EmbeddedTopology.java
@@ -11,8 +11,6 @@
package org.eclipse.emf.cdo.tests.topology;
-import org.eclipse.net4j.spring.Container;
-
import javax.sql.DataSource;
@@ -45,9 +43,45 @@ public class EmbeddedTopology extends AbstractTopology
public void stop() throws Exception
{
super.stop();
- cdoServer.stop();
- net4jEmbedded.stop();
- net4j.stop();
+
+ try
+ {
+ cdoServer.stop();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ cdoServer = null;
+ }
+
+ try
+ {
+ net4jEmbedded.stop();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ net4jEmbedded = null;
+ }
+
+ try
+ {
+ net4j.stop();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ net4j = null;
+ }
}
public DataSource getDataSource()
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ITopology.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ITopology.java
index a3195c67a1..58aae5f98e 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ITopology.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ITopology.java
@@ -26,7 +26,7 @@ public interface ITopology
public void stop() throws Exception;
- public ResourceManager createResourceManager(ResourceSet resourceSet);
+ public ResourceManager createResourceManager(ResourceSet resourceSet) throws Exception;
public DataSource getDataSource();
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ITopologyConstants.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ITopologyConstants.java
index 52b16b4eaa..f0e8358a3f 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ITopologyConstants.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/ITopologyConstants.java
@@ -24,17 +24,17 @@ public interface ITopologyConstants
public static final String EMBEDDED_MODE = "Embedded";
public static final String[] ALL_MODES = { //
- CLIENT_SEPARATED_SERVER_MODE, // 0
- CLIENT_SERVER_MODE, // 1
- CLIENT_MODE, // 2
- EMBEDDED_MODE // 3
- };
+ CLIENT_SEPARATED_SERVER_MODE, // 0
+ CLIENT_SERVER_MODE, // 1
+ CLIENT_MODE, // 2
+ EMBEDDED_MODE // 3
+ };
public static final String[] SELF_CONTAINED_MODES = { //
- CLIENT_SEPARATED_SERVER_MODE, // 0
- CLIENT_SERVER_MODE, // 1
- EMBEDDED_MODE // 2
- };
+ CLIENT_SEPARATED_SERVER_MODE, // 0
+ CLIENT_SERVER_MODE, // 1
+ EMBEDDED_MODE // 2
+ };
public static final String DEFAULT_MODE = EMBEDDED_MODE;
}

Back to the top