Added TimedHashSet that entries have limited TTL
This commit is contained in:
parent
66bebc6f52
commit
33e749dfc7
2 changed files with 91 additions and 0 deletions
39
test/zutil/test/TimedHashSetTest.java
Executable file
39
test/zutil/test/TimedHashSetTest.java
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
package zutil.test;
|
||||
|
||||
import org.junit.Test;
|
||||
import zutil.struct.TimedHashSet;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-11-20.
|
||||
*/
|
||||
public class TimedHashSetTest {
|
||||
public static final String ENTRY = "key";
|
||||
|
||||
@Test
|
||||
public void zeroTTL() throws InterruptedException {
|
||||
TimedHashSet set = new TimedHashSet(0);
|
||||
set.add(ENTRY);
|
||||
Thread.sleep(1);
|
||||
assertFalse(set.contains(ENTRY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tenMsTTL() throws InterruptedException {
|
||||
TimedHashSet set = new TimedHashSet(10);
|
||||
set.add(ENTRY);
|
||||
Thread.sleep(1);
|
||||
assert(set.contains(ENTRY));
|
||||
Thread.sleep(10);
|
||||
assertFalse(set.contains(ENTRY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneSecTTL() throws InterruptedException {
|
||||
TimedHashSet set = new TimedHashSet(1000);
|
||||
set.add(ENTRY);
|
||||
Thread.sleep(1);
|
||||
assert(set.contains(ENTRY));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue