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

Brian Stansberry brian.stansberry at jboss.com
Mon Dec 4 17:18:54 EST 2006


  User: bstansberry
  Date: 06/12/04 17:18:54

  Modified:    tests/functional/org/jboss/cache/marshall   Tag:
                        Branch_JBossCache_1_4_0 SyncReplTest.java
                        AsyncReplTest.java
  Log:
  [JBCACHE-876] Add tests that custom classes in Fqn's work properly
  Be more specific about the usage of classloader in testPuts()
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.5.2.1   +58 -8     JBossCache/tests/functional/org/jboss/cache/marshall/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/marshall/SyncReplTest.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -b -r1.5 -r1.5.2.1
  --- SyncReplTest.java	5 May 2006 12:06:58 -0000	1.5
  +++ SyncReplTest.java	4 Dec 2006 22:18:54 -0000	1.5.2.1
  @@ -12,6 +12,8 @@
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  +
  +import org.jboss.cache.Fqn;
   import org.jboss.cache.PropertyConfigurator;
   import org.jboss.cache.TreeCache;
   import org.jboss.cache.misc.TestingUtil;
  @@ -27,7 +29,7 @@
    * Test case for marshalling using Sync mode.
    * @author Ben Wang
    *
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.5.2.1 $
    */
   public class SyncReplTest extends TestCase {
      TreeCache cache1, cache2;
  @@ -65,7 +67,7 @@
         config.configure(tree, "META-INF/replSync-service.xml"); // read in generic replAsync xml
         tree.setClusterName(name);
         // Use marshaller
  -      tree.setUseMarshalling(true);
  +      tree.setUseRegionBasedMarshalling(true);
         tree.createService();
         tree.startService();
         return tree;
  @@ -207,17 +209,33 @@
      {
         ClassLoader cl = getClassLoader();
         cache1.registerClassLoader("/aop", cl);
  +      // Create an empty Person loaded by this classloader
  +      Object scopedBen1 = getPersonFromClassloader(cl);
  +      
         cl = getClassLoader();
         cache2.registerClassLoader("/aop", cl);
  +      // Create another empty Person loaded by this classloader
  +      Object scopedBen2 = getPersonFromClassloader(cl);
   
         cache1.put("/aop/1", "person", ben_);
  -      cache1.put("/aop/1", "person", ben_);
  +      cache1.put("/aop/2", "person", scopedBen1);
   
         Object ben2 = null;
  +      try
  +      {
         // Can't cast it to Person. CCE will resutl.
         ben2 = cache2.get("/aop/1", "person");
         assertEquals(ben_.toString(), ben2.toString());
   
  +         ben2 = cache2.get("/aop/2", "person");
  +         assertFalse("cache2 deserialized with scoped classloader", ben2 instanceof Person);
  +         assertFalse("cache2 deserialized with cache2 classloader", scopedBen1.equals(ben2));
  +         assertEquals("scopedBen deserialized properly", scopedBen2, ben2);
  +      } catch (Exception ex)
  +      {
  +         fail("Test fails with exception " +ex);
  +      }
  +
      }
   
      public void testMethodCall() throws Exception
  @@ -326,6 +344,32 @@
         // Need to test out if app is not registered with beforehand??
      }
   
  +   public void testCustomFqn() throws Exception
  +   {
  +      FooClassLoader cl1 = new FooClassLoader(Thread.currentThread().getContextClassLoader());
  +      cache1.registerClassLoader("/aop", cl1);
  +      FooClassLoader cl2 = new FooClassLoader(Thread.currentThread().getContextClassLoader());
  +      cache2.registerClassLoader("/aop", cl2); 
  +      
  +      Class clazz = cl1.loadFoo();
  +      Object custom1 = clazz.newInstance();
  +
  +      clazz = cl2.loadFoo();
  +      Object custom2 = clazz.newInstance();
  +      
  +      Fqn base = Fqn.fromString("/aop");
  +      cache1.put(new Fqn(base, custom1), "key", "value");
  +
  +      try
  +      {
  +         Object val = cache2.get(new Fqn(base, custom2), "key");
  +         assertEquals("value", val);
  +      } catch (Exception ex)
  +      {
  +         fail("Test fails with exception " +ex);
  +      }      
  +   }
  +
      Transaction beginTransaction() throws SystemException, NotSupportedException {
         DummyTransactionManager mgr=DummyTransactionManager.getInstance();
         mgr.begin();
  @@ -341,6 +385,12 @@
         return new SelectedClassnameClassLoader(includesClasses, excludesClasses, cl);
      }
   
  +   protected Object getPersonFromClassloader(ClassLoader cl) throws Exception
  +   {
  +      Class clazz = cl.loadClass("org.jboss.cache.marshall.Person");
  +      return clazz.newInstance();
  +   }
  +
      void log(String msg) {
         System.out.println("-- [" + Thread.currentThread() + "]: " + msg);
      }
  
  
  
  1.5.2.1   +50 -5     JBossCache/tests/functional/org/jboss/cache/marshall/AsyncReplTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AsyncReplTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/marshall/AsyncReplTest.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -b -r1.5 -r1.5.2.1
  --- AsyncReplTest.java	8 Jun 2006 00:41:14 -0000	1.5
  +++ AsyncReplTest.java	4 Dec 2006 22:18:54 -0000	1.5.2.1
  @@ -12,6 +12,8 @@
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  +
  +import org.jboss.cache.Fqn;
   import org.jboss.cache.PropertyConfigurator;
   import org.jboss.cache.TreeCache;
   import org.jboss.cache.misc.TestingUtil;
  @@ -26,7 +28,7 @@
   /**
    * Test marshalling for async mode.
    * @author Ben Wang
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.5.2.1 $
    */
   public class AsyncReplTest extends TestCase {
      TreeCache cache1, cache2;
  @@ -65,7 +67,7 @@
         config.configure(tree, "META-INF/replAsync-service.xml"); // read in generic replAsync xml
         tree.setClusterName(name);
         // Use marshaller
  -      tree.setUseMarshalling(true);
  +      tree.setUseRegionBasedMarshalling(true);
         tree.createService();
         tree.startService();
         return tree;
  @@ -150,11 +152,16 @@
      {
         ClassLoader cl = getClassLoader();
         cache1.registerClassLoader("/aop", cl);
  +      // Create an empty Person loaded by this classloader
  +      Object scopedBen1 = getPersonFromClassloader(cl);
  +      
         cl = getClassLoader();
         cache2.registerClassLoader("/aop", cl);
  +      // Create another empty Person loaded by this classloader
  +      Object scopedBen2 = getPersonFromClassloader(cl);
   
         cache1.put("/aop/1", "person", ben_);
  -      cache1.put("/aop/1", "person", ben_);
  +      cache1.put("/aop/2", "person", scopedBen1);
         TestingUtil.sleepThread(1000);
   
         Object ben2 = null;
  @@ -163,6 +170,11 @@
            // Can't cast it to Person. CCE will resutl.
            ben2 = cache2.get("/aop/1", "person");
            assertEquals(ben_.toString(), ben2.toString());
  +         
  +         ben2 = cache2.get("/aop/2", "person");
  +         assertFalse("cache2 deserialized with scoped classloader", ben2 instanceof Person);
  +         assertFalse("cache2 deserialized with cache2 classloader", scopedBen1.equals(ben2));
  +         assertEquals("scopedBen deserialized properly", scopedBen2, ben2);
         } catch (Exception ex)
         {
            fail("Test fails with exception " +ex);
  @@ -242,6 +254,33 @@
         // Need to test out if app is not registered with beforehand??
      }
   
  +   public void testCustomFqn() throws Exception
  +   {
  +      FooClassLoader cl1 = new FooClassLoader(Thread.currentThread().getContextClassLoader());
  +      cache1.registerClassLoader("/aop", cl1);
  +      FooClassLoader cl2 = new FooClassLoader(Thread.currentThread().getContextClassLoader());
  +      cache2.registerClassLoader("/aop", cl2); 
  +      
  +      Class clazz = cl1.loadFoo();
  +      Object custom1 = clazz.newInstance();
  +
  +      clazz = cl2.loadFoo();
  +      Object custom2 = clazz.newInstance();
  +      
  +      Fqn base = Fqn.fromString("/aop");
  +      cache1.put(new Fqn(base, custom1), "key", "value");
  +      TestingUtil.sleepThread(1000);
  +
  +      try
  +      {
  +         Object val = cache2.get(new Fqn(base, custom2), "key");
  +         assertEquals("value", val);
  +      } catch (Exception ex)
  +      {
  +         fail("Test fails with exception " +ex);
  +      }      
  +   }
  +
      Transaction beginTransaction() throws SystemException, NotSupportedException {
         DummyTransactionManager mgr=DummyTransactionManager.getInstance();
         mgr.begin();
  @@ -257,6 +296,12 @@
         return new SelectedClassnameClassLoader(includesClasses, excludesClasses, cl);
      }
   
  +   protected Object getPersonFromClassloader(ClassLoader cl) throws Exception
  +   {
  +      Class clazz = cl.loadClass("org.jboss.cache.marshall.Person");
  +      return clazz.newInstance();
  +   }
  +
      void log(String msg) {
         System.out.println("-- [" + Thread.currentThread() + "]: " + msg);
      }
  
  
  



More information about the jboss-cvs-commits mailing list