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

Manik Surtani msurtani at belmont.prod.atl2.jboss.com
Tue Aug 29 13:50:14 EDT 2006


  User: msurtani
  Date: 06/08/29 13:50:14

  Modified:    tests/functional/org/jboss/cache/replicated  
                        SyncCacheListenerTest.java SyncReplTest.java
  Log:
  Fixed RPCManager scoping issues
  
  Revision  Changes    Path
  1.10      +125 -88   JBossCache/tests/functional/org/jboss/cache/replicated/SyncCacheListenerTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SyncCacheListenerTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/replicated/SyncCacheListenerTest.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -r1.9 -r1.10
  --- SyncCacheListenerTest.java	16 Aug 2006 10:52:52 -0000	1.9
  +++ SyncCacheListenerTest.java	29 Aug 2006 17:50:14 -0000	1.10
  @@ -32,13 +32,14 @@
   /**
    * Test out the TreeCacheListener
    *
  - * @version $Revision: 1.9 $
  + * @version $Revision: 1.10 $
    */
  -public class SyncCacheListenerTest extends TestCase {
  +public class SyncCacheListenerTest extends TestCase
  +{
      TreeCache cache1, cache2;
  -   Configuration.CacheMode caching_mode= Configuration.CacheMode.REPL_SYNC;
  -   final String group_name="TreeCacheTestGroup";
  -   String props=
  +   Configuration.CacheMode caching_mode = Configuration.CacheMode.REPL_SYNC;
  +   final String group_name = "TreeCacheTestGroup";
  +   String props =
            "UDP(ip_mcast=true;ip_ttl=64;loopback=false;mcast_addr=228.1.2.3;" +
            "mcast_port=45566;mcast_recv_buf_size=80000;mcast_send_buf_size=150000;" +
            "ucast_recv_buf_size=80000;ucast_send_buf_size=150000):" +
  @@ -54,48 +55,58 @@
            "pbcast.GMS(join_retry_timeout=2000;join_timeout=5000;print_local_addr=true;shun=true):" +
            "pbcast.STATE_TRANSFER(down_thread=true;up_thread=true)";
   
  -   final static Log log_=LogFactory.getLog(SyncCacheListenerTest.class);
  -   String old_factory=null;
  -   final String FACTORY="org.jboss.cache.transaction.DummyContextFactory";
  -   FIFOSemaphore lock=new FIFOSemaphore(1);
  +   final static Log log_ = LogFactory.getLog(SyncCacheListenerTest.class);
  +   String old_factory = null;
  +   final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
  +   FIFOSemaphore lock = new FIFOSemaphore(1);
      DummyTransactionManager tx_mgr;
  -   Throwable t1_ex, t2_ex, ex=null;
  +   Throwable t1_ex, t2_ex, ex = null;
   
   
  -
  -   public SyncCacheListenerTest(String name) {
  +   public SyncCacheListenerTest(String name)
  +   {
         super(name);
      }
   
  -   public void setUp() throws Exception {
  +   protected void setUp() throws Exception
  +   {
  +      System.out.println("*** starting setUp()");
         super.setUp();
  -      old_factory=System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
  +      old_factory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
         System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
  -      tx_mgr=DummyTransactionManager.getInstance();
  -      t1_ex=t2_ex=ex=null;
  +      tx_mgr = DummyTransactionManager.getInstance();
  +      t1_ex = t2_ex = ex = null;
  +      lock = new FIFOSemaphore(1);
  +      System.out.println("*** finished setUp()");
      }
   
  -   public void tearDown() throws Exception {
  +   protected void tearDown() throws Exception
  +   {
  +      System.out.println("*** starting tearDown()");
         super.tearDown();
         DummyTransactionManager.destroy();
         destroyCaches();
  -      if(old_factory != null) {
  +      if (old_factory != null)
  +      {
            System.setProperty(Context.INITIAL_CONTEXT_FACTORY, old_factory);
  -         old_factory=null;
  +         old_factory = null;
         }
  +      System.out.println("*** finished tearDown()");
      }
   
  -   Transaction beginTransaction() throws SystemException, NotSupportedException {
  -      DummyTransactionManager mgr=DummyTransactionManager.getInstance();
  +   Transaction beginTransaction() throws SystemException, NotSupportedException
  +   {
  +      DummyTransactionManager mgr = DummyTransactionManager.getInstance();
         mgr.begin();
  -      Transaction tx=mgr.getTransaction();
  +      Transaction tx = mgr.getTransaction();
         return tx;
      }
   
  -   void initCaches(Configuration.CacheMode caching_mode) throws Exception {
  -      this.caching_mode=caching_mode;
  -      cache1=new TreeCache();
  -      cache2=new TreeCache();
  +   void initCaches(Configuration.CacheMode caching_mode) throws Exception
  +   {
  +      this.caching_mode = caching_mode;
  +      cache1 = new TreeCache();
  +      cache2 = new TreeCache();
         cache1.getConfiguration().setCacheMode(caching_mode);
         cache2.getConfiguration().setCacheMode(caching_mode);
         cache1.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
  @@ -113,23 +124,30 @@
         cache2.start();
      }
   
  -   void destroyCaches() throws Exception {
  -      if(cache1 != null)
  +   void destroyCaches() throws Exception
  +   {
  +      if (cache1 != null)
  +      {
            cache1.stop();
  -      if(cache2 != null)
  +      }
  +      if (cache2 != null)
  +      {
            cache2.stop();
  -      cache1=null;
  -      cache2=null;
  +      }
  +      cache1 = null;
  +      cache2 = null;
      }
   
  -   public void testSyncTxRepl() throws Exception {
  +   public void testSyncTxRepl() throws Exception
  +   {
         Integer age;
         Transaction tx;
   
  -      try {
  +      try
  +      {
            initCaches(Configuration.CacheMode.REPL_SYNC);
   
  -         tx=beginTransaction();
  +         tx = beginTransaction();
            Listener lis = new Listener();
            cache1.getNotifier().addCacheListener(lis);
            lis.put("/a/b/c", "age", new Integer(38));
  @@ -137,38 +155,44 @@
            tx.commit();
   
            // value on cache2 must be 38
  -         age=(Integer)cache2.get("/a/b/c", "age");
  +         age = (Integer) cache2.get("/a/b/c", "age");
            assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
            assertTrue("\"age\" must be 38", age.intValue() == 38);
         }
  -      catch(Exception e) {
  +      catch (Exception e)
  +      {
            fail(e.toString());
         }
      }
   
  -   public void testRemoteCacheListener() throws Exception {
  +   public void testRemoteCacheListener() throws Exception
  +   {
         Integer age;
  -      try {
  +      try
  +      {
            initCaches(Configuration.CacheMode.REPL_SYNC);
            RemoteListener lis = new RemoteListener();
            cache2.getNotifier().addCacheListener(lis);
            cache1.put("/a/b/c", "age", new Integer(38));
   
            // value on cache2 must be 38
  -         age=(Integer)cache2.get("/a/b/c", "age");
  +         age = (Integer) cache2.get("/a/b/c", "age");
            assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
            assertTrue("\"age\" must be 38", age.intValue() == 38);
   	 cache1.remove("/a/b/c", "age");
         }
  -      catch(Exception e) {
  +      catch (Exception e)
  +      {
            fail(e.toString());
         }
      }
   
   
  -   public void testSyncRepl() throws Exception {
  +   public void testSyncRepl() throws Exception
  +   {
         Integer age;
  -      try {
  +      try
  +      {
            initCaches(Configuration.CacheMode.REPL_SYNC);
   
            Listener lis = new Listener();
  @@ -176,23 +200,26 @@
            lis.put("/a/b/c", "age", new Integer(38));
   
            // value on cache2 must be 38
  -         age=(Integer)cache2.get("/a/b/c", "age");
  +         age = (Integer) cache2.get("/a/b/c", "age");
            assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
            assertTrue("\"age\" must be 38", age.intValue() == 38);
         }
  -      catch(Exception e) {
  +      catch (Exception e)
  +      {
            fail(e.toString());
         }
      }
   
  -   public void testSyncTxReplMap() throws Exception {
  +   public void testSyncTxReplMap() throws Exception
  +   {
         Integer age;
         Transaction tx;
   
  -      try {
  +      try
  +      {
            initCaches(Configuration.CacheMode.REPL_SYNC);
   
  -         tx=beginTransaction();
  +         tx = beginTransaction();
            Listener lis = new Listener();
            cache1.getNotifier().addCacheListener(lis);
            Map map = new HashMap();
  @@ -203,19 +230,22 @@
            tx.commit();
   
            // value on cache2 must be 38
  -         age=(Integer)cache2.get("/a/b/c", "age");
  +         age = (Integer) cache2.get("/a/b/c", "age");
            assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
            assertTrue("\"age\" must be 38", age.intValue() == 38);
         }
  -      catch(Exception e) {
  +      catch (Exception e)
  +      {
            fail(e.toString());
         }
      }
   
   
  -   public void testSyncReplMap() throws Exception {
  +   public void testSyncReplMap() throws Exception
  +   {
         Integer age;
  -      try {
  +      try
  +      {
            initCaches(Configuration.CacheMode.REPL_SYNC);
   
            Listener lis = new Listener();
  @@ -226,11 +256,12 @@
            lis.put("/a/b/c", map);
   
            // value on cache2 must be 38
  -         age=(Integer)cache2.get("/a/b/c", "age");
  +         age = (Integer) cache2.get("/a/b/c", "age");
            assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
            assertTrue("\"age\" must be 38", age.intValue() == 38);
         }
  -      catch(Exception e) {
  +      catch (Exception e)
  +      {
            fail(e.toString());
         }
      }
  @@ -239,6 +270,7 @@
      class Listener extends AbstractCacheListener
      {
         Object key_ = null;
  +
         public void put(String fqn, Object key, Object val) throws Exception
         {
            key_ = key;
  @@ -247,7 +279,7 @@
   
         public void put(String fqn, Map map) throws Exception
         {
  -         if(map.size() == 0) fail("put(): map size can't be 0");
  +         if (map.size() == 0) fail("put(): map size can't be 0");
            Set set = map.keySet();
            key_ = set.iterator().next(); // take anyone
            cache1.put(fqn, map);
  @@ -256,14 +288,18 @@
   
         public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, Map data)
         {
  -          if (!pre) {
  -         log_.debug("nodeModified visited with fqn: " +fqn);
  -         try {
  +         if (!pre)
  +         {
  +            log_.debug("nodeModified visited with fqn: " + fqn);
  +            try
  +            {
               // test out if we can get the read lock since there is a write lock going as well.
               cache1.get(fqn, key_);
  -         } catch (CacheException e) {
  +            }
  +            catch (CacheException e)
  +            {
               e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
  -            fail("nodeModified: test failed with exception: " +e);
  +               fail("nodeModified: test failed with exception: " + e);
            }
             }
         }
  @@ -275,21 +311,22 @@
   
         public void nodeRemoved(Fqn fqn, boolean isPre, boolean isLocal, Map data)
         {
  -System.out.println("nodeRemove visited with fqn: " +fqn + ", isPre: "+ isPre + ", isLocal "+isLocal);
  -         log_.debug("nodeRemove visited with fqn: " +fqn + ", isPre: "+ isPre + ", isLocal "+isLocal);
  +         System.out.println("nodeRemove visited with fqn: " + fqn + ", isPre: " + isPre + ", isLocal " + isLocal);
  +         log_.debug("nodeRemove visited with fqn: " + fqn + ", isPre: " + isPre + ", isLocal " + isLocal);
   	 assertFalse("node was removed on remote cache so isLocal should be false", isLocal);
         }
   
         public void nodeModified(Fqn fqn, boolean isPre, boolean isLocal, Map data)
         {
  -System.out.println("nodeModify visited with fqn: " +fqn + ", isPre: "+ isPre + ", isLocal "+isLocal);
  -         log_.debug("nodeModify visited with fqn: " +fqn + ", isPre: "+ isPre + ", isLocal "+isLocal);
  +         System.out.println("nodeModify visited with fqn: " + fqn + ", isPre: " + isPre + ", isLocal " + isLocal);
  +         log_.debug("nodeModify visited with fqn: " + fqn + ", isPre: " + isPre + ", isLocal " + isLocal);
   	 assertFalse("node was modified on remote cache so isLocal should be false", isLocal);
         }
   
      }
   
  -    public static Test suite() throws Exception {
  +   public static Test suite() throws Exception
  +   {
   //        return getDeploySetup(SyncTxUnitTestCase.class, "cachetest.jar");
          return new TestSuite(SyncCacheListenerTest.class);
       }
  
  
  
  1.2       +35 -7     JBossCache/tests/functional/org/jboss/cache/replicated/SyncReplTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SyncReplTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/replicated/SyncReplTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- SyncReplTest.java	29 Aug 2006 16:35:52 -0000	1.1
  +++ SyncReplTest.java	29 Aug 2006 17:50:14 -0000	1.2
  @@ -8,9 +8,12 @@
   
   import junit.framework.TestCase;
   import org.jboss.cache.Cache;
  +import org.jboss.cache.CacheSPI;
   import org.jboss.cache.Fqn;
  +import org.jboss.cache.InvocationContext;
   import org.jboss.cache.Node;
   import org.jboss.cache.TreeCacheProxyImpl;
  +import org.jboss.cache.config.Option;
   import org.jboss.cache.factories.DefaultCacheFactory;
   import org.jboss.cache.misc.TestingUtil;
   
  @@ -50,6 +53,7 @@
      public void testBasicOperation()
      {
         assertClusterSize("Should only be 2  caches in the cluster!!!", 2);
  +      assertInvocationContextInitState();
   
         Fqn f = Fqn.fromString("/test/data");
         String k = "key", v = "value";
  @@ -71,19 +75,16 @@
      public void testSyncRepl()
      {
         assertClusterSize("Should only be 2  caches in the cluster!!!", 2);
  +      assertInvocationContextInitState();
   
         Fqn fqn = Fqn.fromString("/JSESSIONID/1010.10.5:3000/1234567890/1");
  -      Integer age;
         caches[0].getConfiguration().setSyncCommitPhase(true);
         caches[1].getConfiguration().setSyncCommitPhase(true);
   
   
  -      caches[0].put(fqn, "age", new Integer(38));
  -
  -      // value on cache2 must be 38
  -      age = (Integer) caches[1].get(fqn, "age");
  -      assertNotNull("\"age\" obtained from caches[1] is null ", age);
  -      assertTrue("\"age\" must be 38", age.intValue() == 38);
  +      caches[0].put(fqn, "age", 38);
  +      assertEquals("Value should be set", 38, caches[0].get(fqn, "age"));
  +      assertEquals("Value should have replicated", 38, caches[1].get(fqn, "age"));
      }
   
   
  @@ -100,5 +101,32 @@
         assertEquals(message, size, tcpi.treeCache.getMembers().size());
      }
   
  +   private void assertInvocationContextInitState()
  +   {
  +      for (Cache c : caches)
  +      {
  +         assertInvocationContextInitState(c);
  +      }
  +   }
  +
  +   private void assertInvocationContextInitState(Cache c)
  +   {
  +      InvocationContext ctx = ((CacheSPI) c).getInvocationContext();
  +      InvocationContext control = null;
  +      try
  +      {
  +         control = ctx.clone();
  +      }
  +      catch (CloneNotSupportedException e)
  +      {
  +         fail("Unable to clone InvocationCOntext");
  +      }
  +
  +      control.reset();
  +      control.setOptionOverrides(new Option());
  +
  +      assertEquals("Should be equal", control, ctx);
  +   }
  +
   
   }
  
  
  



More information about the jboss-cvs-commits mailing list