Fix so references are properly cleared on Kaffe JVM
bug 34689, by Guilhem Lavaux git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@169101 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
decc437cc7
commit
d9796b6160
|
@ -218,6 +218,9 @@
|
||||||
<contributor>
|
<contributor>
|
||||||
<name>Olaf Krische</name>
|
<name>Olaf Krische</name>
|
||||||
</contributor>
|
</contributor>
|
||||||
|
<contributor>
|
||||||
|
<name>Guilhem Lavaux</name>
|
||||||
|
</contributor>
|
||||||
<contributor>
|
<contributor>
|
||||||
<name>David Leppik</name>
|
<name>David Leppik</name>
|
||||||
</contributor>
|
</contributor>
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.apache.commons.collections.map.AbstractTestMap;
|
||||||
* @version $Revision$ $Date$
|
* @version $Revision$ $Date$
|
||||||
*
|
*
|
||||||
* @author Paul Jack
|
* @author Paul Jack
|
||||||
|
* @author Guilhem Lavaux
|
||||||
*/
|
*/
|
||||||
public class TestReferenceMap extends AbstractTestMap {
|
public class TestReferenceMap extends AbstractTestMap {
|
||||||
|
|
||||||
|
@ -152,14 +153,15 @@ public class TestReferenceMap extends AbstractTestMap {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Tests whether purge values setting works */
|
WeakReference keyReference;
|
||||||
public void testPurgeValues() throws Exception {
|
WeakReference valueReference;
|
||||||
// many thanks to Juozas Baliuka for suggesting this method
|
|
||||||
|
public Map buildRefMap() {
|
||||||
Object key = new Object();
|
Object key = new Object();
|
||||||
Object value = new Object();
|
Object value = new Object();
|
||||||
|
|
||||||
WeakReference keyReference = new WeakReference(key);
|
keyReference = new WeakReference(key);
|
||||||
WeakReference valueReference = new WeakReference(value);
|
valueReference = new WeakReference(value);
|
||||||
|
|
||||||
Map testMap = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.HARD, true);
|
Map testMap = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.HARD, true);
|
||||||
testMap.put(key, value);
|
testMap.put(key, value);
|
||||||
|
@ -167,10 +169,14 @@ public class TestReferenceMap extends AbstractTestMap {
|
||||||
assertEquals("In map", value, testMap.get(key));
|
assertEquals("In map", value, testMap.get(key));
|
||||||
assertNotNull("Weak reference released early (1)", keyReference.get());
|
assertNotNull("Weak reference released early (1)", keyReference.get());
|
||||||
assertNotNull("Weak reference released early (2)", valueReference.get());
|
assertNotNull("Weak reference released early (2)", valueReference.get());
|
||||||
|
return testMap;
|
||||||
|
}
|
||||||
|
|
||||||
// dereference strong references
|
/** Tests whether purge values setting works */
|
||||||
key = null;
|
public void testPurgeValues() throws Exception {
|
||||||
value = null;
|
// many thanks to Juozas Baliuka for suggesting this method
|
||||||
|
|
||||||
|
Map testMap = buildRefMap();
|
||||||
|
|
||||||
int iterations = 0;
|
int iterations = 0;
|
||||||
int bytz = 2;
|
int bytz = 2;
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.apache.commons.collections.IterableMap;
|
||||||
*
|
*
|
||||||
* @author Paul Jack
|
* @author Paul Jack
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
|
* @author Guilhem Lavaux
|
||||||
*/
|
*/
|
||||||
public class TestReferenceIdentityMap extends AbstractTestIterableMap {
|
public class TestReferenceIdentityMap extends AbstractTestIterableMap {
|
||||||
|
|
||||||
|
@ -261,25 +262,29 @@ public class TestReferenceIdentityMap extends AbstractTestIterableMap {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Tests whether purge values setting works */
|
WeakReference keyReference;
|
||||||
public void testPurgeValues() throws Exception {
|
WeakReference valueReference;
|
||||||
// many thanks to Juozas Baliuka for suggesting this method
|
|
||||||
|
public Map buildRefMap() {
|
||||||
Object key = new Object();
|
Object key = new Object();
|
||||||
Object value = new Object();
|
Object value = new Object();
|
||||||
|
|
||||||
WeakReference keyReference = new WeakReference(key);
|
keyReference = new WeakReference(key);
|
||||||
WeakReference valueReference = new WeakReference(value);
|
valueReference = new WeakReference(value);
|
||||||
|
|
||||||
Map testMap = new ReferenceIdentityMap(ReferenceIdentityMap.WEAK, ReferenceIdentityMap.HARD, true);
|
Map testMap = new ReferenceIdentityMap(ReferenceMap.WEAK, ReferenceMap.HARD, true);
|
||||||
testMap.put(key, value);
|
testMap.put(key, value);
|
||||||
|
|
||||||
assertEquals("In map", value, testMap.get(key));
|
assertEquals("In map", value, testMap.get(key));
|
||||||
assertNotNull("Weak reference released early (1)", keyReference.get());
|
assertNotNull("Weak reference released early (1)", keyReference.get());
|
||||||
assertNotNull("Weak reference released early (2)", valueReference.get());
|
assertNotNull("Weak reference released early (2)", valueReference.get());
|
||||||
|
return testMap;
|
||||||
|
}
|
||||||
|
|
||||||
// dereference strong references
|
/** Tests whether purge values setting works */
|
||||||
key = null;
|
public void testPurgeValues() throws Exception {
|
||||||
value = null;
|
// many thanks to Juozas Baliuka for suggesting this method
|
||||||
|
Map testMap = buildRefMap();
|
||||||
|
|
||||||
int iterations = 0;
|
int iterations = 0;
|
||||||
int bytz = 2;
|
int bytz = 2;
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.apache.commons.collections.BulkTest;
|
||||||
* @version $Revision$ $Date$
|
* @version $Revision$ $Date$
|
||||||
*
|
*
|
||||||
* @author Paul Jack
|
* @author Paul Jack
|
||||||
|
* @author Guilhem Lavaux
|
||||||
*/
|
*/
|
||||||
public class TestReferenceMap extends AbstractTestIterableMap {
|
public class TestReferenceMap extends AbstractTestIterableMap {
|
||||||
|
|
||||||
|
@ -196,14 +197,15 @@ public class TestReferenceMap extends AbstractTestIterableMap {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Tests whether purge values setting works */
|
WeakReference keyReference;
|
||||||
public void testPurgeValues() throws Exception {
|
WeakReference valueReference;
|
||||||
// many thanks to Juozas Baliuka for suggesting this method
|
|
||||||
|
public Map buildRefMap() {
|
||||||
Object key = new Object();
|
Object key = new Object();
|
||||||
Object value = new Object();
|
Object value = new Object();
|
||||||
|
|
||||||
WeakReference keyReference = new WeakReference(key);
|
keyReference = new WeakReference(key);
|
||||||
WeakReference valueReference = new WeakReference(value);
|
valueReference = new WeakReference(value);
|
||||||
|
|
||||||
Map testMap = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.HARD, true);
|
Map testMap = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.HARD, true);
|
||||||
testMap.put(key, value);
|
testMap.put(key, value);
|
||||||
|
@ -211,10 +213,13 @@ public class TestReferenceMap extends AbstractTestIterableMap {
|
||||||
assertEquals("In map", value, testMap.get(key));
|
assertEquals("In map", value, testMap.get(key));
|
||||||
assertNotNull("Weak reference released early (1)", keyReference.get());
|
assertNotNull("Weak reference released early (1)", keyReference.get());
|
||||||
assertNotNull("Weak reference released early (2)", valueReference.get());
|
assertNotNull("Weak reference released early (2)", valueReference.get());
|
||||||
|
return testMap;
|
||||||
|
}
|
||||||
|
|
||||||
// dereference strong references
|
/** Tests whether purge values setting works */
|
||||||
key = null;
|
public void testPurgeValues() throws Exception {
|
||||||
value = null;
|
// many thanks to Juozas Baliuka for suggesting this method
|
||||||
|
Map testMap = buildRefMap();
|
||||||
|
|
||||||
int iterations = 0;
|
int iterations = 0;
|
||||||
int bytz = 2;
|
int bytz = 2;
|
||||||
|
|
Loading…
Reference in New Issue