Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2016-08-25 14:55:41 +0000
committerAndrey Loskutov2016-08-25 14:55:41 +0000
commitba0abc228cde4836afb6bc6fc4baf8259973e762 (patch)
tree425421aaba53b162dfbf13fdfbe4e24187b8c2ab
parent60e34dbeeeb3d5c8a2fe7f2e81a93bcdbd2b7b00 (diff)
downloadeclipse.platform.debug-ba0abc228cde4836afb6bc6fc4baf8259973e762.tar.gz
eclipse.platform.debug-ba0abc228cde4836afb6bc6fc4baf8259973e762.tar.xz
eclipse.platform.debug-ba0abc228cde4836afb6bc6fc4baf8259973e762.zip
Bug 500273 - Removing elements from source lookup cache not workingY20160908-1000Y20160901-1000I20160906-0800I20160830-0800
properly Applied patch from Alexander Schwarz and added test for the LRU cache. Change-Id: I145af345d019a7f1414e7b97d1802891948ccf91 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/SourceLookupFacilityTests.java49
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupFacility.java2
2 files changed, 49 insertions, 2 deletions
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/SourceLookupFacilityTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/SourceLookupFacilityTests.java
index 9e474edd1..693f81b0e 100644
--- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/SourceLookupFacilityTests.java
+++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/SourceLookupFacilityTests.java
@@ -10,12 +10,17 @@
*******************************************************************************/
package org.eclipse.debug.tests.sourcelookup;
-import junit.framework.TestCase;
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
import org.eclipse.debug.core.model.IStackFrame;
import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupFacility;
+import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupResult;
import org.eclipse.debug.ui.sourcelookup.ISourceLookupResult;
+import junit.framework.TestCase;
+
/**
* Tests {@link SourceLookupFacility}
*
@@ -289,4 +294,46 @@ public class SourceLookupFacilityTests extends TestCase {
SourceLookupFacility.shutdown();
}
}
+
+ public void testLRU() throws Exception {
+ try {
+ final int MAX_LRU_SIZE = 10;
+
+ // Get the original map
+ Field field = SourceLookupFacility.class.getDeclaredField("fLookupResults"); //$NON-NLS-1$
+ field.setAccessible(true);
+ HashMap<?, ?> map = (HashMap<?, ?>) field.get(null);
+ LinkedHashMap<String, ISourceLookupResult> cached = new LinkedHashMap<>();
+
+ // fill the LRU with one element overflow
+ for (int i = 0; i < MAX_LRU_SIZE + 1; i++) {
+ String artifact = "" + i; //$NON-NLS-1$
+ ISourceLookupResult result = SourceLookupFacility.getDefault().lookup(artifact, fTestLocator, false);
+ assertNotNull("There should be a result", result); //$NON-NLS-1$
+ assertFalse(cached.containsKey(result));
+ cached.put(artifact, result);
+
+ result = SourceLookupFacility.getDefault().lookup(artifact, fTestLocator, false);
+ assertTrue(cached.containsValue(result));
+ assertTrue(map.size() <= MAX_LRU_SIZE);
+ }
+ assertEquals(MAX_LRU_SIZE, map.size());
+
+
+ // The LRU cache is full now, and the very first element should be
+ // *not* in the LRU cache anymore
+ assertFalse(map.containsValue(cached.values().iterator().next()));
+
+ // If we lookup for the first element again, we should get new one
+ String artifact = "" + 0; //$NON-NLS-1$
+ SourceLookupResult result = SourceLookupFacility.getDefault().lookup(artifact, fTestLocator, false);
+ assertNotNull("There should be a result", result); //$NON-NLS-1$
+ assertFalse(cached.containsValue(result));
+
+ // Check: the LRU map size should not grow
+ assertEquals(MAX_LRU_SIZE, map.size());
+ } finally {
+ SourceLookupFacility.shutdown();
+ }
+ }
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupFacility.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupFacility.java
index 6c3f986bc..01b402f9e 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupFacility.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupFacility.java
@@ -116,7 +116,7 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro
@Override
public SourceLookupResult remove(Object key) {
SourceLookupResult oldResult = super.remove(key);
- fEntryStack.remove(oldResult);
+ fEntryStack.remove(key);
return oldResult;
}

Back to the top