KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > loader > CacheLoaderManagerTest


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.cache.loader;
8
9 import junit.framework.Assert;
10 import junit.framework.Test;
11 import junit.framework.TestSuite;
12 import org.jboss.cache.CacheListener;
13 import org.jboss.cache.CacheSPI;
14 import org.jboss.cache.config.CacheLoaderConfig;
15 import org.jboss.cache.factories.XmlConfigurationParser;
16 import org.jboss.cache.xml.XmlHelper;
17 import org.w3c.dom.Element JavaDoc;
18
19 import java.util.List JavaDoc;
20 import java.util.Properties JavaDoc;
21
22 /**
23  * Tests the construction of a cache laoder based on an XML element passed in.
24  *
25  * @author <a HREF="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
26  */

27 public class CacheLoaderManagerTest extends AbstractCacheLoaderTestBase
28 {
29    private CacheLoaderConfig createCacheLoaderCfg(boolean passivation)
30    {
31       CacheLoaderConfig cfg = new CacheLoaderConfig();
32       cfg.setPassivation(passivation);
33       return cfg;
34    }
35
36    private CacheLoaderConfig.IndividualCacheLoaderConfig createIndividualCacheLoaderConfig(CacheLoaderConfig parent, boolean async, String JavaDoc classname) throws Exception JavaDoc
37    {
38       CacheLoaderConfig.IndividualCacheLoaderConfig cfg = new CacheLoaderConfig.IndividualCacheLoaderConfig();
39       cfg.setAsync(async);
40       cfg.setClassName(classname);
41       cfg.setFetchPersistentState(false);
42       Properties JavaDoc p = new Properties JavaDoc();
43       p.setProperty("location", getTempDir());
44       p.setProperty("cache.jdbc.driver", "com.mysql.jdbc.Driver");
45       p.setProperty("cache.jdbc.url", "jdbc:mysql://localhost/test");
46       p.setProperty("cache.jdbc.user", "user");
47       p.setProperty("cache.jdbc.password", "pwd");
48       cfg.setProperties(p);
49       return cfg;
50    }
51
52    private String JavaDoc getTempDir()
53    {
54       return System.getProperty("java.io.tempdir", "/tmp");
55    }
56
57    private static Element JavaDoc strToElement(String JavaDoc s) throws Exception JavaDoc
58    {
59       return XmlHelper.stringToElement(s);
60    }
61
62    public void testSingleCacheLoader() throws Exception JavaDoc
63    {
64       // without async
65
CacheLoaderManager mgr = new CacheLoaderManager();
66       CacheLoaderConfig cfg = createCacheLoaderCfg(false);
67       cfg.addIndividualCacheLoaderConfig(createIndividualCacheLoaderConfig(cfg, false, "org.jboss.cache.loader.FileCacheLoader"));
68
69       mgr.setConfig(cfg, null);
70       CacheLoader cl = mgr.getCacheLoader();
71
72       Assert.assertEquals(FileCacheLoader.class, cl.getClass());
73
74       // with async
75
cfg = createCacheLoaderCfg(false);
76       cfg.addIndividualCacheLoaderConfig(createIndividualCacheLoaderConfig(cfg, true, "org.jboss.cache.loader.FileCacheLoader"));
77
78       mgr.setConfig(cfg, null);
79       cl = mgr.getCacheLoader();
80
81       Assert.assertEquals(AsyncCacheLoader.class, cl.getClass());
82    }
83
84    public void testSingleCacheLoaderPassivation() throws Exception JavaDoc
85    {
86       // without async
87
CacheLoaderConfig cfg = createCacheLoaderCfg(true);
88       cfg.addIndividualCacheLoaderConfig(createIndividualCacheLoaderConfig(cfg, false, "org.jboss.cache.loader.FileCacheLoader"));
89       cfg.addIndividualCacheLoaderConfig(createIndividualCacheLoaderConfig(cfg, false, "org.jboss.cache.loader.bdbje.BdbjeCacheLoader"));
90       cfg.addIndividualCacheLoaderConfig(createIndividualCacheLoaderConfig(cfg, false, "org.jboss.cache.loader.JDBCCacheLoader"));
91
92       CacheLoaderManager mgr = new CacheLoaderManager();
93       mgr.setConfig(cfg, null);
94       CacheLoader cl = mgr.getCacheLoader();
95
96       Assert.assertEquals(FileCacheLoader.class, cl.getClass());
97
98       // with async
99
cfg = createCacheLoaderCfg(true);
100       cfg.addIndividualCacheLoaderConfig(createIndividualCacheLoaderConfig(cfg, true, "org.jboss.cache.loader.FileCacheLoader"));
101       cfg.addIndividualCacheLoaderConfig(createIndividualCacheLoaderConfig(cfg, true, "org.jboss.cache.loader.bdbje.BdbjeCacheLoader"));
102       cfg.addIndividualCacheLoaderConfig(createIndividualCacheLoaderConfig(cfg, true, "org.jboss.cache.loader.JDBCCacheLoader"));
103
104       mgr.setConfig(cfg, null);
105       cl = mgr.getCacheLoader();
106
107       Assert.assertEquals(AsyncCacheLoader.class, cl.getClass());
108    }
109
110    public void testSingleCacheLoaderFromXml() throws Exception JavaDoc
111    {
112       // without async
113
CacheLoaderConfig clc = getSingleCacheLoaderConfig("", "org.jboss.cache.loader.FileCacheLoader", "location=" + getTempDir(), false, false, false);
114
115       CacheLoaderManager mgr = new CacheLoaderManager();
116       mgr.setConfig(clc, null);
117       CacheLoader cl = mgr.getCacheLoader();
118
119       Assert.assertEquals(FileCacheLoader.class, cl.getClass());
120
121       // with async
122
clc = getSingleCacheLoaderConfig("", "org.jboss.cache.loader.FileCacheLoader", "location=" + getTempDir(), true, false, false);
123
124       mgr.setConfig(clc, null);
125       cl = mgr.getCacheLoader();
126       Assert.assertEquals(AsyncCacheLoader.class, cl.getClass());
127    }
128
129    public void testSingleCacheLoaderPassivationFromXml() throws Exception JavaDoc
130    {
131       // without async
132
String JavaDoc conf = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
133               "<config><passivation>true</passivation>" +
134               "<cacheloader>" +
135               " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
136               " <async>false</async>" +
137               " <fetchPersistentState>false</fetchPersistentState>" +
138               " <ignoreModifications>false</ignoreModifications>" +
139               " <properties>" +
140               " location=" + getTempDir() +
141               " </properties>" +
142               "</cacheloader>" +
143               "<cacheloader>" +
144               " <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>" +
145               " <async>false</async>" +
146               " <fetchPersistentState>false</fetchPersistentState>" +
147               " <ignoreModifications>false</ignoreModifications>" +
148               " <properties>" +
149               " location=" + getTempDir() +
150               " </properties>" +
151               "</cacheloader>" +
152               "<cacheloader>" +
153               " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
154               " <async>false</async>" +
155               " <fetchPersistentState>false</fetchPersistentState>" +
156               " <ignoreModifications>false</ignoreModifications>" +
157               " <properties>" +
158               " location=" + getTempDir() +
159               " </properties>" +
160               "</cacheloader></config>";
161       CacheLoaderConfig clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
162       CacheLoaderManager mgr = new CacheLoaderManager();
163       mgr.setConfig(clc, null);
164       CacheLoader cl = mgr.getCacheLoader();
165
166       Assert.assertEquals(FileCacheLoader.class, cl.getClass());
167
168       // with async
169
conf = "<config><passivation>true</passivation>" +
170               "<cacheloader>" +
171               " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
172               " <async>true</async>" +
173               " <fetchPersistentState>false</fetchPersistentState>" +
174               " <ignoreModifications>false</ignoreModifications>" +
175               " <properties>" +
176               " location=" + getTempDir() +
177               " </properties>" +
178               "</cacheloader>" +
179               "<cacheloader>" +
180               " <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>" +
181               " <async>true</async>" +
182               " <fetchPersistentState>false</fetchPersistentState>" +
183               " <ignoreModifications>false</ignoreModifications>" +
184               " <properties>" +
185               " location=" + getTempDir() +
186               " </properties>" +
187               "</cacheloader>" +
188               "<cacheloader>" +
189               " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
190               " <async>true</async>" +
191               " <fetchPersistentState>false</fetchPersistentState>" +
192               " <ignoreModifications>false</ignoreModifications>" +
193               " <properties>" +
194               " location=" + getTempDir() +
195               " </properties>" +
196               "</cacheloader></config>";
197       clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
198       mgr.setConfig(clc, null);
199       cl = mgr.getCacheLoader();
200
201       Assert.assertEquals(AsyncCacheLoader.class, cl.getClass());
202    }
203
204    public void testChainingCacheLoader() throws Exception JavaDoc
205    {
206       // async = false
207
CacheLoaderConfig cfg = createCacheLoaderCfg(false);
208       cfg.addIndividualCacheLoaderConfig(createIndividualCacheLoaderConfig(cfg, false, "org.jboss.cache.loader.FileCacheLoader"));
209       cfg.addIndividualCacheLoaderConfig(createIndividualCacheLoaderConfig(cfg, false, "org.jboss.cache.loader.JDBCCacheLoader"));
210
211       CacheLoaderManager mgr = new CacheLoaderManager();
212       mgr.setConfig(cfg, null);
213       CacheLoader cl = mgr.getCacheLoader();
214
215       Assert.assertEquals(ChainingCacheLoader.class, cl.getClass());
216       Assert.assertEquals(2, ((ChainingCacheLoader) cl).getSize());
217       List JavaDoc loaders = ((ChainingCacheLoader) cl).getCacheLoaders();
218       Assert.assertEquals(FileCacheLoader.class, loaders.get(0).getClass());
219       Assert.assertEquals(JDBCCacheLoader.class, loaders.get(1).getClass());
220
221       // async = true
222
cfg = createCacheLoaderCfg(false);
223       cfg.addIndividualCacheLoaderConfig(createIndividualCacheLoaderConfig(cfg, false, "org.jboss.cache.loader.FileCacheLoader"));
224       cfg.addIndividualCacheLoaderConfig(createIndividualCacheLoaderConfig(cfg, true, "org.jboss.cache.loader.JDBCCacheLoader"));
225
226       mgr.setConfig(cfg, null);
227       cl = mgr.getCacheLoader();
228
229       Assert.assertEquals(ChainingCacheLoader.class, cl.getClass());
230       Assert.assertEquals(2, ((ChainingCacheLoader) cl).getSize());
231       loaders = ((ChainingCacheLoader) cl).getCacheLoaders();
232       Assert.assertEquals(FileCacheLoader.class, loaders.get(0).getClass());
233       Assert.assertEquals(AsyncCacheLoader.class, loaders.get(1).getClass());
234    }
235
236    public void testChainingCacheLoaderFromXml() throws Exception JavaDoc
237    {
238       // async = false
239
String JavaDoc conf = "<config><passivation>false</passivation>" +
240               "<cacheloader>" +
241               " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
242               " <async>false</async>" +
243               " <fetchPersistentState>false</fetchPersistentState>" +
244               " <ignoreModifications>false</ignoreModifications>" +
245               " <properties>" +
246               " location=" + getTempDir() +
247               " </properties>" +
248               "</cacheloader>" +
249               "<cacheloader>" +
250               " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
251               " <async>false</async>" +
252               " <fetchPersistentState>false</fetchPersistentState>" +
253               " <ignoreModifications>false</ignoreModifications>" +
254               " <properties>" +
255               "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
256               " </properties>" +
257               "</cacheloader></config>";
258
259       CacheLoaderConfig clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
260       CacheLoaderManager mgr = new CacheLoaderManager();
261       mgr.setConfig(clc, null);
262       CacheLoader cl = mgr.getCacheLoader();
263
264
265       Assert.assertEquals(ChainingCacheLoader.class, cl.getClass());
266       Assert.assertEquals(2, ((ChainingCacheLoader) cl).getSize());
267       List JavaDoc loaders = ((ChainingCacheLoader) cl).getCacheLoaders();
268       Assert.assertEquals(FileCacheLoader.class, loaders.get(0).getClass());
269       Assert.assertEquals(JDBCCacheLoader.class, loaders.get(1).getClass());
270
271       // async = true
272
conf = "<config>" +
273               "<passivation>false</passivation>" +
274               "<cacheloader>" +
275               " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
276               " <async>false</async>" +
277               " <fetchPersistentState>false</fetchPersistentState>" +
278               " <ignoreModifications>false</ignoreModifications>" +
279               " <properties>" +
280               " location=" + getTempDir() +
281               " </properties>" +
282               "</cacheloader>" +
283               "<cacheloader>" +
284               " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
285               " <async>true</async>" +
286               " <fetchPersistentState>false</fetchPersistentState>" +
287               " <ignoreModifications>false</ignoreModifications>" +
288               " <properties>" +
289               "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
290               " </properties>" +
291               "</cacheloader></config>";
292       clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
293       mgr.setConfig(clc, null);
294       cl = mgr.getCacheLoader();
295
296       Assert.assertEquals(ChainingCacheLoader.class, cl.getClass());
297       Assert.assertEquals(2, ((ChainingCacheLoader) cl).getSize());
298       loaders = ((ChainingCacheLoader) cl).getCacheLoaders();
299       Assert.assertEquals(FileCacheLoader.class, loaders.get(0).getClass());
300       Assert.assertEquals(AsyncCacheLoader.class, loaders.get(1).getClass());
301    }
302
303    public void testMoreThanOneFetchPersistentState() throws Exception JavaDoc
304    {
305       CacheLoaderManager mgr = new CacheLoaderManager();
306       CacheLoaderConfig cfg = createCacheLoaderCfg(false);
307       CacheLoaderConfig.IndividualCacheLoaderConfig i = createIndividualCacheLoaderConfig(cfg, true, "org.jboss.cache.loader.FileCacheLoader");
308       i.setFetchPersistentState(true);
309       CacheLoaderConfig.IndividualCacheLoaderConfig i2 = createIndividualCacheLoaderConfig(cfg, true, "org.jboss.cache.loader.FileCacheLoader");
310       i2.setFetchPersistentState(true);
311
312       cfg.addIndividualCacheLoaderConfig(i);
313       cfg.addIndividualCacheLoaderConfig(i2);
314
315       Assert.assertEquals(2, cfg.getIndividualCacheLoaderConfigs().size());
316
317       try
318       {
319          mgr.setConfig(cfg, null);
320          Assert.assertTrue("Should throw exception since we have > 1 cache loader with fetchPersistentState as true", false);
321       }
322       catch (Exception JavaDoc e)
323       {
324          Assert.assertTrue(true);
325       }
326
327       // control cases which should not throw exceptions
328
mgr = new CacheLoaderManager();
329       cfg = createCacheLoaderCfg(false);
330       i = createIndividualCacheLoaderConfig(cfg, true, "org.jboss.cache.loader.FileCacheLoader");
331       i.setFetchPersistentState(true);
332
333       cfg.addIndividualCacheLoaderConfig(i);
334
335       Assert.assertEquals(1, cfg.getIndividualCacheLoaderConfigs().size());
336       mgr.setConfig(cfg, null);
337
338       // control cases which should not throw exceptions
339
mgr = new CacheLoaderManager();
340       cfg = createCacheLoaderCfg(false);
341       i = createIndividualCacheLoaderConfig(cfg, true, "org.jboss.cache.loader.FileCacheLoader");
342       i.setFetchPersistentState(true);
343       i2 = createIndividualCacheLoaderConfig(cfg, true, "org.jboss.cache.loader.FileCacheLoader");
344       i2.setFetchPersistentState(false);
345
346       cfg.addIndividualCacheLoaderConfig(i);
347       cfg.addIndividualCacheLoaderConfig(i2);
348
349       Assert.assertEquals(2, cfg.getIndividualCacheLoaderConfigs().size());
350       mgr.setConfig(cfg, null);
351
352       // control cases which should not throw exceptions
353
mgr = new CacheLoaderManager();
354       cfg = createCacheLoaderCfg(false);
355       i = createIndividualCacheLoaderConfig(cfg, true, "org.jboss.cache.loader.FileCacheLoader");
356       i.setFetchPersistentState(false);
357       i2 = createIndividualCacheLoaderConfig(cfg, true, "org.jboss.cache.loader.FileCacheLoader");
358       i2.setFetchPersistentState(false);
359
360       cfg.addIndividualCacheLoaderConfig(i);
361       cfg.addIndividualCacheLoaderConfig(i2);
362
363       Assert.assertEquals(2, cfg.getIndividualCacheLoaderConfigs().size());
364       mgr.setConfig(cfg, null);
365    }
366
367    public void testConfigurationParsing() throws Exception JavaDoc
368    {
369
370       String JavaDoc conf = "<config>" +
371               "<passivation>false</passivation>" +
372               "<preload>/, /blah, /blah2</preload>" +
373               "<cacheloader>" +
374               " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
375               " <async>false</async>" +
376               " <fetchPersistentState>false</fetchPersistentState>" +
377               " <ignoreModifications>true</ignoreModifications>" +
378               " <properties>" +
379               " location=" + getTempDir() +
380               " </properties>" +
381               "</cacheloader>" +
382               "<cacheloader>" +
383               " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
384               " <async>true</async>" +
385               " <fetchPersistentState>true</fetchPersistentState>" +
386               " <ignoreModifications>false</ignoreModifications>" +
387               " <properties>" +
388               "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
389               " </properties>" +
390               "</cacheloader></config>";
391       CacheLoaderConfig clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
392       CacheLoaderManager mgr = new CacheLoaderManager();
393       mgr.setConfig(clc, null);
394
395       Assert.assertEquals(ChainingCacheLoader.class, mgr.getCacheLoader().getClass());
396       Assert.assertTrue("Should be true", mgr.isFetchPersistentState());
397       Assert.assertTrue("Passivation shuld be false", !mgr.isPassivation());
398       CacheLoaderConfig c = mgr.getCacheLoaderConfig();
399       Assert.assertTrue("Should be using a chaining cache loader", c.useChainingCacheLoader());
400       Assert.assertEquals("/, /blah, /blah2", c.getPreload());
401       Assert.assertEquals(2, c.getIndividualCacheLoaderConfigs().size());
402
403       CacheLoaderConfig.IndividualCacheLoaderConfig icfg = c.getIndividualCacheLoaderConfigs().get(0);
404       Assert.assertEquals("org.jboss.cache.loader.FileCacheLoader", icfg.getClassName());
405       Assert.assertTrue("Async shld be false", !icfg.isAsync());
406       Assert.assertTrue("fetchPersistentState shld be false", !icfg.isFetchPersistentState());
407       Assert.assertTrue("IgnoreMods should be true", icfg.isIgnoreModifications());
408       Assert.assertEquals(1, icfg.getProperties().size());
409
410       icfg = c.getIndividualCacheLoaderConfigs().get(1);
411       Assert.assertEquals("org.jboss.cache.loader.JDBCCacheLoader", icfg.getClassName());
412       Assert.assertTrue("Async shld be true", icfg.isAsync());
413       Assert.assertTrue("fetchPersistentState shld be true", icfg.isFetchPersistentState());
414       Assert.assertTrue("IgnoreMods should be false", !icfg.isIgnoreModifications());
415       Assert.assertEquals(4, icfg.getProperties().size());
416
417       // fetch PersistentState shld be false now
418
conf = "<config>" +
419               "<passivation>false</passivation>" +
420               "<preload>/, /blah, /blah2</preload>" +
421               "<cacheloader>" +
422               " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
423               " <async>false</async>" +
424               " <fetchPersistentState>false</fetchPersistentState>" +
425               " <ignoreModifications>true</ignoreModifications>" +
426               " <properties>" +
427               " location=" + getTempDir() +
428               " </properties>" +
429               "</cacheloader>" +
430               "<cacheloader>" +
431               " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
432               " <async>true</async>" +
433               " <fetchPersistentState>false</fetchPersistentState>" +
434               " <ignoreModifications>false</ignoreModifications>" +
435               " <properties>" +
436               "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
437               " </properties>" +
438               "</cacheloader></config>";
439       clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
440
441       mgr = new CacheLoaderManager();
442       mgr.setConfig(clc, null);
443
444       Assert.assertTrue("Should be false", !mgr.isFetchPersistentState());
445
446
447    }
448
449    public void testSingletonConfiguration() throws Exception JavaDoc
450    {
451       String JavaDoc conf = "<config>" +
452               "<passivation>false</passivation>" +
453               "<preload>/, /blah, /blah2</preload>" +
454               "<cacheloader>" +
455               " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
456               " <async>false</async>" +
457               " <fetchPersistentState>false</fetchPersistentState>" +
458               " <ignoreModifications>true</ignoreModifications>" +
459               " <properties>" +
460               " location=" + getTempDir() +
461               " </properties>" +
462               "</cacheloader>" +
463               "</config>";
464       CacheLoaderConfig clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
465       CacheLoaderManager mgr = new CacheLoaderManager();
466       mgr.setConfig(clc, null);
467
468       CacheLoaderConfig.IndividualCacheLoaderConfig iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
469       assertFalse("Singleton has not been configured", iclc.isSingletonStore());
470       assertFalse("Singleton.pushStateWhenCoordinator has not been configured", iclc.isPushStateWhenCoordinator());
471
472       conf = "<config>" +
473               "<passivation>false</passivation>" +
474               "<preload>/, /blah, /blah2</preload>" +
475               "<cacheloader>" +
476               " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
477               " <async>false</async>" +
478               " <fetchPersistentState>false</fetchPersistentState>" +
479               " <ignoreModifications>true</ignoreModifications>" +
480               " <properties>" +
481               " location=" + getTempDir() +
482               " </properties>" +
483               " <singletonStore>true</singletonStore>" +
484               "</cacheloader>" +
485               "</config>";
486       clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
487       mgr = new MockCacheLoaderManager();
488       mgr.setConfig(clc, null);
489
490       iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
491       assertTrue("Singleton has been configured", iclc.isSingletonStore());
492       assertFalse("Singleton.pushStateWhenCoordinator has not been configured", iclc.isPushStateWhenCoordinator());
493
494       conf = "<config>" +
495               "<passivation>false</passivation>" +
496               "<preload>/, /blah, /blah2</preload>" +
497               "<cacheloader>" +
498               " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
499               " <async>false</async>" +
500               " <fetchPersistentState>false</fetchPersistentState>" +
501               " <ignoreModifications>true</ignoreModifications>" +
502               " <properties>" +
503               " location=" + getTempDir() +
504               " </properties>" +
505               " <singletonStore>false</singletonStore>" +
506               "</cacheloader>" +
507               "</config>";
508       clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
509       mgr = new CacheLoaderManager();
510       mgr.setConfig(clc, null);
511
512       iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
513       assertFalse("Singleton has not been configured", iclc.isSingletonStore());
514       assertFalse("Singleton.pushStateWhenCoordinator has not been configured", iclc.isPushStateWhenCoordinator());
515
516       conf = "<config>" +
517               "<passivation>false</passivation>" +
518               "<preload>/, /blah, /blah2</preload>" +
519               "<cacheloader>" +
520               " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
521               " <async>false</async>" +
522               " <fetchPersistentState>false</fetchPersistentState>" +
523               " <ignoreModifications>true</ignoreModifications>" +
524               " <properties>" +
525               " location=" + getTempDir() +
526               " </properties>" +
527               " <singletonStore pushStateWhenCoordinator=\"false\">true</singletonStore>" +
528               "</cacheloader>" +
529               "</config>";
530       clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
531       mgr = new MockCacheLoaderManager();
532       mgr.setConfig(clc, null);
533
534       iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
535       assertTrue("Singleton has been configured", iclc.isSingletonStore());
536       assertFalse("Singleton.pushStateWhenCoordinator has not been configured", iclc.isPushStateWhenCoordinator());
537
538       conf = "<config>" +
539               "<passivation>false</passivation>" +
540               "<preload>/, /blah, /blah2</preload>" +
541               "<cacheloader>" +
542               " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
543               " <async>false</async>" +
544               " <fetchPersistentState>false</fetchPersistentState>" +
545               " <ignoreModifications>true</ignoreModifications>" +
546               " <properties>" +
547               " location=" + getTempDir() +
548               " </properties>" +
549               " <singletonStore pushStateWhenCoordinator=\"false\">false</singletonStore>" +
550               "</cacheloader>" +
551               "</config>";
552       clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
553       mgr = new CacheLoaderManager();
554       mgr.setConfig(clc, null);
555
556       iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
557       assertFalse("Singleton has not been configured", iclc.isSingletonStore());
558       assertFalse("Singleton.pushStateWhenCoordinator has not been configured", iclc.isPushStateWhenCoordinator());
559
560       conf = "<config>" +
561               "<passivation>false</passivation>" +
562               "<preload>/, /blah, /blah2</preload>" +
563               "<cacheloader>" +
564               " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
565               " <async>false</async>" +
566               " <fetchPersistentState>false</fetchPersistentState>" +
567               " <ignoreModifications>true</ignoreModifications>" +
568               " <properties>" +
569               " location=" + getTempDir() +
570               " </properties>" +
571               " <singletonStore pushStateWhenCoordinator=\"true\">false</singletonStore>" +
572               "</cacheloader>" +
573               "</config>";
574       clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
575       mgr = new CacheLoaderManager();
576       mgr.setConfig(clc, null);
577
578       iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
579       assertFalse("Singleton has not been configured", iclc.isSingletonStore());
580       assertFalse("Singleton.pushStateWhenCoordinator should be false has not been configured", iclc.isPushStateWhenCoordinator());
581
582       conf = "<config>" +
583               "<passivation>false</passivation>" +
584               "<preload>/, /blah, /blah2</preload>" +
585               "<cacheloader>" +
586               " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
587               " <async>false</async>" +
588               " <fetchPersistentState>false</fetchPersistentState>" +
589               " <ignoreModifications>true</ignoreModifications>" +
590               " <properties>" +
591               " location=" + getTempDir() +
592               " </properties>" +
593               " <singletonStore pushStateWhenCoordinator=\"true\">true</singletonStore>" +
594               "</cacheloader>" +
595               "</config>";
596       clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
597       mgr = new MockCacheLoaderManager();
598       mgr.setConfig(clc, null);
599
600       iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
601       assertTrue("Singleton has been configured", iclc.isSingletonStore());
602       assertTrue("Singleton.pushStateWhenCoordinator has been configured", iclc.isPushStateWhenCoordinator());
603
604       conf = "<config>" +
605               "<passivation>false</passivation>" +
606               "<shared>true</shared>" +
607               "<preload>/, /blah, /blah2</preload>" +
608               "<cacheloader>" +
609               " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
610               " <async>false</async>" +
611               " <fetchPersistentState>false</fetchPersistentState>" +
612               " <ignoreModifications>true</ignoreModifications>" +
613               " <properties>" +
614               " location=" + getTempDir() +
615               " </properties>" +
616               " <singletonStore pushStateWhenCoordinator=\"true\">true</singletonStore>" +
617               "</cacheloader>" +
618               "</config>";
619       clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
620       mgr = new CacheLoaderManager();
621       try
622       {
623          mgr.setConfig(clc, null);
624          fail("A cache loader cannot be configured as singleton and shared, should have thrown an Exception");
625       }
626       catch (Exception JavaDoc e)
627       {
628       }
629    }
630
631    private class MockCacheLoaderManager extends CacheLoaderManager
632    {
633       protected void addCacheListener(CacheSPI cache, CacheListener listener)
634       {
635          /* do nothing... */
636       }
637    }
638
639    public static Test suite()
640    {
641       return new TestSuite(CacheLoaderManagerTest.class);
642    }
643
644    public static void main(String JavaDoc[] args)
645    {
646       junit.textui.TestRunner.run(suite());
647    }
648 }
649
Popular Tags