[COLLECTIONS-475] Fixed conversion of timeout parameters in PassiveExpiringMap.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1503029 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2013-07-14 19:09:25 +00:00
parent d639a9b437
commit 4951344fb2
5 changed files with 35 additions and 5 deletions

View File

@ -46,7 +46,8 @@ Major changes since 3.2.1
Changes since 4.0-alpha1
------------------------
- renamed CompliantBag to CollectionBag
- [COLLECTIONS-468] Renamed CompliantBag to CollectionBag.
- [COLLECTIONS-475] Fixed conversion of timeout parameters in "PassiveExpiringMap".
Removed classes
@ -206,6 +207,7 @@ Changed classes / methods
Fixed Bugs
----------
o [COLLECTIONS-475] Fixed conversion of timeout parameters in "PassiveExpiringMap".
o [COLLECTIONS-474] ListOrderedMap#putAll(index, Object, Object) does not throw an exception anymore if the
map contains null values. Additionally added javadoc clarification on the supported bounds
for the index parameter. Thanks to Ning Chen.

View File

@ -22,8 +22,11 @@
<body>
<release version="4.0" date="TBA" description="Next release">
<action issue="COLLECTIONS-474" dev="sebb" type="fix" due-to="Ning Chen ">
Exception in ListOrderedMap#putAll if map contains null values.
<action issue="COLLECTIONS-475" dev="tn" type="fix">
Fixed conversion of timeout parameters in "PassiveExpiringMap".
</action>
<action issue="COLLECTIONS-474" dev="sebb" type="fix" due-to="Ning Chen">
Exception in "ListOrderedMap#putAll" if map contains null values.
</action>
<action issue="COLLECTIONS-473" dev="tn" type="update" due-to="sebb">
Made field "collection" in class "AbstractCollectionDecorator" private and added

View File

@ -121,7 +121,7 @@ public class PassiveExpiringMap<K, V>
*/
public ConstantTimeToLiveExpirationPolicy(final long timeToLive,
final TimeUnit timeUnit) {
this(validateAndConvertToMillis(timeToLive, TimeUnit.MILLISECONDS));
this(validateAndConvertToMillis(timeToLive, timeUnit));
}
/**
@ -196,7 +196,7 @@ public class PassiveExpiringMap<K, V>
if (timeUnit == null) {
throw new IllegalArgumentException("Time unit must not be null");
}
return timeUnit.convert(timeToLive, TimeUnit.MILLISECONDS);
return TimeUnit.MILLISECONDS.convert(timeToLive, timeUnit);
}
/** map used to manage expiration times for the actual map entries. */

View File

@ -186,6 +186,7 @@ This release is <b>not</b> source or binary compatible with v3.x.
<center><h3>Bugfixes</h3></center>
<ul>
<li>Fixed conversion of timeout parameters in "PassiveExpiringMap".</li>
<li>ListOrderedMap#putAll(index, Object, Object) does not throw an exception anymore if the map contains null values. Additionally added javadoc clarification on the supported bounds for the index parameter. Thanks to Ning Chen.</li>
<li>Improved performance of "AbstractMapBag#containsAll(Collection)" by returning immediately after a difference has been found. Thanks to Adrian Nistor.</li>
<li>Added additional clarification to javadoc of interface "Put" wrt return type of "put(Object, Object)" method. Thanks to Matt Benson, sebb.</li>

View File

@ -225,4 +225,28 @@ public class PassiveExpiringMapTest<K, V> extends AbstractMapTest<K, V> {
m.put("a", "b");
assertNull(m.get("a"));
}
public void testExpiration() {
validateExpiration(new PassiveExpiringMap<String, String>(500), 500);
validateExpiration(new PassiveExpiringMap<String, String>(1000), 1000);
validateExpiration(new PassiveExpiringMap<String, String>(
new PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<String, String>(500)), 500);
validateExpiration(new PassiveExpiringMap<String, String>(
new PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<String, String>(1, TimeUnit.SECONDS)), 1000);
}
private void validateExpiration(final Map<String, String> map, long timeout) {
map.put("a", "b");
assertNotNull(map.get("a"));
try {
Thread.sleep(2 * timeout);
} catch (InterruptedException e) {
fail();
}
assertNull(map.get("a"));
}
}