1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.cache.tests; |
21 |
|
|
22 |
|
import org.junit.Assert; |
23 |
|
import org.junit.Test; |
24 |
|
import org.xwiki.cache.Cache; |
25 |
|
import org.xwiki.cache.CacheFactory; |
26 |
|
import org.xwiki.cache.config.CacheConfiguration; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
@version |
32 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (70) |
Complexity: 8 |
Complexity Density: 0.13 |
|
33 |
|
public abstract class AbstractGenericTestCache extends AbstractTestCache |
34 |
|
{ |
35 |
|
|
36 |
|
@param |
37 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
38 |
11 |
protected AbstractGenericTestCache(String roleHint)... |
39 |
|
{ |
40 |
11 |
super(roleHint); |
41 |
|
} |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@throws |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
4-
|
|
51 |
1 |
@Test... |
52 |
|
public void testGetFactory() throws Exception |
53 |
|
{ |
54 |
1 |
CacheFactory factory = getCacheFactory(); |
55 |
|
|
56 |
1 |
CacheFactory factory2 = getCacheFactory(); |
57 |
|
|
58 |
1 |
Assert.assertSame(factory, factory2); |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@throws |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
4-
|
|
66 |
1 |
@Test... |
67 |
|
public void testCreateAndDestroyCacheSimple() throws Exception |
68 |
|
{ |
69 |
1 |
CacheFactory factory = getCacheFactory(); |
70 |
|
|
71 |
1 |
Cache<Object> cache = factory.newCache(new CacheConfiguration()); |
72 |
|
|
73 |
1 |
Assert.assertNotNull(cache); |
74 |
|
|
75 |
1 |
cache.set(KEY, VALUE); |
76 |
1 |
cache.set(KEY2, VALUE2); |
77 |
|
|
78 |
1 |
Assert.assertEquals(VALUE, cache.get(KEY)); |
79 |
1 |
Assert.assertEquals(VALUE2, cache.get(KEY2)); |
80 |
|
|
81 |
1 |
cache.dispose(); |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
@link |
86 |
|
|
87 |
|
@throws |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
4-
|
|
89 |
1 |
@Test... |
90 |
|
public void testRemove() throws Exception |
91 |
|
{ |
92 |
1 |
CacheFactory factory = getCacheFactory(); |
93 |
|
|
94 |
1 |
Cache<Object> cache = factory.newCache(new CacheConfiguration()); |
95 |
|
|
96 |
1 |
cache.set(KEY, VALUE); |
97 |
1 |
cache.set(KEY2, VALUE2); |
98 |
|
|
99 |
1 |
cache.remove(KEY); |
100 |
|
|
101 |
1 |
Assert.assertNull(cache.get(KEY)); |
102 |
1 |
Assert.assertEquals(VALUE2, cache.get(KEY2)); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
@link |
107 |
|
|
108 |
|
@throws |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
4-
|
|
110 |
1 |
@Test... |
111 |
|
public void testRemoveAll() throws Exception |
112 |
|
{ |
113 |
1 |
CacheFactory factory = getCacheFactory(); |
114 |
|
|
115 |
1 |
Cache<Object> cache = factory.newCache(new CacheConfiguration()); |
116 |
|
|
117 |
1 |
cache.set(KEY, VALUE); |
118 |
1 |
cache.set(KEY2, VALUE2); |
119 |
|
|
120 |
1 |
cache.removeAll(); |
121 |
|
|
122 |
1 |
Assert.assertNull(cache.get(KEY)); |
123 |
1 |
Assert.assertNull(cache.get(KEY2)); |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
@throws |
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
4-
|
|
131 |
1 |
@Test... |
132 |
|
public void testEvents() throws Exception |
133 |
|
{ |
134 |
1 |
CacheFactory factory = getCacheFactory(); |
135 |
|
|
136 |
1 |
Cache<Object> cache = factory.newCache(new CacheConfiguration()); |
137 |
|
|
138 |
1 |
CacheEntryListenerTest eventListener = new CacheEntryListenerTest(); |
139 |
|
|
140 |
1 |
cache.addCacheEntryListener(eventListener); |
141 |
|
|
142 |
1 |
cache.set(KEY, VALUE); |
143 |
|
|
144 |
1 |
Assert.assertNotNull(eventListener.getAddedEvent()); |
145 |
1 |
Assert.assertSame(cache, eventListener.getAddedEvent().getCache()); |
146 |
1 |
Assert.assertEquals(KEY, eventListener.getAddedEvent().getEntry().getKey()); |
147 |
1 |
Assert.assertEquals(VALUE, eventListener.getAddedEvent().getEntry().getValue()); |
148 |
|
|
149 |
1 |
cache.set(KEY, VALUE2); |
150 |
|
|
151 |
1 |
Assert.assertNotNull(eventListener.getModifiedEvent()); |
152 |
1 |
Assert.assertSame(cache, eventListener.getModifiedEvent().getCache()); |
153 |
1 |
Assert.assertEquals(KEY, eventListener.getModifiedEvent().getEntry().getKey()); |
154 |
1 |
Assert.assertEquals(VALUE2, eventListener.getModifiedEvent().getEntry().getValue()); |
155 |
|
|
156 |
1 |
cache.remove(KEY); |
157 |
1 |
cache.get(KEY); |
158 |
|
|
159 |
1 |
Assert.assertNotNull(eventListener.getRemovedEvent()); |
160 |
1 |
Assert.assertSame(cache, eventListener.getRemovedEvent().getCache()); |
161 |
1 |
Assert.assertEquals(KEY, eventListener.getRemovedEvent().getEntry().getKey()); |
162 |
1 |
Assert.assertEquals(VALUE2, eventListener.getRemovedEvent().getEntry().getValue()); |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
@throws |
169 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
4-
|
|
170 |
1 |
@Test... |
171 |
|
public void testSeveralCaches() throws Exception |
172 |
|
{ |
173 |
1 |
CacheFactory factory = getCacheFactory(); |
174 |
|
|
175 |
1 |
Cache<Object> cache = factory.newCache(new CacheConfiguration()); |
176 |
1 |
Cache<Object> cache2 = factory.newCache(new CacheConfiguration()); |
177 |
|
|
178 |
1 |
cache.set(KEY, VALUE); |
179 |
|
|
180 |
1 |
Assert.assertNull(cache2.get(KEY)); |
181 |
|
} |
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
@throws |
187 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
4-
|
|
188 |
1 |
@Test... |
189 |
|
public void testRecreateCache() throws Exception |
190 |
|
{ |
191 |
1 |
CacheFactory factory = getCacheFactory(); |
192 |
|
|
193 |
1 |
CacheConfiguration configuration = new CacheConfiguration(); |
194 |
1 |
configuration.setConfigurationId("test"); |
195 |
|
|
196 |
1 |
Cache<Object> cache = factory.newCache(configuration); |
197 |
|
|
198 |
1 |
cache.set(KEY, VALUE); |
199 |
|
|
200 |
1 |
Assert.assertEquals(VALUE, cache.get(KEY)); |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
1 |
cache.dispose(); |
205 |
|
|
206 |
|
|
207 |
|
|
208 |
1 |
cache = factory.newCache(configuration); |
209 |
|
|
210 |
1 |
Assert.assertNull(cache.get(KEY)); |
211 |
|
|
212 |
1 |
cache.set(KEY, VALUE); |
213 |
|
|
214 |
1 |
Assert.assertEquals(VALUE, cache.get(KEY)); |
215 |
|
} |
216 |
|
} |