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

Galder Zamarreno galder.zamarreno at jboss.com
Wed Nov 29 13:39:16 EST 2006


  User: gzamarreno
  Date: 06/11/29 13:39:16

  Added:       tests/functional/org/jboss/cache/marshall  Tag:
                        Branch_JBossCache_1_4_0
                        RedeploymentEmulationTest.java
  Log:
  How to use JBC marshalling to get around redeployment ClassCastExceptions. QA entry added explaining the problem and resolution as well as a unit test emulating redeployment.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +101 -0    JBossCache/tests/functional/org/jboss/cache/marshall/Attic/RedeploymentEmulationTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: RedeploymentEmulationTest.java
  ===================================================================
  RCS file: RedeploymentEmulationTest.java
  diff -N RedeploymentEmulationTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ RedeploymentEmulationTest.java	29 Nov 2006 18:39:16 -0000	1.1.2.1
  @@ -0,0 +1,101 @@
  +/*
  + * JBoss, the OpenSource J2EE webOS
  + * 
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +package org.jboss.cache.marshall;
  +
  +import junit.framework.TestCase;
  +import org.jboss.cache.TreeCache;
  +import org.jboss.cache.TreeCacheMBean;
  +import org.jgroups.Global;
  +
  +import java.net.URLClassLoader;
  +import java.net.URL;
  +import java.io.File;
  +
  +/**
  + * Unit test demonstrating usability of marshalling for application redeployment in application server.
  + *
  + * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
  + */
  +public class RedeploymentEmulationTest extends TestCase
  +{
  +   private TreeCacheMBean tcmb;
  +
  +   private static final String INSTANCE_LIBRARY = "jgroups.jar";
  +   private static final String INSTANCE_CLASS_NAME = "org.jgroups.Global";
  +   private static final String USER_DIR = System.getProperty("user.dir");
  +   private static final String FILE_SEPARATOR = System.getProperty("file.separator");
  +   private static final String LIB_DIR = "lib";
  +
  +   protected void setUp() throws Exception
  +   {
  +      TreeCache tc = new TreeCache();
  +      tc.setCacheMode(TreeCache.LOCAL);
  +      tc.setUseRegionBasedMarshalling(true);
  +      tcmb = tc;
  +   }
  +
  +   public void testClassCastException() throws Exception
  +   {
  +      tcmb.startService();
  +
  +      File f = new File(USER_DIR + FILE_SEPARATOR + LIB_DIR + FILE_SEPARATOR);
  +      URL context = f.toURL();
  +      URL jar= new URL(context, INSTANCE_LIBRARY);
  +      URLClassLoader ucl1 = new URLClassLoader(new URL[]{jar}, null);
  +      Thread.currentThread().setContextClassLoader(ucl1);
  +      
  +      Class clazz1 = ucl1.loadClass(INSTANCE_CLASS_NAME);
  +      tcmb.put("/a", "key", clazz1.newInstance());
  +
  +      Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
  +      try
  +      {
  +         Global object = (Global)tcmb.get("/a", "key");
  +         fail("Should have produced a ClassCastException");
  +      }
  +      catch(ClassCastException cce)
  +      {
  +         assertTrue(cce.getMessage().equals(INSTANCE_CLASS_NAME));
  +      }
  +   }
  +
  +   public void testRegisterUnregister() throws Exception
  +   {
  +      tcmb.startService();
  +
  +      File f = new File(USER_DIR + FILE_SEPARATOR + LIB_DIR + FILE_SEPARATOR);
  +      URL context = f.toURL();
  +      URL jar= new URL(context, INSTANCE_LIBRARY);
  +      URLClassLoader ucl1 = new URLClassLoader(new URL[]{jar}, null);
  +      Thread.currentThread().setContextClassLoader(ucl1);
  +
  +      tcmb.registerClassLoader("/", Thread.currentThread().getContextClassLoader());
  +      
  +      Class clazz1 = ucl1.loadClass(INSTANCE_CLASS_NAME);
  +      tcmb.put("/a", "key", clazz1.newInstance());
  +
  +      tcmb.inactivateRegion("/");
  +      tcmb.unregisterClassLoader("/");
  +
  +      Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
  +
  +      tcmb.registerClassLoader("/", Thread.currentThread().getContextClassLoader());
  +      
  +      try
  +      {
  +         Global object = (Global)tcmb.get("/a", "key");
  +         assertNull(object);
  +      }
  +      catch(ClassCastException cce)
  +      {
  +         fail("Should not have produced a ClassCastException");
  +      }
  +
  +      tcmb.inactivateRegion("/");
  +      tcmb.unregisterClassLoader("/");      
  +   }
  +}
  
  
  



More information about the jboss-cvs-commits mailing list