commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject commons-collections git commit: [COLLECTIONS-703] The PassiveExpiringMap#put() method should return the previous record only if not expired.
Date Fri, 23 Nov 2018 07:51:22 GMT
Repository: commons-collections
Updated Branches:
  refs/heads/master c15be5398 -> 26bebdafe


[COLLECTIONS-703] The PassiveExpiringMap#put() method should return the
previous record only if not expired.

Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/26bebdaf
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/26bebdaf
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/26bebdaf

Branch: refs/heads/master
Commit: 26bebdafe451c5992398c8c69e06de11845e6666
Parents: c15be53
Author: Tomas Tulka <tomas.tulka@gmail.com>
Authored: Fri Nov 23 00:51:19 2018 -0700
Committer: Gary Gregory <garydgregory@gmail.com>
Committed: Fri Nov 23 00:51:19 2018 -0700

----------------------------------------------------------------------
 src/changes/changes.xml                         |  3 ++
 .../collections4/map/PassiveExpiringMap.java    |  3 ++
 .../map/PassiveExpiringMapTest.java             | 30 +++++++++++++-------
 3 files changed, 26 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-collections/blob/26bebdaf/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4881baa..28a02c9 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -39,6 +39,9 @@
     <action issue="COLLECTIONS-701" dev="ggregory" type="fix" due-to="Shin Hong, Don Jeba">
       StackOverflowError in SetUniqueList.add() when it receives itself.
     </action>
+    <action issue="COLLECTIONS-703" dev="ggregory" type="fix" due-to="Tomas Tulka">
+      The PassiveExpiringMap#put() method should return the previous record only if not expired.
+    </action>
   </release>
   <release version="4.2" date="2018-07-11" description="Update from Java 6 to Java 7,
bug fixes, and small changes.">
     <action issue="COLLECTIONS-681" dev="kinow" type="add" due-to="Stephan Fuhrmann">

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/26bebdaf/src/main/java/org/apache/commons/collections4/map/PassiveExpiringMap.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/collections4/map/PassiveExpiringMap.java b/src/main/java/org/apache/commons/collections4/map/PassiveExpiringMap.java
index d8565e6..76a0d84 100644
--- a/src/main/java/org/apache/commons/collections4/map/PassiveExpiringMap.java
+++ b/src/main/java/org/apache/commons/collections4/map/PassiveExpiringMap.java
@@ -430,6 +430,9 @@ public class PassiveExpiringMap<K, V>
     */
     @Override
     public V put(final K key, final V value) {
+        // remove the previous record
+        removeIfExpired(key, now());
+
         // record expiration time of new entry
         final long expirationTime = expiringPolicy.expirationTime(key, value);
         expirationMap.put(key, Long.valueOf(expirationTime));

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/26bebdaf/src/test/java/org/apache/commons/collections4/map/PassiveExpiringMapTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/collections4/map/PassiveExpiringMapTest.java
b/src/test/java/org/apache/commons/collections4/map/PassiveExpiringMapTest.java
index f09105c..0dee598 100644
--- a/src/test/java/org/apache/commons/collections4/map/PassiveExpiringMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/map/PassiveExpiringMapTest.java
@@ -181,6 +181,15 @@ public class PassiveExpiringMapTest<K, V> extends AbstractMapTest<K,
V> {
         assertEquals(3, m.entrySet().size());
     }
 
+    public void testExpiration() {
+        validateExpiration(new PassiveExpiringMap<String, String>(500), 500);
+        validateExpiration(new PassiveExpiringMap<String, String>(1000), 1000);
+        validateExpiration(new PassiveExpiringMap<>(
+                new PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<String, String>(500)),
500);
+        validateExpiration(new PassiveExpiringMap<>(
+                new PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<String, String>(1,
TimeUnit.SECONDS)), 1000);
+    }
+
     public void testGet() {
         final Map<Integer, String> m = makeTestMap();
         assertNull(m.get(Integer.valueOf(1)));
@@ -208,6 +217,16 @@ public class PassiveExpiringMapTest<K, V> extends AbstractMapTest<K,
V> {
         assertEquals(3, m.keySet().size());
     }
 
+    public void testPut() {
+        final Map<Integer, String> m = makeTestMap();
+        assertNull(m.put(Integer.valueOf(1), "ONE"));
+        assertEquals("two", m.put(Integer.valueOf(2), "TWO"));
+        assertNull(m.put(Integer.valueOf(3), "THREE"));
+        assertEquals("four", m.put(Integer.valueOf(4), "FOUR"));
+        assertNull(m.put(Integer.valueOf(5), "FIVE"));
+        assertEquals("six", m.put(Integer.valueOf(6), "SIX"));
+    }
+
     public void testSize() {
         final Map<Integer, String> m = makeTestMap();
         assertEquals(3, m.size());
@@ -225,15 +244,6 @@ public class PassiveExpiringMapTest<K, V> extends AbstractMapTest<K,
V> {
         assertNull(m.get("a"));
     }
 
-    public void testExpiration() {
-        validateExpiration(new PassiveExpiringMap<String, String>(500), 500);
-        validateExpiration(new PassiveExpiringMap<String, String>(1000), 1000);
-        validateExpiration(new PassiveExpiringMap<>(
-                new PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<String, String>(500)),
500);
-        validateExpiration(new PassiveExpiringMap<>(
-                new PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<String, String>(1,
TimeUnit.SECONDS)), 1000);
-    }
-
     private void validateExpiration(final Map<String, String> map, final long timeout)
{
         map.put("a", "b");
 
@@ -247,5 +257,5 @@ public class PassiveExpiringMapTest<K, V> extends AbstractMapTest<K,
V> {
 
         assertNull(map.get("a"));
     }
-
+     
 }


Mime
View raw message