[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/loader ...

Mircea Markus mircea.markus at gmail.com
Mon Mar 5 16:10:48 EST 2007


  User: mmarkus 
  Date: 07/03/05 16:10:48

  Modified:    tests/functional/org/jboss/cache/loader   
                        C3p0ConnectionFactoryTest.java
                        JDBCCacheLoaderConfigTest.java
  Added:       tests/functional/org/jboss/cache/loader   
                        AdjListJDBCCacheLoaderCompatibilityTest.java
  Log:
  some classes were incorreclly named *JDBCClassLoader* instead of *JDBCCacheLoader*. The typo was fixed.
  
  Revision  Changes    Path
  1.3       +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.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- C3p0ConnectionFactoryTest.java	10 Feb 2007 17:47:02 -0000	1.2
  +++ C3p0ConnectionFactoryTest.java	5 Mar 2007 21:10:48 -0000	1.3
  @@ -25,7 +25,7 @@
      private static final Log log = LogFactory.getLog(C3p0ConnectionFactoryTest.class);
   
      private C3p0ConnectionFactory cf;
  -   private AdjListJDBCClassLoaderConfig config;
  +   private AdjListJDBCCacheLoaderConfig config;
   
      public C3p0ConnectionFactoryTest(String string)
      {
  @@ -36,7 +36,7 @@
      {
         Properties prop = load("cache-jdbc.properties");
   
  -      config = new AdjListJDBCClassLoaderConfig();
  +      config = new AdjListJDBCCacheLoaderConfig();
         config.setProperties(prop);
      }
   
  
  
  
  1.3       +3 -3      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.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- JDBCCacheLoaderConfigTest.java	10 Feb 2007 17:47:02 -0000	1.2
  +++ JDBCCacheLoaderConfigTest.java	5 Mar 2007 21:10:48 -0000	1.3
  @@ -15,11 +15,11 @@
    */
   public class JDBCCacheLoaderConfigTest extends TestCase
   {
  -   private AdjListJDBCClassLoaderConfig cacheLoaderConfig;
  +   private AdjListJDBCCacheLoaderConfig cacheLoaderConfig;
   
      protected void setUp() throws Exception
      {
  -      cacheLoaderConfig = new AdjListJDBCClassLoaderConfig();
  +      cacheLoaderConfig = new AdjListJDBCCacheLoaderConfig();
      }
   
      public void testSetGetConnectionFactory()
  @@ -31,7 +31,7 @@
      public void testEqualsHashCode()
      {
         cacheLoaderConfig.setConnectionFactoryClass("com.acme.Paradise");
  -      AdjListJDBCClassLoaderConfig other = new AdjListJDBCClassLoaderConfig();
  +      AdjListJDBCCacheLoaderConfig other = new AdjListJDBCCacheLoaderConfig();
         other.setConnectionFactoryClass("com.acme.Paradise");
         assertTrue(cacheLoaderConfig.equals(other));
         assertEquals(cacheLoaderConfig.hashCode(), other.hashCode());
  
  
  
  1.1      date: 2007/03/05 21:10:48;  author: mmarkus;  state: Exp;JBossCache/tests/functional/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java
  
  Index: AdjListJDBCCacheLoaderCompatibilityTest.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 AdjListJDBCCacheLoaderCompatibilityTest 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