[jboss-cvs] JBossAS SVN: r69700 - in projects/aop/trunk/aop/src: test/org/jboss/test/aop/proxy and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 7 13:51:47 EST 2008


Author: kabir.khan at jboss.com
Date: 2008-02-07 13:51:47 -0500 (Thu, 07 Feb 2008)
New Revision: 69700

Added:
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/AnnotationImpl.java
Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyCacheKey.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/SerializeContainerProxyCacheKeyTestCase.java
Log:
[JBAOP-525] Should be possible to serialize a ContainerProxyCacheKey containing (unserializable) MetaData

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyCacheKey.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyCacheKey.java	2008-02-07 15:54:15 UTC (rev 69699)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyCacheKey.java	2008-02-07 18:51:47 UTC (rev 69700)
@@ -46,6 +46,8 @@
    private WeakReference<Class>[] addedInterfaces = EMTPY_WR_ARRAY;
    
    private MetaData metaData;
+   /** In case we are serializing with an unserializable MetaData in the same JVM, give a chance to make sure that the metaData is the same */
+   private long metaDataIdentityHashCode; 
    
    private AOPProxyFactoryMixin[] addedMixins = EMPTY_MIXIN_ARRAY;
    private int hashcode = 0;
@@ -197,21 +199,42 @@
    
    private boolean compareMetadataContext(ContainerProxyCacheKey other)
    {
-      if (this.metaData == null && other.metaData == null)
+      if (this.metaData == null && this.metaDataIdentityHashCode == 0 && other.metaData == null && other.metaDataIdentityHashCode == 0)
       {
+         return true;
       }
-      else if ((this.metaData != null && other.metaData != null))
+      
+      if (this.metaData != null && other.metaData != null)
       {
-         if (!this.metaData.equals(other.metaData))
+         return this.metaData.equals(other.metaData);
+      }
+      
+      if (this.metaDataIdentityHashCode != 0 && other.metaDataIdentityHashCode != 0)
+      {
+         return this.metaDataIdentityHashCode == other.metaDataIdentityHashCode;
+      }
+      
+      if (this.metaData != null && other.metaData == null && other.metaDataIdentityHashCode != 0)
+      {
+         long oneHashCode = System.identityHashCode(this.metaData);
+         if (oneHashCode == other.metaDataIdentityHashCode)
          {
-            return false;
+            other.metaData = this.metaData;
+            return true;
          }
       }
-      else
+      
+      if (other.metaData != null && this.metaData == null && this.metaDataIdentityHashCode != 0)
       {
-         return false;
+         long twoHashCode = System.identityHashCode(other.metaData);
+         if (twoHashCode == this.metaDataIdentityHashCode)
+         {
+            this.metaData = other.metaData;
+            return true;
+         }
       }
-      return true;
+      
+      return false;
    }
    
    private boolean compareClass(ContainerProxyCacheKey other)
@@ -266,7 +289,16 @@
           }
        }
        out.writeObject(ifs);
-       out.writeObject(metaData);
+       if (metaData instanceof Serializable)
+       {
+          out.writeObject(metaData);   
+       }
+       else
+       {
+          out.writeObject(null);
+       }
+       out.writeLong(System.identityHashCode(metaData));
+       
        out.writeObject(addedMixins);
        out.writeInt(hashCode());
     }
@@ -286,6 +318,7 @@
           }
        }
        metaData = (MetaData)in.readObject();
+       metaDataIdentityHashCode = in.readLong();
        addedMixins = (AOPProxyFactoryMixin[])in.readObject();
        hashcode = in.readInt();
     }

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/AnnotationImpl.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/AnnotationImpl.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/AnnotationImpl.java	2008-02-07 18:51:47 UTC (rev 69700)
@@ -0,0 +1,36 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.aop.proxy;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class AnnotationImpl implements Annotation
+{
+   public Class<? extends java.lang.annotation.Annotation> annotationType()
+   {
+      return Annotation.class;
+   }
+
+}

Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/SerializeContainerProxyCacheKeyTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/SerializeContainerProxyCacheKeyTestCase.java	2008-02-07 15:54:15 UTC (rev 69699)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/SerializeContainerProxyCacheKeyTestCase.java	2008-02-07 18:51:47 UTC (rev 69700)
@@ -23,12 +23,21 @@
 
 import java.io.Externalizable;
 import java.rmi.MarshalledObject;
+import java.util.ArrayList;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
 import org.jboss.aop.proxy.container.AOPProxyFactoryMixin;
 import org.jboss.aop.proxy.container.ContainerProxyCacheKey;
+import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
+import org.jboss.metadata.plugins.repository.basic.BasicMetaDataRepository;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.MutableMetaData;
+import org.jboss.metadata.spi.repository.MutableMetaDataRepository;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.Scope;
+import org.jboss.metadata.spi.scope.ScopeKey;
 import org.jboss.test.aop.AOPTestWithSetup;
 
 /**
@@ -53,7 +62,7 @@
    }
 
    
-   public void testSerializeKey() throws Exception
+   public void testSerializeKeyNoMetaData() throws Exception
    {
       ContainerProxyCacheKey original1 = new ContainerProxyCacheKey(
             "/", 
@@ -69,7 +78,7 @@
             getMixins(),
             null);
       
-      assertNotSame(original1, original2);
+      assertFalse(original1.equals(original2));
       
       MarshalledObject mo1 = new MarshalledObject(original1);
       MarshalledObject mo2 = new MarshalledObject(original2);
@@ -78,9 +87,88 @@
       ContainerProxyCacheKey deserialized2 = (ContainerProxyCacheKey)mo2.get();
       
       assertEquals(original1, deserialized1);
+      assertEquals(deserialized1, original1);
       assertEquals(original2, deserialized2);
+      assertEquals(deserialized2, original2);
+      assertFalse(deserialized1.equals(deserialized2));
+   }
+   
+   public void testEqualsMetaDataNotSerialized()
+   {
+      MetaData md = getMetaData("A", "testEqualsMetaDataNotSerialized");
+
+      ContainerProxyCacheKey original1 = new ContainerProxyCacheKey(
+            "/", 
+            SerializeContainerProxyCacheKeyTestCase.class, 
+            new Class[] {Externalizable.class, SomeInterface.class}, 
+            getMixins(),
+            md);
+
+      ContainerProxyCacheKey original2 = new ContainerProxyCacheKey(
+            "/", 
+            SerializeContainerProxyCacheKeyTestCase.class, 
+            new Class[] {Externalizable.class, SomeInterface.class}, 
+            getMixins(),
+            md);
       
+      assertEquals(original1, original2);
+      assertEquals(original2, original1);
+      
+      ContainerProxyCacheKey original3 = new ContainerProxyCacheKey(
+            "/", 
+            SerializeContainerProxyCacheKeyTestCase.class, 
+            new Class[] {Externalizable.class, SomeInterface.class}, 
+            getMixins(),
+            null);
+
+      assertFalse(original1.equals(original3));
+      
+      MetaData md2 = getMetaData("A", "testEqualsMetaDataNotSerialized2");
+      ContainerProxyCacheKey original4 = new ContainerProxyCacheKey(
+            "/", 
+            SerializeContainerProxyCacheKeyTestCase.class, 
+            new Class[] {Externalizable.class, SomeInterface.class}, 
+            getMixins(),
+            md2);
+      
+      assertFalse(original1.equals(original4));
    }
+   
+   public void testSerializeKeyWithMetaData() throws Exception
+   {
+      MetaData md = getMetaData("A", "testSerializeKeyWithMetaData");
+      ContainerProxyCacheKey original1 = new ContainerProxyCacheKey(
+            "/", 
+            SerializeContainerProxyCacheKeyTestCase.class, 
+            new Class[] {Externalizable.class, SomeInterface.class}, 
+            getMixins(),
+            md);
+      
+      MarshalledObject mo1 = new MarshalledObject(original1);
+      
+      ContainerProxyCacheKey deserialized1 = (ContainerProxyCacheKey)mo1.get();
+      
+      assertEquals(original1, deserialized1);
+      assertEquals(deserialized1, original1);
+   }
+   
+   private MetaData getMetaData(String app, String instance)
+   {
+      MutableMetaDataRepository repository = new BasicMetaDataRepository();
+      ArrayList<Scope> scopes = new ArrayList<Scope>();
+      scopes.add(new Scope(CommonLevels.APPLICATION, app));
+      scopes.add(new Scope(CommonLevels.INSTANCE, instance));
+      ScopeKey scopeKey = new ScopeKey(scopes);
+      
+      MemoryMetaDataLoader loader = new MemoryMetaDataLoader(scopeKey);
+      repository.addMetaDataRetrieval(loader);
+      
+      ((MutableMetaData)loader).addAnnotation(new AnnotationImpl());
+      
+      MetaData md = repository.getMetaData(scopeKey);
+      
+      return md;
+   }
 
    private AOPProxyFactoryMixin[] getMixins()
    {




More information about the jboss-cvs-commits mailing list