Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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