summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-12-18 11:12:00 (EST)
committerEike Stepper2007-12-18 11:12:00 (EST)
commit75fe07082b25168d37ce697abd4022664e695650 (patch)
tree9f8857b450128e86dd218fe7981abfb2be3618a3
parent2af988b3fea51871dbbe17e6c3fa1d692cfcbd4e (diff)
downloadcdo-75fe07082b25168d37ce697abd4022664e695650.zip
cdo-75fe07082b25168d37ce697abd4022664e695650.tar.gz
cdo-75fe07082b25168d37ce697abd4022664e695650.tar.bz2
[209490] Put purging mechanism in CDOViewIMpl::objects to avoid OutOfMemory
https://bugs.eclipse.org/bugs/show_bug.cgi?id=209490
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/SensitiveProtoTest.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/SensitiveProtoTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/SensitiveProtoTest.java
new file mode 100644
index 0000000..c603d25
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/SensitiveProtoTest.java
@@ -0,0 +1,83 @@
+/***************************************************************************
+ * 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.net4j.util.tests.cache;
+
+import org.eclipse.net4j.util.ref.KeyedWeakReference;
+import org.eclipse.net4j.util.tests.AbstractOMTest;
+
+import java.lang.ref.ReferenceQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * @author Eike Stepper
+ */
+public class SensitiveProtoTest extends AbstractOMTest
+{
+ public void testSensitiveCacheWithEvictionPolicy() throws Exception
+ {
+ ConcurrentMap<Integer, KeyedAndValuedWeakReference<Integer, String>> map //
+ = new ConcurrentHashMap<Integer, KeyedAndValuedWeakReference<Integer, String>>();
+
+ ReferenceQueue<String> queue //
+ = new ReferenceQueue<String>();
+
+ for (int i = 0; i < 20; i++)
+ {
+ map.put(i, new KeyedAndValuedWeakReference<Integer, String>(i, String.valueOf(i), queue));
+ }
+
+ for (int gc = 0; gc < 10; gc++)
+ {
+ System.gc();
+ sleep(100);
+ }
+
+ KeyedAndValuedWeakReference<Integer, String> ref;
+ while ((ref = (KeyedAndValuedWeakReference<Integer, String>)queue.poll()) != null)
+ {
+ int i = ref.getKey();
+ System.out.println("Dequeued i=" + i);
+ if (i < 10)
+ {
+ map.put(i, new KeyedAndValuedWeakReference<Integer, String>(i, ref.getValue(), queue));
+ }
+ else
+ {
+ map.remove(i, ref);
+ }
+ }
+
+ assertEquals(10, map.size());
+ }
+
+ public static class KeyedAndValuedWeakReference<K, T> extends KeyedWeakReference<K, T>
+ {
+ private T value;
+
+ public KeyedAndValuedWeakReference(K key, T ref, ReferenceQueue<T> queue)
+ {
+ super(key, ref, queue);
+ value = ref;
+ }
+
+ public KeyedAndValuedWeakReference(K key, T ref)
+ {
+ super(key, ref);
+ value = ref;
+ }
+
+ public T getValue()
+ {
+ return value;
+ }
+ }
+}