File tree Expand file tree Collapse file tree 4 files changed +53
-5
lines changed
main/java/io/github/grrolland/hcshm
test/java/io/github/grrolland/hcshm Expand file tree Collapse file tree 4 files changed +53
-5
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff line change 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 ,
Original file line number Diff line number Diff 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 /**
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments