Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2018-05-24 02:54:10 -0400
committerEike Stepper2018-05-24 02:54:10 -0400
commitbc842e8edda8edaaf40c281760e7791af16075d4 (patch)
tree1cb3c329151a00ed03fc852bf32c61bb955f8f79 /plugins/org.eclipse.emf.cdo.tests/src
parent0664b0471e5b12aca1965fabd0b698c57ea42d70 (diff)
downloadcdo-bc842e8edda8edaaf40c281760e7791af16075d4.tar.gz
cdo-bc842e8edda8edaaf40c281760e7791af16075d4.tar.xz
cdo-bc842e8edda8edaaf40c281760e7791af16075d4.zip
[517225] StringCompressor can create huge memory leak
https://bugs.eclipse.org/bugs/show_bug.cgi?id=517225
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/bugzilla/Bugzilla_340709_Test.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_441136_Test.java21
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_517225_Test.java117
3 files changed, 132 insertions, 8 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_340709_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_340709_Test.java
index d9c31363d6..6c2929cfb7 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_340709_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_340709_Test.java
@@ -27,7 +27,7 @@ import java.util.concurrent.CountDownLatch;
*/
public class Bugzilla_340709_Test extends AbstractCDOTest
{
- CountDownLatch latch = new CountDownLatch(1);
+ private transient CountDownLatch latch = new CountDownLatch(1);
public void test() throws Exception
{
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_441136_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_441136_Test.java
index a6c2d45e31..b68826183b 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_441136_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_441136_Test.java
@@ -24,6 +24,8 @@ import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.net4j.signal.AcknowledgeCompressedStringsIndication;
+import org.eclipse.net4j.signal.AcknowledgeCompressedStringsRequest;
import org.eclipse.net4j.signal.ISignalProtocol;
import org.eclipse.net4j.signal.IndicationWithMonitoring;
import org.eclipse.net4j.signal.MonitorProgressIndication;
@@ -72,30 +74,35 @@ public class Bugzilla_441136_Test extends AbstractCDOTest
Company company = getModel1Factory().createCompany();
resource.getContents().add(company);
transaction.commit(useMonitor ? new NullProgressMonitor() : null);
- String assertMessage = " differents kinds of requests should have been sent, QueryRequest, QueryCancel, LoadRevisionsRequest and CommitTransactionRequest";
+
+ signalCounter.removeCountFor(AcknowledgeCompressedStringsRequest.class);
+ signalCounter.removeCountFor(AcknowledgeCompressedStringsIndication.class);
+
int nbExpectedCalls;
- if (!useMonitor)
+ String assertMessage = " differents kinds of requests should have been sent, QueryRequest, QueryCancel, LoadRevisionsRequest and CommitTransactionRequest";
+
+ if (useMonitor)
{
+ nbExpectedCalls = 5;
+ assertMessage += " and MonitorProgressIndications should have been received";
+
// QueryRequest, QueryCancel are used to get the resourcePath
- nbExpectedCalls = 4;
assertEquals(nbExpectedCalls + assertMessage, nbExpectedCalls, signalCounter.getCountForSignalTypes());
assertNotSame(0, signalCounter.getCountFor(QueryRequest.class));
assertNotSame(0, signalCounter.getCountFor(QueryCancelRequest.class));
assertNotSame(0, signalCounter.getCountFor(LoadRevisionsRequest.class));
assertNotSame(0, signalCounter.getCountFor(CommitTransactionRequest.class));
+ assertNotSame(0, signalCounter.getCountFor(MonitorProgressIndication.class));
}
else
{
- nbExpectedCalls = 5;
- assertMessage += " and MonitorProgressIndications should have been received";
-
// QueryRequest, QueryCancel are used to get the resourcePath
+ nbExpectedCalls = 4;
assertEquals(nbExpectedCalls + assertMessage, nbExpectedCalls, signalCounter.getCountForSignalTypes());
assertNotSame(0, signalCounter.getCountFor(QueryRequest.class));
assertNotSame(0, signalCounter.getCountFor(QueryCancelRequest.class));
assertNotSame(0, signalCounter.getCountFor(LoadRevisionsRequest.class));
assertNotSame(0, signalCounter.getCountFor(CommitTransactionRequest.class));
- assertNotSame(0, signalCounter.getCountFor(MonitorProgressIndication.class));
}
protocol.removeListener(signalCounter);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_517225_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_517225_Test.java
new file mode 100644
index 0000000000..2842217c54
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_517225_Test.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2018 Eike Stepper (Berlin, Germany) and others.
+ * 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.bugzilla;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.internal.net4j.protocol.CDOClientProtocol;
+import org.eclipse.emf.cdo.net4j.CDONet4jSession;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.model1.Category;
+import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.tests.model1.Product1;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+
+import org.eclipse.net4j.signal.SignalProtocol;
+import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.net4j.util.io.StringCompressor;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.spi.cdo.CDOSessionProtocol;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * Bug 517225: StringCompressor can create huge memory leak
+ *
+ * @author Eike Stepper
+ */
+public class Bugzilla_517225_Test extends AbstractCDOTest
+{
+ private static final int LEVELS = 3;
+
+ private static final int CATEGORIES = 3;
+
+ private static final int PRODUCTS = 15;
+
+ @SuppressWarnings("unchecked")
+ public void testStringCompressorLeak() throws Exception
+ {
+ // Initialize model.
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("res"));
+
+ Category category = getModel1Factory().createCategory();
+ category.setName("ROOT");
+
+ Company company = getModel1Factory().createCompany();
+ company.getCategories().add(category);
+ resource.getContents().add(company);
+
+ createModel(category, LEVELS);
+ transaction.commit();
+ }
+
+ CDONet4jSession session = (CDONet4jSession)openSession();
+ CDOClientProtocol protocol = (CDOClientProtocol)(CDOSessionProtocol)session.options().getNet4jProtocol();
+ StringCompressor compressor = (StringCompressor)protocol.getPackageURICompressor();
+
+ Collection<Integer> pendingAcknowledgements = (Collection<Integer>)ReflectUtil
+ .getValue(ReflectUtil.getField(StringCompressor.class, "pendingAcknowledgements"), compressor);
+
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.getResource(getResourcePath("res"));
+ for (Iterator<EObject> it = resource.eAllContents(); it.hasNext();)
+ {
+ it.next();
+ }
+
+ // Should be 9 with a HashSet instead of 728 with an ArrayList.
+ assertTrue("pendingAcknowledgements: " + pendingAcknowledgements, pendingAcknowledgements.size() < 10);
+
+ sleep(SignalProtocol.COMPRESSED_STRINGS_ACKNOWLEDGE_TIMEOUT + 1000);
+ session.openView();
+
+ pendingAcknowledgements = (Collection<Integer>)ReflectUtil.getValue(ReflectUtil.getField(StringCompressor.class, "pendingAcknowledgements"), compressor);
+ assertEquals("pendingAcknowledgements: " + pendingAcknowledgements, 0, pendingAcknowledgements.size());
+ }
+
+ private void createModel(Category parent, int levels)
+ {
+ EList<Category> categories = parent.getCategories();
+ for (int i = 0; i < CATEGORIES; i++)
+ {
+ Category category = getModel1Factory().createCategory();
+ category.setName("Category" + levels + "-" + i);
+ categories.add(category);
+ }
+
+ EList<Product1> products = parent.getProducts();
+ for (int i = 0; i < PRODUCTS; i++)
+ {
+ Product1 product = getModel1Factory().createProduct1();
+ product.setName("Product" + levels + "-" + i);
+ products.add(product);
+ }
+
+ if (levels > 0)
+ {
+ for (Category category : categories)
+ {
+ createModel(category, levels - 1);
+ }
+ }
+ }
+}

Back to the top