Skip to content

Commit ba4d62a

Browse files
author
THAVEAU Alexis
committed
feat(incr): decrease lasting time threshold deadline from 1000ms to 100ms
1 parent 70fda5d commit ba4d62a

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

src/main/java/io/github/grrolland/hcshm/ShmValue.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,15 @@ public String getValue() {
5151
/**
5252
* Get le lasting time for the value
5353
* <p>
54-
* When the time to the expiration deadline is lower than 1000, return -1.
55-
* <p>
56-
* tha mean the value should expire immediately
54+
* When the time to the expiration deadline is lower than 100 milliseconds, return -1.
55+
* That mean the value should expire immediately
5756
*
5857
* @return the time to the expiration deadline
5958
*/
6059
public long getLastingTime() {
6160
if (doExpire) {
6261
final long lt = deadline - System.currentTimeMillis();
63-
if (lt < 1000) {
62+
if (lt < 100) {
6463
return -1;
6564
} else {
6665
return lt;

src/test/java/io/github/grrolland/hcshm/HCSHMTestSuite.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
* Test Suite initializing the distributed SHM
3030
*/
3131
@RunWith(Suite.class)
32-
@Suite.SuiteClasses({DeleteTestCase.class,
32+
@Suite.SuiteClasses({ShmValueTestCase.class,
33+
DeleteTestCase.class,
3334
GetTestCase.class,
3435
IncrTestCase.class,
3536
QuitTestCase.class,

src/test/java/io/github/grrolland/hcshm/IncrTestCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,15 @@ public void testIncrExpire() {
9292
public void testMultiIncrExpireLoad() throws IOException {
9393
Logger logger = (Logger) LoggerFactory.getLogger(IncrTestCase.class);
9494
logger.setLevel(Level.INFO);
95+
9596
// Increment key
9697
for (int i = 1; i <= 200; i++) {
9798
getWriter().write("INCR key 1 0 60\r\n");
9899
getWriter().flush();
99100
logger.info("Expect value {}", i);
100101
assertResponseGetValue(String.valueOf(i));
101102
}
103+
logger.info("DONE");
102104
}
103105

104106
/**
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package io.github.grrolland.hcshm;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
import static org.junit.Assert.assertTrue;
7+
8+
/***
9+
* ShmValue test case
10+
*/
11+
public class ShmValueTestCase {
12+
13+
@Test
14+
public void getValue() {
15+
ShmValue shmValue = new ShmValue("X", 0);
16+
assertEquals("X", shmValue.getValue());
17+
}
18+
19+
@Test
20+
public void getLastingTime() {
21+
ShmValue shmValue = new ShmValue("X", 0);
22+
assertEquals(0, shmValue.getLastingTime());
23+
}
24+
25+
@Test
26+
public void getLastingTimeExpired() {
27+
ShmValue shmValue = new ShmValue("X", 99);
28+
assertEquals(-1, shmValue.getLastingTime());
29+
}
30+
31+
@Test
32+
public void getLastingTimeNotExpired() {
33+
ShmValue shmValue = new ShmValue("X", 150);
34+
assertTrue(shmValue.getLastingTime() > 100);
35+
}
36+
37+
@Test
38+
public void expire() {
39+
ShmValue shmValue = new ShmValue("X", 0);
40+
assertEquals(0, shmValue.getLastingTime());
41+
shmValue.expire(150);
42+
assertTrue(shmValue.getLastingTime() > 100);
43+
shmValue.expire(99);
44+
assertEquals(-1, shmValue.getLastingTime());
45+
}
46+
}

0 commit comments

Comments
 (0)