-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTtlCommandTest.java
More file actions
49 lines (41 loc) · 1.29 KB
/
Copy pathTtlCommandTest.java
File metadata and controls
49 lines (41 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.vaultdb;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class TtlCommandTest {
private VaultDBEngine engine;
@BeforeEach
void setUp() {
engine = new VaultDBEngine();
}
@Test
void expireAndTtl() throws InterruptedException {
engine.set("temp", "value");
assertEquals(1, engine.expire("temp", 2));
assertTrue(engine.ttl("temp") > 0);
Thread.sleep(2100);
assertNull(engine.get("temp"));
assertEquals(-2, engine.ttl("temp"));
}
@Test
void setExExpiresKey() throws InterruptedException {
engine.setEx("session", "abc", 1);
assertEquals("abc", engine.get("session"));
Thread.sleep(1100);
assertNull(engine.get("session"));
}
@Test
void lazyEvictionOnRead() throws InterruptedException {
engine.setEx("lazy", "1", 1);
Thread.sleep(1100);
assertNull(engine.get("lazy"));
}
@Test
void activeSweeperEvictsExpiredKeys() throws InterruptedException {
engine.setEx("sweep", "data", 1);
Thread.sleep(1100);
TestSupport.runTtlSweeperOnce(engine);
assertEquals(-2, engine.ttl("sweep"));
assertNull(engine.get("sweep"));
}
}