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() {
51
51
/**
52
52
* Get le lasting time for the value
53
53
* <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
57
56
*
58
57
* @return the time to the expiration deadline
59
58
*/
60
59
public long getLastingTime () {
61
60
if (doExpire ) {
62
61
final long lt = deadline - System .currentTimeMillis ();
63
- if (lt < 1000 ) {
62
+ if (lt < 100 ) {
64
63
return -1 ;
65
64
} else {
66
65
return lt ;
Original file line number Diff line number Diff line change 29
29
* Test Suite initializing the distributed SHM
30
30
*/
31
31
@ RunWith (Suite .class )
32
- @ Suite .SuiteClasses ({DeleteTestCase .class ,
32
+ @ Suite .SuiteClasses ({ShmValueTestCase .class ,
33
+ DeleteTestCase .class ,
33
34
GetTestCase .class ,
34
35
IncrTestCase .class ,
35
36
QuitTestCase .class ,
Original file line number Diff line number Diff line change @@ -92,13 +92,15 @@ public void testIncrExpire() {
92
92
public void testMultiIncrExpireLoad () throws IOException {
93
93
Logger logger = (Logger ) LoggerFactory .getLogger (IncrTestCase .class );
94
94
logger .setLevel (Level .INFO );
95
+
95
96
// Increment key
96
97
for (int i = 1 ; i <= 200 ; i ++) {
97
98
getWriter ().write ("INCR key 1 0 60\r \n " );
98
99
getWriter ().flush ();
99
100
logger .info ("Expect value {}" , i );
100
101
assertResponseGetValue (String .valueOf (i ));
101
102
}
103
+ logger .info ("DONE" );
102
104
}
103
105
104
106
/**
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