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

Manik Surtani msurtani at jboss.com
Thu Jan 11 08:49:06 EST 2007


  User: msurtani
  Date: 07/01/11 08:49:06

  Modified:    tests/functional/org/jboss/cache        
                        HungChannelTest.java TreeNodeTest.java FqnTest.java
                        GetKeysTest.java TreeCacheFunctionalTest.java
                        CallbackTest.java LifeCycleTest.java
  Added:       tests/functional/org/jboss/cache        
                        CacheFactoryTest.java
  Log:
  Changed CacheImpl ctor to be protected, and changed cache factories accordingly
  
  Revision  Changes    Path
  1.4       +4 -4      JBossCache/tests/functional/org/jboss/cache/HungChannelTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: HungChannelTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/HungChannelTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- HungChannelTest.java	30 Dec 2006 17:49:54 -0000	1.3
  +++ HungChannelTest.java	11 Jan 2007 13:49:06 -0000	1.4
  @@ -22,7 +22,7 @@
   
      protected void setUp() throws Exception
      {
  -      cache = new CacheImpl();
  +      cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
         cache.getConfiguration().setCacheMode("REPL_SYNC");
      }
   
  @@ -52,7 +52,7 @@
            ch.setOpt(Channel.AUTO_GETSTATE, Boolean.TRUE);
            cache.channel = ch;
   
  -         cache.start(); // the state transfer here should fail, leading to an exception being thrown.
  +         cache.start();// the state transfer here should fail, leading to an exception being thrown.
            fail("Expecting the startService() method to throw an exception");
         }
         catch (Exception e)
  @@ -60,7 +60,7 @@
            // normal behaviour
         }
   
  -      Channel c = cache.channel; // hold a reference to this since stopService will set this to null in the cache.
  +      Channel c = cache.channel;// hold a reference to this since stopService will set this to null in the cache.
   
         assertFalse("Channel should not have connected!", c.isConnected());
         assertFalse("Channel should not be open", c.isOpen());
  @@ -84,7 +84,7 @@
            fail("NOT expecting the startService() method to throw an exception");
         }
   
  -      Channel c = cache.channel; // hold a reference to this since stopService will set this to null in the cache.
  +      Channel c = cache.channel;// hold a reference to this since stopService will set this to null in the cache.
   
         assertTrue("Channel should have connected!", c.isConnected());
         assertTrue("Channel should be open", c.isOpen());
  
  
  
  1.6       +2 -48     JBossCache/tests/functional/org/jboss/cache/TreeNodeTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TreeNodeTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/TreeNodeTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- TreeNodeTest.java	30 Dec 2006 19:48:46 -0000	1.5
  +++ TreeNodeTest.java	11 Jan 2007 13:49:06 -0000	1.6
  @@ -8,7 +8,7 @@
    * Tests restart (stop-destroy-create-start) of CacheImpl
    *
    * @author Bela Ban
  - * @version $Id: TreeNodeTest.java,v 1.5 2006/12/30 19:48:46 msurtani Exp $
  + * @version $Id: TreeNodeTest.java,v 1.6 2007/01/11 13:49:06 msurtani Exp $
    */
   public class TreeNodeTest extends TestCase
   {
  @@ -17,8 +17,7 @@
      protected void setUp() throws Exception
      {
         super.setUp();
  -      cache = new CacheImpl();
  -      startCache(cache);
  +      cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache();
      }
   
      protected void tearDown() throws Exception
  @@ -44,51 +43,6 @@
   
      }
   
  -   /**
  -    * public void testRelocate() throws Exception
  -    * {
  -    * Object key = new Integer(1);
  -    * cache.put("/a/b/c", key, "test");
  -    * cache.put("/a/b/c/d", key, "test1");
  -    * cache.put("/relocate", "1", "1");
  -    * <p/>
  -    * DataNode node = cache.get("/a/b/c");
  -    * DataNode newParentNode = cache.get("/relocate");
  -    * assertFalse(newParentNode.hasChildren());
  -    * <p/>
  -    * Fqn newFqn = Fqn.fromString("/relocate/c");
  -    * <p/>
  -    * cache.put("/relocate/c", "1", "1");
  -    * <p/>
  -    * node.relocate(newParentNode, newFqn);
  -    * assertNotNull("/relocat/c should not be null", cache.get(newFqn));
  -    * <p/>
  -    * node = cache.get("/a/b");
  -    * assertTrue(!node.hasChildren());
  -    * assertTrue(!node.childExists("c"));
  -    * <p/>
  -    * node = cache.get("/relocate");
  -    * assertTrue(node.hasChildren());
  -    * assertTrue(node.childExists(newFqn.get(1)));
  -    * <p/>
  -    * node = cache.get(newFqn);
  -    * assertEquals(newFqn, node.getFqn());
  -    * assertTrue(node.hasChildren());
  -    * assertTrue(node.childExists("d"));
  -    * <p/>
  -    * node = cache.get("/relocate/c/d");
  -    * assertNotNull(node);
  -    * assertEquals("test1", cache.get("/relocate/c/d", key));
  -    * <p/>
  -    * assertNull(cache.get("/relocate/c/","1"));
  -    * }
  -    */
  -
  -   void startCache(CacheImpl c) throws Exception
  -   {
  -      c.create();
  -      c.start();
  -   }
   
      void stopCache(CacheImpl c)
      {
  
  
  
  1.22      +2 -3      JBossCache/tests/functional/org/jboss/cache/FqnTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: FqnTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/FqnTest.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -b -r1.21 -r1.22
  --- FqnTest.java	4 Jan 2007 05:35:41 -0000	1.21
  +++ FqnTest.java	11 Jan 2007 13:49:06 -0000	1.22
  @@ -11,7 +11,6 @@
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   import org.jboss.cache.config.Configuration;
  -import org.jboss.cache.factories.DefaultCacheFactory;
   import org.jgroups.util.Util;
   
   import java.util.HashMap;
  @@ -20,7 +19,7 @@
    * Tests {@link Fqn}.
    *
    * @author <a href="mailto:bela at jboss.org">Bela Ban</a> May 9, 2003
  - * @version $Revision: 1.21 $
  + * @version $Revision: 1.22 $
    */
   public class FqnTest extends TestCase
   {
  @@ -310,7 +309,7 @@
      public void testRemovalNonString() throws Exception
      {
         Fqn f = new Fqn(new Object[]{"test", 1});
  -      //       CacheImpl tc = new CacheImpl();
  +      //       CacheImpl tc = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
         //       tc.getConfiguration().setCacheMode("LOCAL");
         //       tc.start();
         Configuration c = new Configuration();
  
  
  
  1.5       +5 -9      JBossCache/tests/functional/org/jboss/cache/GetKeysTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: GetKeysTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/GetKeysTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- GetKeysTest.java	30 Dec 2006 19:48:46 -0000	1.4
  +++ GetKeysTest.java	11 Jan 2007 13:49:06 -0000	1.5
  @@ -18,7 +18,7 @@
   
   /**
    * @author <a href="mailto:bela at jboss.org">Bela Ban</a>
  - * @version $Id: GetKeysTest.java,v 1.4 2006/12/30 19:48:46 msurtani Exp $
  + * @version $Id: GetKeysTest.java,v 1.5 2007/01/11 13:49:06 msurtani Exp $
    */
   public class GetKeysTest extends TestCase
   {
  @@ -41,9 +41,7 @@
   
      public void testGetKeys() throws Exception
      {
  -      cache = new CacheImpl();
  -      cache.create();
  -      cache.start();
  +      cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache();
         cache.put("/a/b/c", "name", "Bela Ban");
         cache.put("/a/b/c", "age", 40);
         cache.put("/a/b/c", "city", "Kreuzlingen");
  @@ -55,14 +53,12 @@
   
         ByteArrayOutputStream outstream = new ByteArrayOutputStream(20);
         ObjectOutputStream out = new ObjectOutputStream(outstream);
  -      out.writeObject(keys); // must be serializable
  +      out.writeObject(keys);// must be serializable
      }
   
      public void testGetChildren() throws Exception
      {
  -      cache = new CacheImpl();
  -      cache.create();
  -      cache.start();
  +      cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache();
         cache.put("/a/b/c", null);
         cache.put("/a/b/c/1", null);
         cache.put("/a/b/c/2", null);
  @@ -75,7 +71,7 @@
   
         ByteArrayOutputStream outstream = new ByteArrayOutputStream(20);
         ObjectOutputStream out = new ObjectOutputStream(outstream);
  -      out.writeObject(children); // must be serializable
  +      out.writeObject(children);// must be serializable
      }
   
   
  
  
  
  1.8       +4 -2      JBossCache/tests/functional/org/jboss/cache/TreeCacheFunctionalTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TreeCacheFunctionalTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/TreeCacheFunctionalTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- TreeCacheFunctionalTest.java	30 Dec 2006 19:48:46 -0000	1.7
  +++ TreeCacheFunctionalTest.java	11 Jan 2007 13:49:06 -0000	1.8
  @@ -13,7 +13,7 @@
    * Simple functional tests for CacheImpl
    *
    * @author Bela Ban
  - * @version $Id: TreeCacheFunctionalTest.java,v 1.7 2006/12/30 19:48:46 msurtani Exp $
  + * @version $Id: TreeCacheFunctionalTest.java,v 1.8 2007/01/11 13:49:06 msurtani Exp $
    */
   public class TreeCacheFunctionalTest extends TestCase
   {
  @@ -28,7 +28,7 @@
      protected void setUp() throws Exception
      {
         super.setUp();
  -      cache = new CacheImpl();
  +      cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
         cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
         cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
         cache.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
  @@ -47,8 +47,10 @@
            cache = null;
         }
         if (ex != null)
  +      {
            throw ex;
      }
  +   }
   
   
      public void testPut() throws CacheException
  
  
  
  1.15      +15 -17    JBossCache/tests/functional/org/jboss/cache/CallbackTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CallbackTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/CallbackTest.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -b -r1.14 -r1.15
  --- CallbackTest.java	30 Dec 2006 17:49:54 -0000	1.14
  +++ CallbackTest.java	11 Jan 2007 13:49:06 -0000	1.15
  @@ -14,7 +14,7 @@
    * Tests whether modifications within callbacks (TreeCacheListener) are handled correctly
    *
    * @author Bela Ban
  - * @version $Id: CallbackTest.java,v 1.14 2006/12/30 17:49:54 msurtani Exp $
  + * @version $Id: CallbackTest.java,v 1.15 2007/01/11 13:49:06 msurtani Exp $
    */
   public class CallbackTest extends TestCase
   {
  @@ -55,7 +55,7 @@
   
         cache.put(FQN_A, null);
         assertTrue(cache.exists(FQN_A));
  -      assertTrue(cache.exists(FQN_B)); //created by callback
  +      assertTrue(cache.exists(FQN_B));//created by callback
         assertEquals(cache.getLockTable().size(), 0);
         System.out.println("cache locks:\n" + cache.printLockInfo());
         assertEquals(0, cache.getNumberOfLocksHeld());
  @@ -154,25 +154,23 @@
         assertEquals(0, tx_table2.getNumGlobalTransactions());
      }*/
   
  -/*   public static void main(String[] args) {
  +   /*   public static void main(String[] args) {
      try {
         new CallbackTest().testSyncReplicationWith2Caches();
      }
      catch(Exception e) {
         e.printStackTrace();
      }
  -}*/
  +   }*/
   
   
      CacheImpl createCache(Configuration.CacheMode mode, IsolationLevel level) throws Exception
      {
  -      CacheImpl c = new CacheImpl();
  -      c.getConfiguration().setCacheMode(mode);
  -      c.getConfiguration().setIsolationLevel(level);
  -      c.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
  -      c.create();
  -      c.start();
  -      return c;
  +      Configuration c = new Configuration();
  +      c.setCacheMode(mode);
  +      c.setIsolationLevel(level);
  +      c.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
  +      return (CacheImpl) DefaultCacheFactory.getInstance().createCache(c);
      }
   
      Transaction startTransaction()
  
  
  
  1.7       +2 -2      JBossCache/tests/functional/org/jboss/cache/LifeCycleTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: LifeCycleTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/LifeCycleTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- LifeCycleTest.java	30 Dec 2006 17:49:54 -0000	1.6
  +++ LifeCycleTest.java	11 Jan 2007 13:49:06 -0000	1.7
  @@ -16,7 +16,7 @@
    * Tests restart (stop-destroy-create-start) of CacheImpl
    *
    * @author Bela Ban
  - * @version $Id: LifeCycleTest.java,v 1.6 2006/12/30 17:49:54 msurtani Exp $
  + * @version $Id: LifeCycleTest.java,v 1.7 2007/01/11 13:49:06 msurtani Exp $
    */
   public class LifeCycleTest extends TestCase
   {
  @@ -103,7 +103,7 @@
   
      CacheImpl createCache(Configuration.CacheMode cache_mode) throws Exception
      {
  -      CacheImpl retval = new CacheImpl();
  +      CacheImpl retval = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
         retval.getConfiguration().setCacheMode(cache_mode);
         retval.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
         return retval;
  
  
  
  1.4       +76 -89    JBossCache/tests/functional/org/jboss/cache/CacheFactoryTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheFactoryTest.java
  ===================================================================
  RCS file: CacheFactoryTest.java
  diff -N CacheFactoryTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ CacheFactoryTest.java	11 Jan 2007 13:49:06 -0000	1.4
  @@ -0,0 +1,94 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +package org.jboss.cache;
  +
  +import junit.framework.TestCase;
  +import org.jboss.cache.config.Configuration;
  +import org.jboss.cache.factories.XmlConfigurationParser;
  +import org.jboss.cache.lock.IsolationLevel;
  +
  +/**
  + * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
  + */
  +public class CacheFactoryTest extends TestCase
  +{
  +   Configuration expected;
  +   String configFile = "META-INF/replSync-service.xml";
  +   private CacheImpl cache;
  +
  +   protected void setUp()
  +   {
  +      XmlConfigurationParser parser = new XmlConfigurationParser();
  +      expected = parser.parseFile(configFile);
  +   }
  +
  +   protected void tearDown()
  +   {
  +      if (cache != null)
  +      {
  +         cache.stop();
  +      }
  +   }
  +
  +   public void testFromConfigFileStarted()
  +   {
  +      cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(configFile);
  +      assertEquals(expected, cache.getConfiguration());
  +
  +      assertTrue("Should have started", cache.isStarted());
  +      doSimpleConfTests(cache.getConfiguration());
  +   }
  +
  +   public void testFromConfigFileUnstarted()
  +   {
  +      cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(configFile, false);
  +      assertEquals(expected, cache.getConfiguration());
  +
  +      assertFalse("Should not have started", cache.isStarted());
  +
  +      doSimpleConfTests(cache.getConfiguration());
  +   }
  +
  +   public void testFromConfigObjStarted()
  +   {
  +      cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(expected);
  +
  +      assertTrue("Should have started", cache.isStarted());
  +
  +      doSimpleConfTests(cache.getConfiguration());
  +   }
  +
  +   public void testFromConfigObjUnstarted()
  +   {
  +      cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(expected, false);
  +
  +      assertFalse("Should not have started", cache.isStarted());
  +
  +      doSimpleConfTests(cache.getConfiguration());
  +   }
  +
  +   private void doSimpleConfTests(Configuration tc)
  +   {
  +      assertEquals(Configuration.CacheMode.REPL_SYNC, tc.getCacheMode());
  +      assertEquals(10000, tc.getLockAcquisitionTimeout());
  +      assertEquals(IsolationLevel.REPEATABLE_READ, tc.getIsolationLevel());
  +      assertEquals(true, tc.isUseRegionBasedMarshalling());
  +      // test some of the XML content.
  +      assertEquals("UDP(ip_mcast=true;ip_ttl=64;loopback=false;mcast_addr=228.1.2.3;mcast_port=48866;mcast_recv_buf_size=80000;mcast_send_buf_size=150000;ucast_recv_buf_size=80000;ucast_send_buf_size=150000):PING(down_thread=false;num_initial_members=3;timeout=2000;up_thread=false):MERGE2(max_interval=20000;min_interval=10000):FD_SOCK:VERIFY_SUSPECT(down_thread=false;timeout=1500;up_thread=false):pbcast.NAKACK(down_thread=false;gc_lag=50;max_xmit_size=8192;retransmit_timeout=600,1200,2400,4800;up_thread=false):UNICAST(down_thread=false;min_threshold=10;timeout=600,1200,2400;window_size=100):pbcast.STABLE(desired_avg_gossip=20000;down_thread=false;up_thread=false):FRAG(down_thread=false;frag_size=8192;up_thread=false):pbcast.GMS(join_retry_timeout=2000;join_timeout=5000;print_local_addr=true;shun=true):pbcast.STATE_TRANSFER(down_thread=true;up_thread=true)", tc.getClusterConfig());
  +   }
  +
  +   public void testLifecycle() throws Exception
  +   {
  +      cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(expected, false);
  +      assertFalse(cache.isStarted());
  +      cache.start();
  +      assertTrue(cache.isStarted());
  +      cache.stop();
  +      assertFalse(cache.isStarted());
  +   }
  +
  +}
  
  
  



More information about the jboss-cvs-commits mailing list