1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.caches.hazelcast;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNotNull;
20 import static org.junit.Assert.assertNull;
21
22 import org.apache.ibatis.cache.Cache;
23 import org.junit.Test;
24 import org.mybatis.caches.oscache.OSCache;
25
26 public final class OSCacheTestCase {
27
28 private static final String DEFAULT_ID = "Hazelcast";
29
30 private static Cache newCache() {
31 return new OSCache(DEFAULT_ID);
32 }
33
34 @Test
35 public void shouldDemonstrateHowAllObjectsAreKept() {
36 Cache cache = newCache();
37 for (int i = 0; i < 100000; i++) {
38 cache.putObject(i, i);
39 assertEquals(i, cache.getObject(i));
40 }
41 assertEquals(100000, cache.getSize());
42 }
43
44 @Test
45 public void shouldDemonstrateCopiesAreEqual() {
46 Cache cache = newCache();
47 for (int i = 0; i < 1000; i++) {
48 cache.putObject(i, i);
49 assertEquals(i, cache.getObject(i));
50 }
51 }
52
53 @Test
54 public void shouldRemoveItemOnDemand() {
55 Cache cache = newCache();
56 cache.putObject(0, 0);
57 assertNotNull(cache.getObject(0));
58 cache.removeObject(0);
59 assertNull(cache.getObject(0));
60 }
61
62 @Test
63 public void shouldFlushAllItemsOnDemand() {
64 Cache cache = newCache();
65 for (int i = 0; i < 5; i++) {
66 cache.putObject(i, i);
67 }
68 assertNotNull(cache.getObject(0));
69 assertNotNull(cache.getObject(4));
70 cache.clear();
71 assertNull(cache.getObject(0));
72 assertNull(cache.getObject(4));
73 }
74
75 }