Skip to content

Commit

Permalink
Merge pull request #8111 from ahmetmircik/fix/3.6.3/expirationTimeCal…
Browse files Browse the repository at this point in the history
…culationAgainstLatestUpdate

Calculates expiration time based on latest update time
  • Loading branch information
pveentjer committed May 8, 2016
2 parents e687d8a + 0b7048f commit 32aa81e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static void updateExpiryTime(Record record, long ttl, MapConfig mapConfig

// Preserve previously set TTL, if TTL < 0.
if (ttl < 0) {
return;
ttl = record.getTtl();
}
// If TTL == 0, convert it to Long.MAX_VALUE.
ttl = checkedTime(ttl);
Expand Down Expand Up @@ -167,6 +167,4 @@ public static long calculateExpirationWithDelay(long timeInMillis, long delayMil
}
return timeInMillis;
}


}
28 changes: 22 additions & 6 deletions hazelcast/src/test/java/com/hazelcast/map/ExpirationTimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import java.util.concurrent.TimeUnit;

import static java.util.concurrent.TimeUnit.MINUTES;
import static org.junit.Assert.assertEquals;

@RunWith(HazelcastParallelClassRunner.class)
Expand All @@ -41,11 +42,11 @@ public class ExpirationTimeTest extends HazelcastTestSupport {
public void testExpirationTime_withTTL() throws Exception {
IMap<Integer, Integer> map = createMap();

map.put(1, 1, 1, TimeUnit.MINUTES);
map.put(1, 1, 1, MINUTES);

EntryView<Integer, Integer> entryView = map.getEntryView(1);

long TTL = TimeUnit.MINUTES.toMillis(1);
long TTL = MINUTES.toMillis(1);
long creationTime = entryView.getCreationTime();

long expectedExpirationTime = creationTime + TTL;
Expand All @@ -59,19 +60,19 @@ public void testExpirationTime_withTTL() throws Exception {
public void testExpirationTime_withTTL_afterMultipleUpdates() throws Exception {
IMap<Integer, Integer> map = createMap();

map.put(1, 1, 1, TimeUnit.MINUTES);
map.put(1, 1, 1, MINUTES);

sleepMillis(1);

map.put(1, 1, 1, TimeUnit.MINUTES);
map.put(1, 1, 1, MINUTES);

sleepMillis(1);

map.put(1, 1, 1, TimeUnit.MINUTES);
map.put(1, 1, 1, MINUTES);

EntryView<Integer, Integer> entryView = map.getEntryView(1);

long TTL = TimeUnit.MINUTES.toMillis(1);
long TTL = MINUTES.toMillis(1);
long lastUpdateTime = entryView.getLastUpdateTime();

long expectedExpirationTime = lastUpdateTime + TTL;
Expand Down Expand Up @@ -165,6 +166,21 @@ public void testLastAccessTime_isZero_afterFirstPut() throws Exception {
assertEquals(0L, entryView.getLastAccessTime());
}


@Test
public void testExpirationTime_calculated_against_lastUpdateTime_after_PutWithNoTTL() throws Exception {
IMap<Integer, Integer> map = createMap();

map.put(1, 1, 1, MINUTES);
sleepMillis(1);
map.put(1, 1);

EntryView<Integer, Integer> entryView = map.getEntryView(1);
long expectedExpirationTime = entryView.getLastUpdateTime() + MINUTES.toMillis(1);

assertEquals(expectedExpirationTime, entryView.getExpirationTime());
}

private IMap<Integer, Integer> createMap() {
String mapName = randomMapName();
HazelcastInstance node = createHazelcastInstance(getConfig());
Expand Down

0 comments on commit 32aa81e

Please sign in to comment.