Skip to content

Commit

Permalink
Return null old value when expired on putX (fixes #26)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Sep 3, 2015
1 parent 2c257b9 commit 3961508
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ V put(K key, V value, boolean notifyWriter, boolean onlyIfAbsent) {
afterRead(prior, now, false);
}

return oldValue;
return expired ? null : oldValue;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ public void putIfAbsent_writerFails(Map<Integer, Integer> map, CacheContext cont
expireAfterWrite = {Expire.DISABLED, Expire.ONE_MINUTE})
public void put_insert(Map<Integer, Integer> map, CacheContext context) {
context.ticker().advance(1, TimeUnit.MINUTES);
map.put(context.firstKey(), context.absentValue());
assertThat(map.put(context.firstKey(), context.absentValue()), is(nullValue()));

long count = context.initialSize();
assertThat(map.size(), is(1));
Expand All @@ -616,8 +616,8 @@ public void put_insert(Map<Integer, Integer> map, CacheContext context) {
public void put_replace(Map<Integer, Integer> map, CacheContext context) {
context.ticker().advance(30, TimeUnit.SECONDS);

map.put(context.firstKey(), context.absentValue());
map.put(context.absentKey(), context.absentValue());
assertThat(map.put(context.firstKey(), context.absentValue()), is(not(nullValue())));
assertThat(map.put(context.absentKey(), context.absentValue()), is(nullValue()));
context.consumedNotifications().clear(); // Ignore replacement notification

context.ticker().advance(45, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void putIfAbsent(Map<Integer, Integer> map, CacheContext context) {
assertThat(map.putIfAbsent(context.firstKey(), context.absentValue()), is(not(nullValue())));

context.ticker().advance(30, TimeUnit.SECONDS);
map.putIfAbsent(context.lastKey(), context.absentValue());
assertThat(map.putIfAbsent(context.lastKey(), context.absentValue()), is(nullValue()));

long count = context.initialSize() - 1;
assertThat(map.size(), is(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void putIfAbsent(Map<Integer, Integer> map, CacheContext context) {
assertThat(map.putIfAbsent(context.firstKey(), context.absentValue()), is(not(nullValue())));

context.ticker().advance(30, TimeUnit.SECONDS);
map.putIfAbsent(context.lastKey(), context.absentValue());
assertThat(map.putIfAbsent(context.lastKey(), context.absentValue()), is(nullValue()));

long count = context.initialSize();
assertThat(map.size(), is(1));
Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ext {
ehcache2: '2.10.0-10',
ehcache3: '3.0.0.m2',
high_scale_lib: '1.0.6',
infinispan: '8.0.0.CR1',
infinispan: '8.0.0.Final',
jackrabbit: '1.3.4',
jamm: '0.3.1',
java_object_layout: '0.3.2',
Expand Down

0 comments on commit 3961508

Please sign in to comment.