summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-30 10:41:05 (EDT)
committerEike Stepper2007-09-30 10:41:05 (EDT)
commit2e78c66e59287b7325a44020863819ca30cbddf8 (patch)
tree327b88ab659c5aeb813fda72f1bfb2e2090451fa
parenteee540cb9f43392f3ab4c6208587295a71b1390a (diff)
downloadcdo-2e78c66e59287b7325a44020863819ca30cbddf8.zip
cdo-2e78c66e59287b7325a44020863819ca30cbddf8.tar.gz
cdo-2e78c66e59287b7325a44020863819ca30cbddf8.tar.bz2
[203538] Limit memory consumption in CDORevisionResolverImpl
https://bugs.eclipse.org/bugs/show_bug.cgi?id=203538
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RevisionHolderTest.java255
2 files changed, 259 insertions, 4 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java
index 31fca39..6f6e555 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java
@@ -19,13 +19,13 @@ import org.eclipse.emf.cdo.tests.model1.Category;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.tests.model1.Model1Factory;
-import org.eclipse.net4j.util.event.IEvent;
-import org.eclipse.net4j.util.event.IListener;
-
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -319,7 +319,7 @@ public class InvalidationTest extends AbstractCDOTest
msg("Changing name");
category1A.setName("CHANGED NAME");
- ITimeOuter timeOuter = new PollingTimeOuter(4, 100)
+ ITimeOuter timeOuter = new PollingTimeOuter(10, 100)
{
@Override
protected boolean successful()
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RevisionHolderTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RevisionHolderTest.java
new file mode 100644
index 0000000..2176a10
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RevisionHolderTest.java
@@ -0,0 +1,255 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 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.cdo.internal.protocol.CDOIDImpl;
+import org.eclipse.emf.cdo.internal.protocol.revision.DLRevisionHolder;
+import org.eclipse.emf.cdo.internal.protocol.revision.LRURevisionHolder;
+import org.eclipse.emf.cdo.internal.protocol.revision.LRURevisionList;
+import org.eclipse.emf.cdo.protocol.CDOID;
+import org.eclipse.emf.cdo.protocol.model.CDOClass;
+import org.eclipse.emf.cdo.protocol.revision.CDORevision;
+import org.eclipse.emf.cdo.protocol.revision.CDORevisionData;
+import org.eclipse.emf.cdo.protocol.revision.CDORevisionDelta;
+import org.eclipse.emf.cdo.protocol.revision.CDORevisionResolver;
+
+import org.eclipse.net4j.tests.AbstractOMTest;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public class RevisionHolderTest extends AbstractOMTest
+{
+ public void testAddHead() throws Exception
+ {
+ LinkedList<LRURevisionHolder> linkedList = new LinkedList<LRURevisionHolder>();
+ LRURevisionList list = new LRURevisionList(100);
+ validateList(list, 0);
+ for (int i = 0; i < 10; i++)
+ {
+ LRURevisionHolder holder = new LRURevisionHolder(list, new RevisionStub(i));
+ linkedList.addFirst(holder);
+ list.addHead(holder);
+ validateList(list, i + 1);
+ validateList(list, linkedList);
+ }
+ }
+
+ public void testAddTail() throws Exception
+ {
+ LinkedList<LRURevisionHolder> linkedList = new LinkedList<LRURevisionHolder>();
+ LRURevisionList list = new LRURevisionList(100);
+ validateList(list, 0);
+ for (int i = 0; i < 10; i++)
+ {
+ LRURevisionHolder holder = new LRURevisionHolder(list, new RevisionStub(i));
+ linkedList.addLast(holder);
+ list.addTail(holder);
+ validateList(list, i + 1);
+ validateList(list, linkedList);
+ }
+ }
+
+ public void testRemoveHead() throws Exception
+ {
+ LinkedList<LRURevisionHolder> linkedList = new LinkedList<LRURevisionHolder>();
+ LRURevisionList list = new LRURevisionList(100);
+ for (int i = 0; i < 10; i++)
+ {
+ LRURevisionHolder holder = new LRURevisionHolder(list, new RevisionStub(i));
+ linkedList.addLast(holder);
+ list.addTail(holder);
+ }
+
+ validateList(list, 10);
+ validateList(list, linkedList);
+
+ LRURevisionHolder holder = linkedList.removeFirst();
+ list.remove(holder);
+ validateList(list, 9);
+ validateList(list, linkedList);
+ }
+
+ public void testRemoveTail() throws Exception
+ {
+ LinkedList<LRURevisionHolder> linkedList = new LinkedList<LRURevisionHolder>();
+ LRURevisionList list = new LRURevisionList(100);
+ for (int i = 0; i < 10; i++)
+ {
+ LRURevisionHolder holder = new LRURevisionHolder(list, new RevisionStub(i));
+ linkedList.addLast(holder);
+ list.addTail(holder);
+ }
+
+ validateList(list, 10);
+ validateList(list, linkedList);
+
+ LRURevisionHolder holder = linkedList.removeLast();
+ list.remove(holder);
+ validateList(list, 9);
+ validateList(list, linkedList);
+ }
+
+ public void testRemoveMiddle() throws Exception
+ {
+ LinkedList<LRURevisionHolder> linkedList = new LinkedList<LRURevisionHolder>();
+ LRURevisionList list = new LRURevisionList(100);
+ for (int i = 0; i < 10; i++)
+ {
+ LRURevisionHolder holder = new LRURevisionHolder(list, new RevisionStub(i));
+ linkedList.addLast(holder);
+ list.addTail(holder);
+ }
+
+ validateList(list, 10);
+ validateList(list, linkedList);
+
+ LRURevisionHolder holder = linkedList.remove(5);
+ list.remove(holder);
+ validateList(list, 9);
+ validateList(list, linkedList);
+ }
+
+ public void testRemoveAll() throws Exception
+ {
+ LinkedList<LRURevisionHolder> linkedList = new LinkedList<LRURevisionHolder>();
+ LRURevisionList list = new LRURevisionList(100);
+ for (int i = 0; i < 10; i++)
+ {
+ LRURevisionHolder holder = new LRURevisionHolder(list, new RevisionStub(i));
+ linkedList.addLast(holder);
+ list.addTail(holder);
+ }
+
+ validateList(list, 10);
+ validateList(list, linkedList);
+
+ for (int i = 10; i > 0; i--)
+ {
+ LRURevisionHolder holder = linkedList.remove(0);
+ list.remove(holder);
+ validateList(list, i - 1);
+ validateList(list, linkedList);
+ }
+
+ validateList(list, 0);
+ validateList(list, linkedList);
+ }
+
+ private void validateList(LRURevisionList list, int size)
+ {
+ assertEquals(size, list.size());
+ if (size == 0)
+ {
+ assertEquals(list.getDLHead(), list.getDLTail());
+ }
+ else
+ {
+ assertNotNull(list.getDLHead());
+ assertNotNull(list.getDLTail());
+ }
+
+ assertEquals(list.getDLHead(), list.getDLHead().getDLNext().getDLPrev());
+ assertEquals(list.getDLTail(), list.getDLTail().getDLPrev().getDLNext());
+
+ DLRevisionHolder holder = list.getDLHead();
+ for (int i = 0; i < size; i++)
+ {
+ assertEquals(holder, holder.getDLNext().getDLPrev());
+ assertEquals(holder, holder.getDLPrev().getDLNext());
+ }
+ }
+
+ private void validateList(LRURevisionList list, List<LRURevisionHolder> expected)
+ {
+ assertEquals(expected.size(), list.size());
+ for (int i = 0; i < expected.size(); i++)
+ {
+ assertEquals(expected.get(i), list.get(i));
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class RevisionStub implements CDORevision
+ {
+ private CDOID id;
+
+ public RevisionStub(long id)
+ {
+ this.id = CDOIDImpl.create(id);
+ }
+
+ public CDORevisionDelta createDelta(CDORevision origin)
+ {
+ return null;
+ }
+
+ public CDOClass getCDOClass()
+ {
+ return null;
+ }
+
+ public long getCreated()
+ {
+ return 0;
+ }
+
+ public CDORevisionData getData()
+ {
+ return null;
+ }
+
+ public CDOID getID()
+ {
+ return id;
+ }
+
+ public long getRevised()
+ {
+ return 0;
+ }
+
+ public CDORevisionResolver getRevisionResolver()
+ {
+ return null;
+ }
+
+ public int getVersion()
+ {
+ return 0;
+ }
+
+ public boolean isCurrent()
+ {
+ return false;
+ }
+
+ public boolean isResource()
+ {
+ return false;
+ }
+
+ public boolean isTransactional()
+ {
+ return false;
+ }
+
+ public boolean isValid(long timeStamp)
+ {
+ return false;
+ }
+ }
+}