diff --git a/src/main/java/io/github/grrolland/hcshm/ShmValue.java b/src/main/java/io/github/grrolland/hcshm/ShmValue.java index e9a2e97..01820bd 100644 --- a/src/main/java/io/github/grrolland/hcshm/ShmValue.java +++ b/src/main/java/io/github/grrolland/hcshm/ShmValue.java @@ -51,16 +51,15 @@ public String getValue() { /** * Get le lasting time for the value *
- * When the time to the expiration deadline is lower than 1000, return -1. - *
- * tha mean the value should expire immediately + * When the time to the expiration deadline is lower than 100 milliseconds, return -1. + * That mean the value should expire immediately * * @return the time to the expiration deadline */ public long getLastingTime() { if (doExpire) { final long lt = deadline - System.currentTimeMillis(); - if (lt < 1000) { + if (lt < 100) { return -1; } else { return lt; diff --git a/src/test/java/io/github/grrolland/hcshm/HCSHMTestSuite.java b/src/test/java/io/github/grrolland/hcshm/HCSHMTestSuite.java index c855a17..3046a25 100644 --- a/src/test/java/io/github/grrolland/hcshm/HCSHMTestSuite.java +++ b/src/test/java/io/github/grrolland/hcshm/HCSHMTestSuite.java @@ -29,7 +29,8 @@ * Test Suite initializing the distributed SHM */ @RunWith(Suite.class) -@Suite.SuiteClasses({DeleteTestCase.class, +@Suite.SuiteClasses({ShmValueTestCase.class, + DeleteTestCase.class, GetTestCase.class, IncrTestCase.class, QuitTestCase.class, diff --git a/src/test/java/io/github/grrolland/hcshm/IncrTestCase.java b/src/test/java/io/github/grrolland/hcshm/IncrTestCase.java index 08101c0..36c46b6 100644 --- a/src/test/java/io/github/grrolland/hcshm/IncrTestCase.java +++ b/src/test/java/io/github/grrolland/hcshm/IncrTestCase.java @@ -92,6 +92,7 @@ public void testIncrExpire() { public void testMultiIncrExpireLoad() throws IOException { Logger logger = (Logger) LoggerFactory.getLogger(IncrTestCase.class); logger.setLevel(Level.INFO); + // Increment key for (int i = 1; i <= 200; i++) { getWriter().write("INCR key 1 0 60\r\n"); @@ -99,6 +100,7 @@ public void testMultiIncrExpireLoad() throws IOException { logger.info("Expect value {}", i); assertResponseGetValue(String.valueOf(i)); } + logger.info("DONE"); } /** diff --git a/src/test/java/io/github/grrolland/hcshm/ShmValueTestCase.java b/src/test/java/io/github/grrolland/hcshm/ShmValueTestCase.java new file mode 100644 index 0000000..8d888ca --- /dev/null +++ b/src/test/java/io/github/grrolland/hcshm/ShmValueTestCase.java @@ -0,0 +1,46 @@ +package io.github.grrolland.hcshm; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/*** + * ShmValue test case + */ +public class ShmValueTestCase { + + @Test + public void getValue() { + ShmValue shmValue = new ShmValue("X", 0); + assertEquals("X", shmValue.getValue()); + } + + @Test + public void getLastingTime() { + ShmValue shmValue = new ShmValue("X", 0); + assertEquals(0, shmValue.getLastingTime()); + } + + @Test + public void getLastingTimeExpired() { + ShmValue shmValue = new ShmValue("X", 99); + assertEquals(-1, shmValue.getLastingTime()); + } + + @Test + public void getLastingTimeNotExpired() { + ShmValue shmValue = new ShmValue("X", 150); + assertTrue(shmValue.getLastingTime() > 100); + } + + @Test + public void expire() { + ShmValue shmValue = new ShmValue("X", 0); + assertEquals(0, shmValue.getLastingTime()); + shmValue.expire(150); + assertTrue(shmValue.getLastingTime() > 100); + shmValue.expire(99); + assertEquals(-1, shmValue.getLastingTime()); + } +}