forked from cloudadc/cluster
/
DefaultCacheTest.java
52 lines (35 loc) · 1009 Bytes
/
DefaultCacheTest.java
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
50
51
52
package org.infinispan.quickstart;
import static org.junit.Assert.*;
import java.util.concurrent.TimeUnit;
import org.infinispan.Cache;
import org.infinispan.manager.DefaultCacheManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class DefaultCacheTest {
Cache<Object, Object> cache;
@Before
public void setup() {
cache = new DefaultCacheManager().getCache();
}
@After
public void cleanup() {
cache.stop();
cache = null;
}
@Test
public void defaultCacheTest() throws InterruptedException {
cache.put("key", "value");
assertEquals(1, cache.size());
assertTrue(cache.containsKey("key"));
Object v = cache.remove("key");
assertEquals("value", v);
assertTrue(cache.isEmpty());
cache.putIfAbsent("key", "newValue");
assertTrue(cache.get("key").equals("newValue"));
cache.put("key", "value", 5, TimeUnit.SECONDS);
assertTrue(cache.containsKey("key"));
Thread.sleep(6000);
assertFalse(cache.containsKey("key"));
}
}