Skip to content

Commit

Permalink
ISPN-5295 Remote cache entries with sub-second lifetime never expire
Browse files Browse the repository at this point in the history
  • Loading branch information
erlyfall authored and danberindei committed Mar 16, 2015
1 parent 1a03a0a commit 9ce3b43
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,15 @@ private MetadataValue<V> binary2MetadataValue(MetadataValue<byte[]> value) {
return new MetadataValueImpl<V>(value.getCreated(), value.getLifespan(), value.getLastUsed(), value.getMaxIdle(), value.getVersion(), valueObj);
}

private int toSeconds(long duration, TimeUnit timeUnit) {
return (int) timeUnit.toSeconds(duration);
protected static int toSeconds(long duration, TimeUnit timeUnit) {
int seconds = (int) timeUnit.toSeconds(duration);
long inverseDuration = timeUnit.convert(seconds, TimeUnit.SECONDS);

if (duration > inverseDuration) {
//Round up.
seconds++;
}
return seconds;
}

private void assertRemoteCacheManagerIsStarted() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.infinispan.client.hotrod.impl;

import static org.junit.Assert.assertEquals;

import java.util.concurrent.TimeUnit;

import org.testng.annotations.Test;

@Test (testName = "client.hotrod.RemoteCacheImplTest", groups = "unit" )
public class RemoteCacheImplTest {
@Test
public void testSubsecondConversion() {
assertEquals(0, RemoteCacheImpl.toSeconds(0, TimeUnit.MILLISECONDS));
assertEquals(1, RemoteCacheImpl.toSeconds(1, TimeUnit.MILLISECONDS));
assertEquals(1, RemoteCacheImpl.toSeconds(999, TimeUnit.MILLISECONDS));
assertEquals(1, RemoteCacheImpl.toSeconds(1000, TimeUnit.MILLISECONDS));
}

@Test
public void testFractionOfSecondConversion() {
assertEquals(2, RemoteCacheImpl.toSeconds(1001, TimeUnit.MILLISECONDS));
assertEquals(2, RemoteCacheImpl.toSeconds(1999, TimeUnit.MILLISECONDS));
assertEquals(2, RemoteCacheImpl.toSeconds(2000, TimeUnit.MILLISECONDS));
assertEquals(3, RemoteCacheImpl.toSeconds(2001, TimeUnit.MILLISECONDS));
}
}

0 comments on commit 9ce3b43

Please sign in to comment.