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.setup; |
35 |
|
|
36 |
|
import static info.magnolia.test.hamcrest.NodeMatchers.*; |
37 |
|
import static org.hamcrest.CoreMatchers.not; |
38 |
|
import static org.junit.Assert.assertEquals; |
39 |
|
import static org.junit.Assert.assertThat; |
40 |
|
|
41 |
|
import info.magnolia.context.MgnlContext; |
42 |
|
import info.magnolia.jcr.util.NodeTypes; |
43 |
|
import info.magnolia.jcr.util.NodeUtil; |
44 |
|
import info.magnolia.module.InstallContext; |
45 |
|
import info.magnolia.module.ModuleVersionHandler; |
46 |
|
import info.magnolia.module.ModuleVersionHandlerTestCase; |
47 |
|
import info.magnolia.module.cache.ehcache.EhCacheFactory; |
48 |
|
import info.magnolia.repository.RepositoryConstants; |
49 |
|
|
50 |
|
import java.util.Arrays; |
51 |
|
import java.util.List; |
52 |
|
|
53 |
|
import javax.jcr.Node; |
54 |
|
import javax.jcr.NodeIterator; |
55 |
|
import javax.jcr.Session; |
56 |
|
|
57 |
|
import org.junit.Before; |
58 |
|
import org.junit.Test; |
59 |
|
|
60 |
|
|
61 |
|
@link |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (49) |
Complexity: 6 |
Complexity Density: 0.14 |
|
63 |
|
public class EhCacheModuleVersionHandlerTest extends ModuleVersionHandlerTestCase { |
64 |
|
|
65 |
|
private Session session; |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
2 |
@Override... |
68 |
|
protected String getModuleDescriptorPath() { |
69 |
2 |
return "/META-INF/magnolia/ehcache.xml"; |
70 |
|
} |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
2 |
@Override... |
73 |
|
protected ModuleVersionHandler newModuleVersionHandlerForTests() { |
74 |
2 |
return new EhCacheModuleVersionHandler(); |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
2 |
@Override... |
78 |
|
protected List<String> getModuleDescriptorPathsForTests() { |
79 |
2 |
return Arrays.asList( |
80 |
|
"/META-INF/magnolia/core.xml" |
81 |
|
); |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
84 |
2 |
@Override... |
85 |
|
@Before |
86 |
|
public void setUp() throws Exception { |
87 |
2 |
super.setUp(); |
88 |
2 |
session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
91 |
1 |
@Test... |
92 |
|
public void upgradeFromCacheModule53() throws Exception { |
93 |
|
|
94 |
1 |
Node moduleCfgNode = NodeUtil.createPath(session.getRootNode(), "/modules/cache/config/", NodeTypes.ContentNode.NAME); |
95 |
1 |
final Node cacheFactory = NodeUtil.createPath(session.getRootNode(), EhCacheModuleVersionHandler.EHCACHE_FACTORY_NODE, NodeTypes.ContentNode.NAME); |
96 |
1 |
cacheFactory.setProperty("class", EhCacheFactory.class.getName()); |
97 |
1 |
final Node defaultCacheConfiguration = cacheFactory.addNode("defaultCacheConfiguration", NodeTypes.ContentNode.NAME); |
98 |
1 |
defaultCacheConfiguration.setProperty("overflowToDisk", true); |
99 |
1 |
defaultCacheConfiguration.setProperty("diskPersistent", false); |
100 |
1 |
defaultCacheConfiguration.setProperty("diskSpoolBufferSizeMB", "50"); |
101 |
|
|
102 |
1 |
final Node cacheContent = NodeUtil.createPath(moduleCfgNode, "configurations/default/executors/store/cacheContent/", NodeTypes.ContentNode.NAME); |
103 |
1 |
cacheContent.addNode("isCacheableVoters", NodeTypes.ContentNode.NAME); |
104 |
|
|
105 |
|
|
106 |
1 |
InstallContext installContext = executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null); |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
1 |
assertThat(cacheFactory, not(hasNode("defaultCacheConfiguration"))); |
111 |
1 |
assertThat(cacheFactory, hasNode("caches")); |
112 |
1 |
assertThat(cacheFactory.getNode("caches"), hasNode("default")); |
113 |
1 |
final Node newDefaultCacheCfg = cacheFactory.getNode("caches").getNode("default"); |
114 |
1 |
assertThat(newDefaultCacheCfg, hasProperty("diskSpoolBufferSizeMB", "50")); |
115 |
1 |
assertThat(newDefaultCacheCfg, not(hasProperty("diskPersistent"))); |
116 |
1 |
assertThat(newDefaultCacheCfg, not(hasProperty("overflowToDisk"))); |
117 |
1 |
assertThat(newDefaultCacheCfg, hasNode("persistence")); |
118 |
1 |
assertThat(newDefaultCacheCfg.getNode("persistence"), hasProperty("strategy", "localTempSwap")); |
119 |
1 |
assertThat(newDefaultCacheCfg.getNode("persistence"), hasProperty("synchronousWrites", "false")); |
120 |
|
|
121 |
1 |
assertNoMessages(installContext); |
122 |
|
} |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
124 |
1 |
@Test... |
125 |
|
public void cleanInstall() throws Exception { |
126 |
|
|
127 |
1 |
setupConfigNode("modules/cache/config/cacheFactory/delegateFactories/memcached"); |
128 |
|
|
129 |
|
|
130 |
1 |
InstallContext installContext = executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null); |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
1 |
assertThat(session.getRootNode(), hasNode("modules/cache/config/cacheFactory/delegateFactories/ehcache")); |
135 |
1 |
final Node cacheFactory = session.getNode("/modules/cache/config/cacheFactory/delegateFactories/ehcache"); |
136 |
1 |
assertThat(cacheFactory, not(hasNode("defaultCacheConfiguration"))); |
137 |
1 |
assertThat(cacheFactory, hasNode("caches")); |
138 |
1 |
assertThat(cacheFactory.getNode("caches"), hasNode("default")); |
139 |
1 |
final Node newDefaultCacheCfg = cacheFactory.getNode("caches").getNode("default"); |
140 |
1 |
assertThat(newDefaultCacheCfg, hasProperty("diskSpoolBufferSizeMB", "30")); |
141 |
1 |
assertThat(newDefaultCacheCfg, hasProperty("diskExpiryThreadIntervalSeconds", "120")); |
142 |
1 |
assertThat(newDefaultCacheCfg, hasProperty("maxElementsInMemory", "10000")); |
143 |
1 |
assertThat(newDefaultCacheCfg, hasNode("persistence")); |
144 |
1 |
assertThat(newDefaultCacheCfg.getNode("persistence"), hasProperty("strategy", "localTempSwap")); |
145 |
1 |
assertThat(newDefaultCacheCfg.getNode("persistence"), hasProperty("synchronousWrites", "false")); |
146 |
|
|
147 |
1 |
final NodeIterator delegateFactories = session.getNode("/modules/cache/config/cacheFactory/delegateFactories/").getNodes(); |
148 |
1 |
assertEquals("memcached", delegateFactories.nextNode().getName()); |
149 |
|
|
150 |
1 |
assertNoMessages(installContext); |
151 |
|
} |
152 |
|
} |