[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/loader ...
Mircea Markus
mircea.markus at gmail.com
Sat Feb 10 12:47:02 EST 2007
User: mmarkus
Date: 07/02/10 12:47:02
Modified: tests/functional/org/jboss/cache/loader
JDBCCacheLoaderTest.java
C3p0JDBCCacheLoaderTest.java
C3p0ConnectionFactoryTest.java
JDBCCacheLoaderConfigTest.java
Added: tests/functional/org/jboss/cache/loader
AdjListJDBCClassLoaderCompatibilityTest.java
Log:
JDBCCaheLoader performance improvements. Also added benchmarks for comparisons and backward compatibility tests
Revision Changes Path
1.11 +9 -2 JBossCache/tests/functional/org/jboss/cache/loader/JDBCCacheLoaderTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: JDBCCacheLoaderTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/JDBCCacheLoaderTest.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- JDBCCacheLoaderTest.java 21 Jan 2007 15:46:42 -0000 1.10
+++ JDBCCacheLoaderTest.java 10 Feb 2007 17:47:02 -0000 1.11
@@ -24,7 +24,7 @@
*
* @author <a href="hmesha at novell.com">Hany Mesha</a>
* @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
- * @version <tt>$Revision: 1.10 $</tt>
+ * @version <tt>$Revision: 1.11 $</tt>
*/
public class JDBCCacheLoaderTest extends CacheLoaderTestsBase
{
@@ -41,7 +41,8 @@
"cache.jdbc.url=" + prop.getProperty("cache.jdbc.url") + "\n" +
"cache.jdbc.user=" + prop.getProperty("cache.jdbc.user") + "\n" +
"cache.jdbc.password=" + prop.getProperty("cache.jdbc.password") + "\n" +
- "cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type");
+ "cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type") + "\n" +
+ "cache.jdbc.sql-concat=" + prop.getProperty("cache.jdbc.sql-concat");
cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("",
"org.jboss.cache.loader.JDBCCacheLoader", props, false, true, false));
@@ -92,6 +93,12 @@
}
}
+ public void testRootIsCreated() throws Exception
+ {
+ loader.put(Fqn.fromString("/a/b/c"), "a", "b");
+ assertTrue(loader.exists(Fqn.ROOT));
+ }
+
public static Test suite()
{
return new TestSuite(JDBCCacheLoaderTest.class);
1.2 +1 -0 JBossCache/tests/functional/org/jboss/cache/loader/C3p0JDBCCacheLoaderTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: C3p0JDBCCacheLoaderTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/C3p0JDBCCacheLoaderTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- C3p0JDBCCacheLoaderTest.java 21 Jan 2007 15:46:42 -0000 1.1
+++ C3p0JDBCCacheLoaderTest.java 10 Feb 2007 17:47:02 -0000 1.2
@@ -39,6 +39,7 @@
"cache.jdbc.user=" + prop.getProperty("cache.jdbc.user") + "\n" +
"cache.jdbc.password=" + prop.getProperty("cache.jdbc.password") + "\n" +
"cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type") + "\n" +
+ "cache.jdbc.sql-concat=" + prop.getProperty("cache.jdbc.sql-concat") + "\n" +
"cache.jdbc.connection.factory=" + CF_CLASS;
cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("",
1.2 +2 -2 JBossCache/tests/functional/org/jboss/cache/loader/C3p0ConnectionFactoryTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: C3p0ConnectionFactoryTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/C3p0ConnectionFactoryTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- C3p0ConnectionFactoryTest.java 21 Jan 2007 15:46:42 -0000 1.1
+++ C3p0ConnectionFactoryTest.java 10 Feb 2007 17:47:02 -0000 1.2
@@ -25,7 +25,7 @@
private static final Log log = LogFactory.getLog(C3p0ConnectionFactoryTest.class);
private C3p0ConnectionFactory cf;
- private JDBCCacheLoaderConfig config;
+ private AdjListJDBCClassLoaderConfig config;
public C3p0ConnectionFactoryTest(String string)
{
@@ -36,7 +36,7 @@
{
Properties prop = load("cache-jdbc.properties");
- config = new JDBCCacheLoaderConfig();
+ config = new AdjListJDBCClassLoaderConfig();
config.setProperties(prop);
}
1.2 +4 -4 JBossCache/tests/functional/org/jboss/cache/loader/JDBCCacheLoaderConfigTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: JDBCCacheLoaderConfigTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/JDBCCacheLoaderConfigTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- JDBCCacheLoaderConfigTest.java 21 Jan 2007 15:46:42 -0000 1.1
+++ JDBCCacheLoaderConfigTest.java 10 Feb 2007 17:47:02 -0000 1.2
@@ -9,17 +9,17 @@
import junit.framework.TestCase;
/**
- * Unit test for JDBCCacheLoaderConfig
+ * Unit test for JDBCCacheLoaderConfigTest
*
* @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
*/
public class JDBCCacheLoaderConfigTest extends TestCase
{
- private JDBCCacheLoaderConfig cacheLoaderConfig;
+ private AdjListJDBCClassLoaderConfig cacheLoaderConfig;
protected void setUp() throws Exception
{
- cacheLoaderConfig = new JDBCCacheLoaderConfig();
+ cacheLoaderConfig = new AdjListJDBCClassLoaderConfig();
}
public void testSetGetConnectionFactory()
@@ -31,7 +31,7 @@
public void testEqualsHashCode()
{
cacheLoaderConfig.setConnectionFactoryClass("com.acme.Paradise");
- JDBCCacheLoaderConfig other = new JDBCCacheLoaderConfig();
+ AdjListJDBCClassLoaderConfig other = new AdjListJDBCClassLoaderConfig();
other.setConnectionFactoryClass("com.acme.Paradise");
assertTrue(cacheLoaderConfig.equals(other));
assertEquals(cacheLoaderConfig.hashCode(), other.hashCode());
1.1 date: 2007/02/10 17:47:02; author: mmarkus; state: Exp;JBossCache/tests/functional/org/jboss/cache/loader/AdjListJDBCClassLoaderCompatibilityTest.java
Index: AdjListJDBCClassLoaderCompatibilityTest.java
===================================================================
package org.jboss.cache.loader;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.xml.XmlHelper;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.marshall.NodeData;
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.util.stream.MarshalledValueOutputStream;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.w3c.dom.Element;
import java.util.Properties;
import java.util.ArrayList;
import java.util.HashSet;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import junit.framework.TestCase;
/**
* Tests the compatibility between <tt>JDBCCacheLoader</tt> and <tt>JDBCCacheLoaderOld</tt>. More exactly,
* it tests whether the new <tt>JDBCCacheLoader</tt> works fine on data previously created
* <tt>JDBCCacheLoaderOld</tt>.
*
* @author Mircea.Markus at iquestint.com
* @version 1.0
*/
public class AdjListJDBCClassLoaderCompatibilityTest extends TestCase
{
private JDBCCacheLoaderOld oldImpl;
private JDBCCacheLoader newImpl;
/**
* Note : newImpl is not started here but in each individual test. That's because on start it performs
* some backward compatibility logic.
* @see JDBCCacheLoader#start()
*/
protected void setUp() throws Exception
{
super.setUp();
newImpl = getNewCacheLoader();
oldImpl = getOldLoader();
CacheImpl cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
CacheImpl cache2 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
newImpl.setCache(cache);//this is needed for marshaller
oldImpl.setCache(cache2);
oldImpl.start();
oldImpl.remove(Fqn.ROOT);
}
protected void tearDown() throws Exception
{
super.tearDown();
oldImpl.remove(Fqn.ROOT);
oldImpl.stop();
newImpl.stop();
}
public void testCommonOperations() throws Exception
{
newImpl.start();
oldImpl.put(Fqn.fromString("/a/b/c"), "key1", "value1");
oldImpl.put(Fqn.fromString("/a/b/d"), "key2", "value2");
oldImpl.put(Fqn.fromString("/a/b/e"), "key3", "value3");
assertTrue(newImpl.exists(Fqn.fromString("/a/b/c")));
assertTrue(newImpl.exists(Fqn.fromString("/a/b/d")));
assertTrue(newImpl.exists(Fqn.fromString("/a/b/e")));
assertEquals("value1", newImpl.get(Fqn.fromString("/a/b/c")).get("key1"));
assertEquals("value2", newImpl.get(Fqn.fromString("/a/b/d")).get("key2"));
assertEquals("value3", newImpl.get(Fqn.fromString("/a/b/e")).get("key3"));
}
/**
* Does the new implementation manage to successfully remove nodes created by old one?
*/
public void testRemove() throws Exception
{
oldImpl.put(Fqn.fromString("/a/b/c"), "key1", "value1");
oldImpl.put(Fqn.fromString("/a/b/d"), "key2", "value2");
oldImpl.put(Fqn.fromString("/a/b/e"), "key3", "value3");
oldImpl.put(Fqn.fromString("/a/f/e"), "key4", "value4");
assertTrue(newImpl.exists(Fqn.fromString("/a/b/c")));
assertTrue(newImpl.exists(Fqn.fromString("/a/b/d")));
assertTrue(newImpl.exists(Fqn.fromString("/a/b/e")));
newImpl.start();
newImpl.remove(Fqn.fromString("/a/b"));
assertFalse(newImpl.exists(Fqn.fromString("/a/b/c")));
assertFalse(newImpl.exists(Fqn.fromString("/a/b/d")));
assertFalse(newImpl.exists(Fqn.fromString("/a/b/e")));
assertTrue(newImpl.exists(Fqn.fromString("/a/f")));
assertTrue(newImpl.exists(Fqn.fromString("/a/f/e")));
}
public void testLoadEntireState() throws Exception
{
oldImpl.put(Fqn.fromString("/a/b/c"), "key1", "value1");
oldImpl.put(Fqn.fromString("/a/b/d"), "key2", "value2");
oldImpl.put(Fqn.fromString("/a/b/e"), "key3", "value3");
oldImpl.put(Fqn.fromString("/a/f/e"), "key4", "value4");
oldImpl.put(Fqn.ROOT, "root_key", "root_value");
ByteArrayOutputStream newBaos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream newOs = new MarshalledValueOutputStream(newBaos);
newImpl.start();
newImpl.loadEntireState(newOs);
newImpl.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, newOs);
newOs.close();
newImpl.remove(Fqn.ROOT);
assertNull(newImpl.get(Fqn.fromString("/a/b/c")));
assertNull(newImpl.get(Fqn.fromString("/a/b/d")));
assertNull(newImpl.get(Fqn.fromString("/a/b/e")));
assertNull(newImpl.get(Fqn.fromString("/a/f/e")));
assertNull(newImpl.get(Fqn.ROOT));
ByteArrayInputStream bais = new ByteArrayInputStream(newBaos.toByteArray());
MarshalledValueInputStream is = new MarshalledValueInputStream(bais);
newImpl.storeEntireState(is);
assertEquals(newImpl.get(Fqn.fromString("/a/b/c")).get("key1"),"value1");
assertEquals(newImpl.get(Fqn.fromString("/a/b/d")).get("key2"),"value2");
assertEquals(newImpl.get(Fqn.fromString("/a/b/e")).get("key3"),"value3");
assertEquals(newImpl.get(Fqn.fromString("/a/f/e")).get("key4"),"value4");
assertEquals(newImpl.get(Fqn.ROOT).get("root_key"),"root_value");
assertEquals(newImpl.getNodeCount(), 8);
}
public void testLoadNodeState() throws Exception {
oldImpl.put(Fqn.fromString("/a/b/c"), "key1", "value1");
oldImpl.put(Fqn.fromString("/a/b/d"), "key2", "value2");
oldImpl.put(Fqn.fromString("/a/b/e"), "key3", "value3");
oldImpl.put(Fqn.fromString("/a/f/e"), "key4", "value4");
oldImpl.put(Fqn.ROOT, "root_key", "root_value");
ByteArrayOutputStream newBaos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream newOs = new MarshalledValueOutputStream(newBaos);
newImpl.start();
newImpl.loadState(Fqn.fromString("/a/b"), newOs);
newImpl.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, newOs);
newOs.close();
newImpl.remove(Fqn.fromString("/a/b"));
assertNull(newImpl.get(Fqn.fromString("/a/b/c")));
assertNull(newImpl.get(Fqn.fromString("/a/b/d")));
assertNull(newImpl.get(Fqn.fromString("/a/b/e")));
assertNull(newImpl.get(Fqn.fromString("/a/b")));
ByteArrayInputStream bais = new ByteArrayInputStream(newBaos.toByteArray());
MarshalledValueInputStream is = new MarshalledValueInputStream(bais);
newImpl.storeState(Fqn.fromString("/a/b"), is);
assertEquals(newImpl.get(Fqn.fromString("/a/b/c")).get("key1"),"value1");
assertEquals(newImpl.get(Fqn.fromString("/a/b/d")).get("key2"),"value2");
assertEquals(newImpl.get(Fqn.fromString("/a/b/e")).get("key3"),"value3");
assertEquals(newImpl.get(Fqn.fromString("/a/f/e")).get("key4"),"value4");
assertEquals(newImpl.get(Fqn.ROOT).get("root_key"),"root_value");
assertEquals(newImpl.getNodeCount(), 8);
}
/**
* getNodeDataList is a template method on which the serialisation process relies. We check here that the new
* implementation works exactelly as the old one.
*/
public void testGetNodeData() throws Exception {
oldImpl.put(Fqn.fromString("/a/b/c"), "key1", "value1");
oldImpl.put(Fqn.fromString("/a/b/d"), "key2", "value2");
oldImpl.put(Fqn.fromString("/a/b/e"), "key3", "value3");
oldImpl.put(Fqn.fromString("/a/f/e"), "key4", "value4");
oldImpl.put(Fqn.ROOT, "root_key", "root_value");
newImpl.start();
ArrayList<NodeData> oldList = new ArrayList<NodeData>();
oldImpl.getNodeDataList(Fqn.ROOT, oldList);
ArrayList<NodeData> newList = new ArrayList<NodeData>();
newImpl.getNodeDataList(Fqn.ROOT, newList);
assertEquals(new HashSet<NodeData>(oldList), new HashSet<NodeData>(newList));
}
/**
* Tests performs some backward copatibility work. See {@link JDBCCacheLoader#start()} for details.
*/
public void testStartWork() throws Exception
{
oldImpl.put(Fqn.fromString("/a/b/c"), "key1", "value1");
oldImpl.put(Fqn.fromString("/a/b/d"), "key2", "value2");
assertNull(oldImpl.get(Fqn.ROOT));
newImpl.start();
assertNotNull(newImpl.get(Fqn.ROOT));
}
protected CacheLoaderConfig getSingleCacheLoaderConfig(String preload, String cacheloaderClass, String properties) throws Exception
{
String xml = "<config>\n" +
"<passivation>false</passivation>\n" +
"<preload>" + preload + "</preload>\n" +
"<cacheloader>\n" +
"<class>" + cacheloaderClass + "</class>\n" +
"<properties>" + properties + "</properties>\n" +
"<async>false</async>\n" +
"<shared>false</shared>\n" +
"<fetchPersistentState>true</fetchPersistentState>\n" +
"<purgeOnStartup>false</purgeOnStartup>\n" +
"</cacheloader>\n" +
"</config>";
Element element = XmlHelper.stringToElement(xml);
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
protected Properties getProperties() throws Exception
{
Properties prop = new Properties();
try
{
prop.load(this.getClass().getClassLoader().getResourceAsStream("cache-jdbc.properties"));
return prop;
}
catch (Exception e)
{
throw new Exception("Error loading jdbc properties ", e);
}
}
private JDBCCacheLoader getNewCacheLoader() throws Exception
{
Properties prop = getProperties();
String props = "cache.jdbc.driver =" + prop.getProperty("cache.jdbc.driver") + "\n" +
"cache.jdbc.url=" + prop.getProperty("cache.jdbc.url") + "\n" +
"cache.jdbc.user=" + prop.getProperty("cache.jdbc.user") + "\n" +
"cache.jdbc.password=" + prop.getProperty("cache.jdbc.password") + "\n" +
"cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type") + "\n" +
"cache.jdbc.sql-concat=" + prop.getProperty("cache.jdbc.sql-concat") + "\n";
CacheLoaderConfig.IndividualCacheLoaderConfig base = getSingleCacheLoaderConfig("", "org.jboss.cache.loader.JDBCCacheLoader", props).getFirstCacheLoaderConfig();
JDBCCacheLoader jdbcCacheLoader = new JDBCCacheLoader();
jdbcCacheLoader.setConfig(base);
return jdbcCacheLoader;
}
private JDBCCacheLoaderOld getOldLoader() throws Exception
{
Properties prop = getProperties();
String props = "cache.jdbc.driver =" + prop.getProperty("cache.jdbc.driver") + "\n" +
"cache.jdbc.url=" + prop.getProperty("cache.jdbc.url") + "\n" +
"cache.jdbc.user=" + prop.getProperty("cache.jdbc.user") + "\n" +
"cache.jdbc.password=" + prop.getProperty("cache.jdbc.password") + "\n" +
"cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type") + "\n" +
"cache.jdbc.sql-concat=" + prop.getProperty("cache.jdbc.sql-concat") + "\n" +
"cache.jdbc.connection.factory=org.jboss.cache.manualtests.cacheloader.OneConnectionFactory";
CacheLoaderConfig.IndividualCacheLoaderConfig base = getSingleCacheLoaderConfig("", "org.jboss.cache.loader.JDBCCacheLoader", props).getFirstCacheLoaderConfig();
JDBCCacheLoaderOld jdbcCacheLoader = new JDBCCacheLoaderOld();
jdbcCacheLoader.setConfig(base);
return jdbcCacheLoader;
}
}
More information about the jboss-cvs-commits
mailing list