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 |
|
package info.magnolia.module.cache.ehcache; |
35 |
|
|
36 |
|
import static org.hamcrest.Matchers.*; |
37 |
|
import static org.junit.Assert.*; |
38 |
|
import static org.mockito.Mockito.*; |
39 |
|
|
40 |
|
import info.magnolia.context.MgnlContext; |
41 |
|
import info.magnolia.init.DefaultMagnoliaInitPaths; |
42 |
|
import info.magnolia.init.MagnoliaConfigurationProperties; |
43 |
|
import info.magnolia.init.MagnoliaInitPaths; |
44 |
|
import info.magnolia.module.ModuleLifecycleContext; |
45 |
|
import info.magnolia.module.cache.Cache; |
46 |
|
import info.magnolia.module.cache.CacheFactory; |
47 |
|
import info.magnolia.module.cache.exception.MgnlLockTimeoutException; |
48 |
|
import info.magnolia.test.hamcrest.UtilMatchers; |
49 |
|
import info.magnolia.test.mock.MockWebContext; |
50 |
|
|
51 |
|
import java.io.File; |
52 |
|
import java.util.Collections; |
53 |
|
import java.util.HashMap; |
54 |
|
import java.util.Map; |
55 |
|
import java.util.concurrent.Callable; |
56 |
|
import java.util.concurrent.Executor; |
57 |
|
import java.util.concurrent.Executors; |
58 |
|
import java.util.concurrent.FutureTask; |
59 |
|
import java.util.concurrent.TimeUnit; |
60 |
|
|
61 |
|
import javax.servlet.http.HttpServletRequest; |
62 |
|
|
63 |
|
import org.junit.After; |
64 |
|
import org.junit.Before; |
65 |
|
import org.junit.Ignore; |
66 |
|
import org.junit.Test; |
67 |
|
import org.slf4j.Logger; |
68 |
|
import org.slf4j.LoggerFactory; |
69 |
|
|
70 |
|
import net.sf.ehcache.CacheManager; |
71 |
|
import net.sf.ehcache.config.Configuration; |
72 |
|
import net.sf.ehcache.config.PersistenceConfiguration; |
73 |
|
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
|
|
| 84.7% |
Uncovered Elements: 30 (196) |
Complexity: 23 |
Complexity Density: 0.13 |
|
78 |
|
public class EhCacheFactoryTest extends AbstractEhCacheTest { |
79 |
|
|
80 |
|
private static final Logger log = LoggerFactory.getLogger(EhCacheFactoryTest.class); |
81 |
|
|
82 |
|
private DefaultMagnoliaInitPaths magnoliaInitPaths = mock(DefaultMagnoliaInitPaths.class); |
83 |
|
private final MockWebContext ctx = new MockWebContext(); |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
85 |
13 |
@Before... |
86 |
|
public void setUp() throws Exception { |
87 |
13 |
super.setUp(); |
88 |
13 |
EhCacheConfiguration config = newCacheConfigForTest(); |
89 |
13 |
factory.getCaches().put(CacheFactory.DEFAULT_CACHE_NAME, config); |
90 |
|
|
91 |
|
|
92 |
13 |
ctx.setRequest(mock(HttpServletRequest.class)); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
95 |
13 |
@After... |
96 |
|
public void tearDown() throws Exception { |
97 |
13 |
super.tearDown(); |
98 |
13 |
MgnlContext.setInstance(null); |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
101 |
16 |
@Override... |
102 |
|
protected EhCacheConfiguration newCacheConfigForTest() { |
103 |
16 |
EhCacheConfiguration config = new EhCacheConfiguration(); |
104 |
16 |
config.setDiskPersistent(false); |
105 |
16 |
config.setOverflowToDisk(false); |
106 |
16 |
config.setTimeToIdleSeconds(0); |
107 |
16 |
config.setTimeToLiveSeconds(0); |
108 |
16 |
config.setMaxEntriesLocalHeap(1); |
109 |
16 |
return config; |
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
112 |
1 |
@Test... |
113 |
|
public void fallbackToDefaultsIfNoConfigForGivenCacheName() throws Exception { |
114 |
1 |
final Map<String, EhCacheConfiguration> cfgMap = new HashMap<String, EhCacheConfiguration>(); |
115 |
1 |
final EhCacheConfiguration customCC = newCacheConfigForTest(); |
116 |
1 |
customCC.setName("cache-2"); |
117 |
1 |
customCC.setMemoryStoreEvictionPolicy("FIFO"); |
118 |
1 |
cfgMap.put(customCC.getName(), customCC); |
119 |
|
|
120 |
1 |
factory.setCaches(cfgMap); |
121 |
1 |
factory.start(false); |
122 |
|
|
123 |
1 |
assertEquals("LRU is our default", MemoryStoreEvictionPolicy.LRU, getEvictionStrategy(factory, "cache-1")); |
124 |
1 |
assertEquals("7 was configured explicitly for cache2", MemoryStoreEvictionPolicy.FIFO, getEvictionStrategy(factory, "cache-2")); |
125 |
|
} |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
127 |
1 |
@Test... |
128 |
|
public void canCustomizeDefaultCacheSettingsAndStillUseDifferentCacheConfigPerNamedCache() throws Exception { |
129 |
1 |
final Map<String, EhCacheConfiguration> cfgMap = new HashMap<String, EhCacheConfiguration>(); |
130 |
1 |
final EhCacheConfiguration customCC = newCacheConfigForTest(); |
131 |
1 |
customCC.setName("cache-X"); |
132 |
1 |
customCC.setMemoryStoreEvictionPolicy("FIFO"); |
133 |
1 |
cfgMap.put("cache-X", customCC); |
134 |
|
|
135 |
|
|
136 |
1 |
final EhCacheConfiguration def = newCacheConfigForTest(); |
137 |
1 |
def.setName("default"); |
138 |
1 |
def.setMemoryStoreEvictionPolicy("LFU"); |
139 |
1 |
cfgMap.put("default", def); |
140 |
|
|
141 |
1 |
factory.setCaches(cfgMap); |
142 |
1 |
factory.start(false); |
143 |
|
|
144 |
1 |
assertEquals("LFU is the default for caches that are not configured explicitly", MemoryStoreEvictionPolicy.LFU, getEvictionStrategy(factory, "cache-foobar")); |
145 |
1 |
assertEquals("FIFO was configured explicitly for cache-X", MemoryStoreEvictionPolicy.FIFO, getEvictionStrategy(factory, "cache-X")); |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
155 |
1 |
@Test... |
156 |
|
public void canNotUseDefaultAsACacheName() throws Exception { |
157 |
1 |
try { |
158 |
1 |
factory.getCache("default"); |
159 |
0 |
fail("should have failed"); |
160 |
|
} catch (Throwable t) { |
161 |
1 |
assertThat(t, UtilMatchers.isExceptionWithMessage(IllegalArgumentException.class, "'default' is not a valid cache name.")); |
162 |
|
} |
163 |
|
} |
164 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
165 |
4 |
private MemoryStoreEvictionPolicy getEvictionStrategy(CacheFactory cacheFactory, String cacheName) {... |
166 |
4 |
return ((EhCacheWrapper) cacheFactory.getCache(cacheName)).getWrappedEhcache().getCacheConfiguration().getMemoryStoreEvictionPolicy(); |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
172 |
1 |
@Test... |
173 |
|
public void testSerialAccess() throws Exception { |
174 |
|
|
175 |
1 |
factory.start(false); |
176 |
1 |
final Cache ehCache = factory.getCache("test1"); |
177 |
|
|
178 |
|
|
179 |
1 |
assertNull(ehCache.get("foo")); |
180 |
1 |
ehCache.put("foo", "xxx"); |
181 |
1 |
assertEquals("xxx", ehCache.get("foo")); |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
187 |
1 |
@Test... |
188 |
|
public void testAddMoreThanMaxSize() throws Exception { |
189 |
1 |
factory.start(false); |
190 |
|
|
191 |
|
|
192 |
1 |
assertEquals(1, factory.getCaches().get(CacheFactory.DEFAULT_CACHE_NAME).getMaxEntriesLocalHeap()); |
193 |
|
|
194 |
1 |
final Cache ehCache = factory.getCache("test2"); |
195 |
1 |
assertNull(ehCache.get("foo")); |
196 |
|
|
197 |
1 |
ehCache.put("foo", "xxx"); |
198 |
|
|
199 |
1 |
assertEquals("xxx", ehCache.get("foo")); |
200 |
|
|
201 |
1 |
ehCache.put("boo", "xxx"); |
202 |
|
|
203 |
1 |
assertEquals(null, ehCache.get("foo")); |
204 |
|
|
205 |
1 |
assertEquals("xxx", ehCache.get("boo")); |
206 |
|
|
207 |
|
} |
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 1 |
Complexity Density: 0.04 |
|
214 |
0 |
@Test... |
215 |
|
@Ignore("This is indeed not passing anymore. Passes with ehcache-ee.jar in the classpath and changing the persistence strategy to 'localRestartable'") |
216 |
|
public void cacheIsPersistedAcrossRestarts() throws Exception { |
217 |
0 |
final String k1 = "TestKey_1"; |
218 |
0 |
final String k2 = "TestKey_2"; |
219 |
0 |
final String v1 = "This is the cached String for TestKey_1"; |
220 |
0 |
final String v2 = "This is the cached String for TestKey_2"; |
221 |
0 |
final String cacheName = "myCache"; |
222 |
|
|
223 |
|
|
224 |
0 |
factory = new EhCacheFactory(null, null, null); |
225 |
0 |
EhCacheConfiguration config = new EhCacheConfiguration(); |
226 |
0 |
config.setName(cacheName); |
227 |
|
|
228 |
0 |
config.setPersistence(new EhCachePersistenceConfiguration(PersistenceConfiguration.Strategy.LOCALTEMPSWAP, false)); |
229 |
|
|
230 |
0 |
config.setPersistence(new EhCachePersistenceConfiguration(PersistenceConfiguration.Strategy.LOCALRESTARTABLE, false)); |
231 |
0 |
config.setMaxEntriesLocalHeap(3); |
232 |
0 |
factory.setCaches(Collections.singletonMap(config.getName(), config)); |
233 |
|
|
234 |
|
|
235 |
0 |
factory.start(false); |
236 |
|
{ |
237 |
0 |
final Cache cache = factory.getCache(cacheName); |
238 |
0 |
assertThat(cache.get(k1), nullValue()); |
239 |
0 |
assertThat(cache.get(k2), nullValue()); |
240 |
|
|
241 |
0 |
cache.put(k1, v1); |
242 |
0 |
cache.put(k2, v2); |
243 |
|
|
244 |
0 |
assertThat((String) cache.get(k1), equalTo(v1)); |
245 |
0 |
assertThat((String) cache.get(k2), equalTo(v2)); |
246 |
|
} |
247 |
|
|
248 |
|
|
249 |
0 |
moduleLifecycleContext.setPhase(ModuleLifecycleContext.PHASE_MODULE_RESTART); |
250 |
0 |
factory.stop(false); |
251 |
0 |
assertThat(CacheManager.ALL_CACHE_MANAGERS, empty()); |
252 |
|
|
253 |
|
|
254 |
|
|
255 |
0 |
factory.start(false); |
256 |
|
{ |
257 |
0 |
final Cache cache = factory.getCache(cacheName); |
258 |
|
|
259 |
0 |
assertThat((String) cache.get(k1), equalTo(v1)); |
260 |
0 |
assertThat((String) cache.get(k2), equalTo(v2)); |
261 |
|
} |
262 |
|
} |
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
267 |
1 |
@Test... |
268 |
|
public void testBlocking() throws Exception { |
269 |
1 |
factory.start(false); |
270 |
|
|
271 |
|
|
272 |
1 |
factory.setBlockingTimeout(0); |
273 |
1 |
final Cache ehCache = factory.getCache("test3"); |
274 |
|
|
275 |
1 |
Object entry = ehCache.get("blah"); |
276 |
1 |
log.debug("On first get: {}", entry); |
277 |
1 |
assertNull(entry); |
278 |
1 |
Executor ex = Executors.newFixedThreadPool(2); |
279 |
|
|
280 |
|
|
281 |
1 |
FutureTask<Object> task2 = new FutureTask<Object>(new Callable<Object>() { |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
282 |
1 |
@Override... |
283 |
|
public Object call() throws Exception { |
284 |
1 |
log.debug("2nd get called"); |
285 |
1 |
Object res = ehCache.get("blah"); |
286 |
1 |
log.debug("2nd unblocked"); |
287 |
1 |
return res; |
288 |
|
} |
289 |
|
}); |
290 |
1 |
ex.execute(task2); |
291 |
|
|
292 |
|
|
293 |
1 |
FutureTask<Object> task3 = new FutureTask<Object>(new Callable<Object>() { |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
294 |
1 |
@Override... |
295 |
|
public Object call() throws Exception { |
296 |
1 |
log.debug("3rd get called"); |
297 |
1 |
Object res = ehCache.get("blah"); |
298 |
1 |
log.debug("3rd unblocked"); |
299 |
1 |
return res; |
300 |
|
} |
301 |
|
}); |
302 |
1 |
ex.execute(task3); |
303 |
|
|
304 |
1 |
log.debug("Put"); |
305 |
|
|
306 |
1 |
ehCache.put("blah", "boo"); |
307 |
|
|
308 |
|
|
309 |
|
|
310 |
1 |
log.debug("verify"); |
311 |
|
|
312 |
1 |
Object result = task2.get(5, TimeUnit.SECONDS); |
313 |
1 |
log.debug("2nd get: {]", result); |
314 |
|
|
315 |
|
|
316 |
1 |
Object result2 = task3.get(5, TimeUnit.SECONDS); |
317 |
1 |
log.debug("3rd get: {}", result2); |
318 |
|
|
319 |
1 |
assertNotNull(result); |
320 |
1 |
assertNotNull(result2); |
321 |
|
|
322 |
|
} |
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
327 |
1 |
@Test... |
328 |
|
public void testBlockingAfterAddingMoreThanMaxSize() throws Exception { |
329 |
1 |
factory.start(false); |
330 |
|
|
331 |
|
|
332 |
1 |
assertEquals(1, factory.getCaches().get(CacheFactory.DEFAULT_CACHE_NAME).getMaxEntriesLocalHeap()); |
333 |
|
|
334 |
|
|
335 |
1 |
factory.setBlockingTimeout(1000); |
336 |
1 |
final Cache ehCache = factory.getCache("test4"); |
337 |
|
|
338 |
1 |
Object entry = ehCache.get("blah"); |
339 |
1 |
log.info("On first get: {}", entry); |
340 |
1 |
assertNull(entry); |
341 |
1 |
Executor ex = Executors.newFixedThreadPool(2); |
342 |
|
|
343 |
1 |
log.info("Put"); |
344 |
|
|
345 |
1 |
ehCache.put("blah", "boo"); |
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
1 |
FutureTask<Object> task2 = new FutureTask<Object>(new Callable<Object>() { |
351 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
352 |
1 |
@Override... |
353 |
|
public Object call() throws Exception { |
354 |
1 |
log.info("2nd get called"); |
355 |
1 |
Object res = ehCache.get("blah"); |
356 |
1 |
log.info("2nd not blocked"); |
357 |
1 |
return res; |
358 |
|
} |
359 |
|
}); |
360 |
1 |
ex.execute(task2); |
361 |
1 |
Object result = task2.get(5, TimeUnit.SECONDS); |
362 |
1 |
log.info("2nd get: {}", result); |
363 |
1 |
assertEquals("boo", result); |
364 |
|
|
365 |
|
|
366 |
|
|
367 |
1 |
ehCache.put("foo", "xxx"); |
368 |
|
|
369 |
1 |
entry = ehCache.get("blah"); |
370 |
1 |
assertNull(entry); |
371 |
|
|
372 |
|
|
373 |
1 |
FutureTask<Object> task3 = new FutureTask<Object>(new Callable<Object>() { |
374 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
375 |
1 |
@Override... |
376 |
|
public Object call() throws Exception { |
377 |
1 |
MgnlContext.setInstance(ctx); |
378 |
1 |
log.info("3rd get called"); |
379 |
1 |
Object res = "futureDummyNotModifiedByCacheGetCall"; |
380 |
1 |
try { |
381 |
1 |
res = ehCache.get("blah"); |
382 |
0 |
fail("should not get here. Cache config is wrong!"); |
383 |
|
} catch (MgnlLockTimeoutException e) { |
384 |
|
|
385 |
|
} |
386 |
1 |
log.info("3rd unblocked"); |
387 |
1 |
return res; |
388 |
|
} |
389 |
|
}); |
390 |
1 |
ex.execute(task3); |
391 |
|
|
392 |
1 |
Object result2 = task3.get(5, TimeUnit.SECONDS); |
393 |
1 |
log.info("3rd get: {}", result2); |
394 |
1 |
assertEquals("futureDummyNotModifiedByCacheGetCall", result2); |
395 |
|
} |
396 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
397 |
1 |
@Test... |
398 |
|
public void configuration() throws Exception { |
399 |
|
|
400 |
1 |
factory.start(false); |
401 |
1 |
Configuration configuration = factory.getWrappedCacheManager().getConfiguration(); |
402 |
|
|
403 |
|
|
404 |
1 |
assertThat(configuration.getDefaultCacheConfiguration().getName(), equalTo(factory.getCaches().get(CacheFactory.DEFAULT_CACHE_NAME).getName())); |
405 |
1 |
assertThat(new File(configuration.getDiskStoreConfiguration().getPath()).getCanonicalFile(), equalTo(cacheFolder.getAbsoluteFile())); |
406 |
|
} |
407 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
408 |
1 |
@Test... |
409 |
|
public void twoWebappsRunningInTheSameJVM() throws Exception { |
410 |
|
|
411 |
1 |
DefaultMagnoliaInitPaths webapp1magnoliaInitPaths = mock(DefaultMagnoliaInitPaths.class); |
412 |
1 |
when(webapp1magnoliaInitPaths.getRootPath()).thenReturn("/Users/username/bundles/apache-tomcat-7.0.47/webapps/magnoliaPublic"); |
413 |
1 |
EhCacheFactory webapp1Cachefactory = new SeparateWebappSimulatingEhCacheFactory(webapp1magnoliaInitPaths, magnoliaConfigurationProperties); |
414 |
|
|
415 |
1 |
DefaultMagnoliaInitPaths webapp2magnoliaInitPaths = mock(DefaultMagnoliaInitPaths.class); |
416 |
1 |
when(webapp1magnoliaInitPaths.getRootPath()).thenReturn("/Users/username/bundles/apache-tomcat-7.0.47/webapps/magnoliaAuthor"); |
417 |
1 |
EhCacheFactory webapp2Cachefactory = new SeparateWebappSimulatingEhCacheFactory(webapp2magnoliaInitPaths, magnoliaConfigurationProperties); |
418 |
|
|
419 |
|
|
420 |
1 |
webapp1Cachefactory.start(false); |
421 |
1 |
webapp2Cachefactory.start(false); |
422 |
|
|
423 |
|
|
424 |
|
} |
425 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
426 |
1 |
@Test... |
427 |
|
public void cacheManagerIdSpecifiedViaPropertiesFile() throws Exception { |
428 |
|
|
429 |
1 |
MagnoliaConfigurationProperties magnoliaConfigurationProperties1 = mock(MagnoliaConfigurationProperties.class); |
430 |
1 |
when(magnoliaConfigurationProperties1.hasProperty(EhCacheFactory.MAGNOLIA_PROPERTY_CACHE_MANAGER_ID)).thenReturn(true); |
431 |
1 |
when(magnoliaConfigurationProperties1.getProperty(EhCacheFactory.MAGNOLIA_PROPERTY_CACHE_MANAGER_ID)).thenReturn("cacheManagerWebappAuthor"); |
432 |
1 |
EhCacheFactory webapp1Cachefactory = new SeparateWebappSimulatingEhCacheFactory(magnoliaInitPaths, magnoliaConfigurationProperties1); |
433 |
|
|
434 |
1 |
MagnoliaConfigurationProperties magnoliaConfigurationProperties2 = mock(MagnoliaConfigurationProperties.class); |
435 |
1 |
when(magnoliaConfigurationProperties2.hasProperty(EhCacheFactory.MAGNOLIA_PROPERTY_CACHE_MANAGER_ID)).thenReturn(true); |
436 |
1 |
when(magnoliaConfigurationProperties2.getProperty(EhCacheFactory.MAGNOLIA_PROPERTY_CACHE_MANAGER_ID)).thenReturn("cacheManagerWebappPublic"); |
437 |
1 |
EhCacheFactory webapp2Cachefactory = new SeparateWebappSimulatingEhCacheFactory(magnoliaInitPaths, magnoliaConfigurationProperties2); |
438 |
|
|
439 |
|
|
440 |
1 |
webapp1Cachefactory.start(false); |
441 |
1 |
webapp2Cachefactory.start(false); |
442 |
|
|
443 |
|
|
444 |
|
} |
445 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
446 |
1 |
@Test... |
447 |
|
public void cacheManagerIdentifierCantContainSpecialCharacters() throws Exception { |
448 |
|
|
449 |
1 |
when(magnoliaInitPaths.getRootPath()).thenReturn(EhCacheFactory.CACHE_MANAGER_ID_INVALID_CHARS); |
450 |
1 |
EhCacheFactory cacheFactory = new EhCacheFactory(null, cacheModule, magnoliaInitPaths, magnoliaConfigurationProperties); |
451 |
1 |
cacheFactory.start(false); |
452 |
|
|
453 |
|
|
454 |
1 |
cacheFactory.createCache("cacheName"); |
455 |
|
|
456 |
|
|
457 |
|
} |
458 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
459 |
1 |
@Test... |
460 |
|
public void cacheManagerIsNotLostOnRestart() throws Exception { |
461 |
|
|
462 |
1 |
factory = new EhCacheFactory(null, cacheModule, magnoliaInitPaths, magnoliaConfigurationProperties); |
463 |
1 |
factory.start(false); |
464 |
1 |
factory = new EhCacheFactory(null, cacheModule, magnoliaInitPaths, magnoliaConfigurationProperties); |
465 |
|
|
466 |
|
|
467 |
1 |
factory.start(true); |
468 |
|
|
469 |
|
|
470 |
1 |
assertThat(factory.getWrappedCacheManager(), not(nullValue())); |
471 |
|
} |
472 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
473 |
|
@Test... |
474 |
|
public void getQuiet() throws Exception { |
475 |
|
|
476 |
|
factory.start(true); |
477 |
|
Cache cache = factory.getCache("cacheName"); |
478 |
|
cache.put("key", "value"); |
479 |
|
|
480 |
|
|
481 |
|
Object existingObject = cache.getQuiet("key"); |
482 |
|
Object nonExistingObject = cache.getQuiet("nonExistingKey"); |
483 |
|
|
484 |
|
|
485 |
|
assertEquals(existingObject, "value"); |
486 |
|
assertNull(nonExistingObject); |
487 |
|
} |
488 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
489 |
|
private class SeparateWebappSimulatingEhCacheFactory extends EhCacheFactory { |
490 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
491 |
4 |
public SeparateWebappSimulatingEhCacheFactory(MagnoliaInitPaths magnoliaInitPaths, MagnoliaConfigurationProperties magnoliaConfigurationProperties) {... |
492 |
4 |
super(cacheMonitor, cacheModule, magnoliaInitPaths, magnoliaConfigurationProperties); |
493 |
|
} |
494 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
495 |
4 |
@Override... |
496 |
|
protected boolean shouldRegisterCacheManager() { |
497 |
4 |
return true; |
498 |
|
} |
499 |
|
} |
500 |
|
|
501 |
|
} |