[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/factories ...
Vladmir Blagojevic
vladimir.blagojevic at jboss.com
Mon Apr 16 13:37:11 EDT 2007
User: vblagojevic
Date: 07/04/16 13:37:11
Added: tests/functional/org/jboss/cache/factories
UnitTestCacheConfigurationFactory.java
Removed: tests/functional/org/jboss/cache/factories
UnitTestCacheFactory.java
Log:
rename UnitTestCacheFactory to UnitTestCacheConfigurationFactory
Revision Changes Path
1.1 date: 2007/04/16 17:37:11; author: vblagojevic; state: Exp;JBossCache/tests/functional/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java
Index: UnitTestCacheConfigurationFactory.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.factories;
import java.io.InputStream;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.xml.XmlHelper;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* Cache configuration factory used by unit tests.
*/
public class UnitTestCacheConfigurationFactory
{
public static String JGROUPS_CHANNEL = "udp";//use udp by default
public static String JGROUPS_STACK_TYPE = "jgroups.stack";
public static String DEFAULT_CONFIGURATION_FILE = "META-INF/unit-test-cache-service.xml";
static
{
JGROUPS_CHANNEL = System.getProperty(JGROUPS_STACK_TYPE, JGROUPS_CHANNEL);
}
public static Configuration createConfiguration(CacheMode mode) throws ConfigurationException
{
return createConfiguration(mode, false, false);
}
public static Configuration createConfiguration(CacheMode mode, boolean useEviction) throws ConfigurationException
{
return createConfiguration(mode, useEviction, false);
}
public static Configuration createConfiguration(CacheMode mode, boolean useEviction, boolean usePassivation) throws ConfigurationException
{
UnitTestXmlConfigurationParser parser = new UnitTestXmlConfigurationParser();
Configuration c = parser.parseFile(DEFAULT_CONFIGURATION_FILE, mode);
if (!useEviction)
{
c.setEvictionConfig(null);
}
if (!usePassivation)
{
c.setCacheLoaderConfig(null);
}
return c;
}
public static CacheLoaderConfig getSingleCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared) throws Exception
{
return getSingleCacheLoaderConfig(preload, cacheloaderClass, properties, async, fetchPersistentState, shared, false);
}
public static CacheLoaderConfig getSingleCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
{
return getSingleCacheLoaderConfig(false, preload, cacheloaderClass, properties, async, fetchPersistentState, shared, purgeOnStartup);
}
protected static CacheLoaderConfig getSingleCacheLoaderConfig(boolean passivation, String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
{
String xml = "<config>\n" +
"<passivation>" + passivation + "</passivation>\n" +
"<preload>" + preload + "</preload>\n" +
"<cacheloader>\n" +
"<class>" + cacheloaderClass + "</class>\n" +
"<properties>" + properties + "</properties>\n" +
"<async>" + async + "</async>\n" +
"<shared>" + shared + "</shared>\n" +
"<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
"<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +
"</cacheloader>\n" +
"</config>";
Element element = XmlHelper.stringToElement(xml);
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
private static class UnitTestXmlConfigurationParser extends XmlConfigurationParser
{
public Configuration parseFile(String filename, CacheMode mode)
{
return parseStream(getAsInputStreamFromClassLoader(DEFAULT_CONFIGURATION_FILE), mode);
}
public Configuration parseStream(InputStream stream, CacheMode mode)
{
// loop through all elements in XML.
if (stream == null) throw new ConfigurationException("Input stream for configuration xml is null!");
Element root = XmlHelper.getDocumentRoot(stream);
Element mbeanElement = getMBeanElement(root);
ParsedAttributes attributes = extractAttributes(mbeanElement);
// Deal with rename of the old property that controlled MBean registration
String keepStats = attributes.stringAttribs.remove("UseMbean");
if (keepStats != null && attributes.stringAttribs.get("ExposeManagementStatistics") == null)
{
attributes.stringAttribs.put("ExposeManagementStatistics", keepStats);
}
Configuration c = new Configuration();
setValues(c, attributes.stringAttribs, false);
// Special handling for XML elements -- we hard code the parsing
setXmlValues(c, attributes.xmlAttribs);
Element list = (Element) root.getElementsByTagName("protocol_stacks").item(0);
NodeList stacks = list.getElementsByTagName("stack");
for (int i = 0; i < stacks.getLength(); i++)
{
Element stack = (Element) stacks.item(i);
String stackName = stack.getAttribute("name");
if (stackName.startsWith(JGROUPS_CHANNEL))
{
Element jgroupsStack = (Element) stack.getElementsByTagName("config").item(0);
if (mode == CacheMode.REPL_ASYNC && !stackName.contains("-"))
{
c.setClusterConfig(jgroupsStack);
c.setCacheMode(CacheMode.REPL_ASYNC);
break;
}
else if (mode == CacheMode.REPL_SYNC && stackName.contains("-"))
{
c.setClusterConfig(jgroupsStack);
c.setCacheMode(CacheMode.REPL_SYNC);
break;
}
}
}
return c;
}
}
}
More information about the jboss-cvs-commits
mailing list