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

Manik Surtani msurtani at belmont.prod.atl2.jboss.com
Wed Aug 30 07:30:46 EDT 2006


  User: msurtani
  Date: 06/08/30 07:30:46

  Modified:    tests/functional/org/jboss/cache/marshall    Tag:
                        Branch_JBossCache_1_4_0
                        VersionAwareMarshallerTest.java
  Added:       tests/functional/org/jboss/cache/marshall    Tag:
                        Branch_JBossCache_1_4_0
                        BaseTreeCacheMarshallerTest.java
                        TreeCacheMarshaller140Test.java
  Log:
  Added unit tests for JBCACHE-755 and JBCACHE-756
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.3.2.1   +61 -142   JBossCache/tests/functional/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: VersionAwareMarshallerTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/marshall/VersionAwareMarshallerTest.java,v
  retrieving revision 1.3
  retrieving revision 1.3.2.1
  diff -u -b -r1.3 -r1.3.2.1
  --- VersionAwareMarshallerTest.java	8 Jun 2006 19:09:28 -0000	1.3
  +++ VersionAwareMarshallerTest.java	30 Aug 2006 11:30:46 -0000	1.3.2.1
  @@ -7,17 +7,11 @@
   package org.jboss.cache.marshall;
   
   import junit.framework.TestCase;
  -import org.jboss.cache.Fqn;
   import org.jboss.cache.Version;
  -import org.jgroups.blocks.MethodCall;
   
  -import java.util.Arrays;
  -import java.util.List;
  -import java.io.ObjectInputStream;
   import java.io.ByteArrayInputStream;
   import java.io.IOException;
  -import java.io.ObjectOutputStream;
  -import java.io.ByteArrayOutputStream;
  +import java.io.ObjectInputStream;
   
   /**
    * Tests the enhanced treecache marshaller
  @@ -26,63 +20,9 @@
    */
   public class VersionAwareMarshallerTest extends TestCase
   {
  -    public void testStringBasedFqn() throws Exception
  -    {
  -        VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, Version.getVersionString(Version.getVersionShort()));
  -        Fqn fqn = new Fqn(new Object[]{"JSESSIONID", "1010.10.5:3000", "1234567890", "1"});
  -        byte[] asBytes = marshaller.objectToByteBuffer(fqn);
  -        System.out.println("Marshalled to " + asBytes.length + " bytes");
  -        Object o2 = marshaller.objectFromByteBuffer(asBytes);
  -        assertEquals(fqn, o2);
  -    }
  -
  -    public void testNonStringBasedFqn() throws Exception
  -    {
  -        VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, Version.getVersionString(Version.getVersionShort()));
  -        Fqn fqn = new Fqn(new Object[]{new Integer(3), Boolean.FALSE});
  -        byte[] asBytes = marshaller.objectToByteBuffer(fqn);
  -        Object o2 = marshaller.objectFromByteBuffer(asBytes);
  -        assertEquals(fqn, o2);
  -    }
  -
  -    public void testMethodCall() throws Exception
  -    {
  -        VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, Version.getVersionString(Version.getVersionShort()));
  -        Fqn fqn = new Fqn(new Object[]{new Integer(3), Boolean.FALSE});
  -        MethodCall call = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, new Object[]{fqn, "key", "value"});
  -        byte[] asBytes = marshaller.objectToByteBuffer(call);
  -        Object o2 = marshaller.objectFromByteBuffer(asBytes);
  -        assertTrue("Unmarshalled object should be a method call", o2 instanceof JBCMethodCall);
  -        MethodCall m2 = (MethodCall) o2;
  -        assertEquals(call.getMethod(), m2.getMethod());
  -        List l1 = Arrays.asList(call.getArgs());
  -        List l2 = Arrays.asList(m2.getArgs());
  -        assertEquals(l1, l2);
  -    }
  -
  -    public void testNestedMethodCall() throws Exception
  -    {
  -        VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, Version.getVersionString(Version.getVersionShort()));
  -        Fqn fqn = new Fqn(new Object[]{new Integer(3), Boolean.FALSE});
  -        MethodCall call = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, new Object[]{fqn, "key", "value"});
  -        MethodCall replicateCall = MethodCallFactory.create(MethodDeclarations.replicateMethod, new Object[]{call});
  -        byte[] asBytes = marshaller.objectToByteBuffer(replicateCall);
  -        Object o2 = marshaller.objectFromByteBuffer(asBytes);
  -        assertTrue("Unmarshalled object should be a method call", o2 instanceof JBCMethodCall);
  -        MethodCall m2 = (MethodCall) o2;
  -        assertEquals(replicateCall.getMethod(), m2.getMethod());
  -
  -        // 1st arg should be another method call.
  -        MethodCall m3 = (MethodCall) m2.getArgs()[0];
  -        assertEquals(call.getMethod(), m3.getMethod());
  -
  -        List l1 = Arrays.asList(call.getArgs());
  -        List l2 = Arrays.asList(m3.getArgs());
  -        assertEquals(l1, l2);
  -    }
  -
       public void testMarshallerSelection()
       {
  +
           VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.4.0.GA");
           assertEquals(TreeCacheMarshaller140.class, marshaller.defaultMarshaller.getClass());
   
  @@ -105,18 +45,14 @@
           assertEquals(LegacyTreeCacheMarshaller.class, marshaller.defaultMarshaller.getClass());
       }
   
  -    public void testGetMarshaller()
  +   public void testVersionHeaderDefaultCurrent() throws Exception
       {
  -        VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.4.0.GA");
  -        assertEquals("Only one marshaller should be in the map by this stage", 1, marshaller.marshallers.size());
  -
  -        assertEquals(TreeCacheMarshaller140.class, marshaller.getMarshaller(14).getClass());
  -        assertEquals(LegacyTreeCacheMarshaller.class, marshaller.getMarshaller(15).getClass());
  -        assertEquals(LegacyTreeCacheMarshaller.class, marshaller.getMarshaller(1).getClass());
  -        assertEquals(LegacyTreeCacheMarshaller.class, marshaller.getMarshaller(-1).getClass());
  -        assertEquals(LegacyTreeCacheMarshaller.class, marshaller.getMarshaller(0).getClass());
  +      VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, Version.getVersionString(Version.getVersionShort()));
  +      byte[] bytes = marshaller.objectToByteBuffer("Hello");
   
  -        assertEquals("Two marshallers should be in the map by this stage", 2, marshaller.marshallers.size());
  +      // expect that this has been serialized using JBoss Serialization so use this to get an OIS.
  +      ObjectInputStream in = ObjectSerializationFactory.createObjectInputStream(bytes);
  +      assertEquals("Version header short should be '14'", 14, in.readShort());
       }
   
       public void testVersionHeader140() throws Exception
  @@ -147,21 +83,4 @@
               assertTrue("Expected an exception trying to read the version short", true);
           }
       }
  -
  -    public void testHandleLegacyStream() throws Exception
  -    {
  -        VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.4.0.GA");
  -
  -        // create a 'legacy' stream.
  -        ByteArrayOutputStream bout = new ByteArrayOutputStream();
  -        ObjectOutputStream out = new ObjectOutputStream(bout);
  -        
  -        out.writeObject("hello");
  -
  -        Object unmarshalled = marshaller.objectFromByteBuffer(bout.toByteArray());
  -
  -        assertEquals("hello", unmarshalled);
  -    }
  -
  -
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +236 -0    JBossCache/tests/functional/org/jboss/cache/marshall/BaseTreeCacheMarshallerTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BaseTreeCacheMarshallerTest.java
  ===================================================================
  RCS file: BaseTreeCacheMarshallerTest.java
  diff -N BaseTreeCacheMarshallerTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ BaseTreeCacheMarshallerTest.java	30 Aug 2006 11:30:46 -0000	1.1.2.2
  @@ -0,0 +1,236 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +package org.jboss.cache.marshall;
  +
  +import junit.framework.TestCase;
  +import org.jboss.cache.Fqn;
  +import org.jgroups.blocks.MethodCall;
  +
  +import java.io.ByteArrayOutputStream;
  +import java.io.ObjectOutputStream;
  +import java.util.ArrayList;
  +import java.util.List;
  +
  +public abstract class BaseTreeCacheMarshallerTest extends TestCase
  +{
  +   protected String currentVersion;
  +   protected int currentVersionShort;
  +   protected Class expectedMarshallerClass;
  +   protected VersionAwareMarshaller marshaller;
  +
  +
  +   protected void setUp()
  +   {
  +      marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, currentVersion);
  +   }
  +
  +   protected void tearDown()
  +   {
  +      marshaller = null;
  +   }
  +
  +   protected void assertMethodCallsEquals(MethodCall call1, MethodCall call2)
  +   {
  +      if (call1 == call2) return;
  +
  +      assertEquals("Method IDs should match", ((JBCMethodCall)call1).getMethodId(), ((JBCMethodCall)call2).getMethodId());
  +      assertEquals("Method names should match", call1.getName(), call2.getName());
  +      assertEquals("Method reflection objects should match", call1.getMethod(), call2.getMethod());
  +      if (call1.getArgs() == null || call2.getArgs() == null)
  +      {
  +         assertNull("Both args should be null", call1.getArgs());
  +         assertNull("Both args should be null", call2.getArgs());
  +      }
  +      else
  +      {
  +         Object[] call1Args = call1.getArgs();
  +         Object[] call2Args = call2.getArgs();
  +
  +         assertObjectArraysAreEqual(call1Args, call2Args);
  +      }
  +   }
  +
  +   protected void assertObjectArraysAreEqual(Object[] a1, Object[] a2)
  +   {
  +      assertEquals("Number of args should match", a1.length, a2.length);
  +
  +      for (int i = 0; i < a1.length; i++)
  +      {
  +         if (a1[i] instanceof MethodCall && a2[i] instanceof MethodCall)
  +         {
  +            assertMethodCallsEquals((MethodCall) a1[i], (MethodCall) a2[i]);
  +         }
  +         else if (a1[i] instanceof List && a2[i] instanceof List)
  +         {
  +            Object[] a1Elements = ((List) a1[i]).toArray();
  +            Object[] a2Elements = ((List) a2[i]).toArray();
  +
  +            assertObjectArraysAreEqual(a1Elements, a2Elements);
  +         }
  +         else
  +         {
  +            assertEquals("Argument # " + i + " should be equal", a1[i], a2[i]);
  +         }
  +      }
  +
  +   }
  +
  +
  +   public void testGetMarshaller()
  +   {
  +      assertEquals("Only one marshaller should be in the map by this stage", 1, marshaller.marshallers.size());
  +
  +      assertEquals(expectedMarshallerClass, marshaller.getMarshaller(currentVersionShort).getClass());
  +      assertEquals(LegacyTreeCacheMarshaller.class, marshaller.getMarshaller(15).getClass());
  +      assertEquals(LegacyTreeCacheMarshaller.class, marshaller.getMarshaller(1).getClass());
  +      assertEquals(LegacyTreeCacheMarshaller.class, marshaller.getMarshaller(-1).getClass());
  +      assertEquals(LegacyTreeCacheMarshaller.class, marshaller.getMarshaller(0).getClass());
  +
  +      assertEquals("Two marshallers should be in the map by this stage", 2, marshaller.marshallers.size());
  +   }
  +
  +   public void testStringBasedFqn() throws Exception
  +   {
  +      Fqn fqn = new Fqn(new Object[]{"JSESSIONID", "1010.10.5:3000", "1234567890", "1"});
  +      byte[] asBytes = marshaller.objectToByteBuffer(fqn);
  +      System.out.println("Marshalled to " + asBytes.length + " bytes");
  +      Object o2 = marshaller.objectFromByteBuffer(asBytes);
  +      assertEquals(fqn, o2);
  +   }
  +
  +   public void testNonStringBasedFqn() throws Exception
  +   {
  +      Fqn fqn = new Fqn(new Object[]{new Integer(3), Boolean.FALSE});
  +      byte[] asBytes = marshaller.objectToByteBuffer(fqn);
  +      Object o2 = marshaller.objectFromByteBuffer(asBytes);
  +      assertEquals(fqn, o2);
  +   }
  +
  +   public void testMethodCall() throws Exception
  +   {
  +      Fqn fqn = new Fqn(new Object[]{new Integer(3), Boolean.FALSE});
  +      MethodCall call = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, new Object[]{fqn, "key", "value"});
  +      byte[] asBytes = marshaller.objectToByteBuffer(call);
  +      Object o2 = marshaller.objectFromByteBuffer(asBytes);
  +
  +      assertTrue("Unmarshalled object should be a method call", o2 instanceof MethodCall);
  +      MethodCall m2 = (MethodCall) o2;
  +
  +      assertMethodCallsEquals(call, m2);
  +   }
  +
  +   public void testNestedMethodCall() throws Exception
  +   {
  +      Fqn fqn = new Fqn(new Object[]{new Integer(3), Boolean.FALSE});
  +      MethodCall call = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, new Object[]{fqn, "key", "value"});
  +      MethodCall replicateCall = MethodCallFactory.create(MethodDeclarations.replicateMethod, new Object[]{call});
  +      byte[] asBytes = marshaller.objectToByteBuffer(replicateCall);
  +      Object o2 = marshaller.objectFromByteBuffer(asBytes);
  +      assertTrue("Unmarshalled object should be a method call", o2 instanceof MethodCall);
  +      MethodCall m2 = (MethodCall) o2;
  +
  +      assertMethodCallsEquals(replicateCall, m2);
  +   }
  +
  +   public void testLargeString() throws Exception
  +   {
  +      StringBuilder sb = new StringBuilder();
  +      int stringSize = 32767;
  +
  +      for (int i = 0; i < stringSize; i++) sb.append('a');
  +
  +      String largeString = sb.toString();
  +
  +      assertEquals(stringSize, largeString.length());
  +
  +      byte[] buf = marshaller.objectToByteBuffer(largeString);
  +
  +      assertEquals(largeString, marshaller.objectFromByteBuffer(buf));
  +   }
  +
  +   public void testLargerString() throws Exception
  +   {
  +      StringBuilder sb = new StringBuilder();
  +      int stringSize = 32768;
  +
  +      for (int i = 0; i < stringSize; i++) sb.append('a');
  +
  +      String largeString = sb.toString();
  +
  +      assertEquals(stringSize, largeString.length());
  +
  +      byte[] buf = marshaller.objectToByteBuffer(largeString);
  +
  +      assertEquals(largeString, marshaller.objectFromByteBuffer(buf));
  +   }
  +
  +   public void testEvenLargerString() throws Exception
  +   {
  +      StringBuilder sb = new StringBuilder();
  +      int stringSize = 32769;
  +
  +      for (int i = 0; i < stringSize; i++) sb.append('a');
  +
  +      String largeString = sb.toString();
  +
  +      assertEquals(stringSize, largeString.length());
  +
  +      byte[] buf = marshaller.objectToByteBuffer(largeString);
  +
  +      assertEquals(largeString, marshaller.objectFromByteBuffer(buf));
  +   }
  +
  +   public void testReplicationQueue() throws Exception
  +   {
  +      doReplicationQueueTest();
  +   }
  +
  +   public void testReplicationQueueWithRegionBasedMarshalling() throws Exception
  +   {
  +      marshaller = new VersionAwareMarshaller(new RegionManager(), false, true, currentVersion);
  +      doReplicationQueueTest();
  +   }
  +
  +   protected void doReplicationQueueTest() throws Exception
  +   {
  +      // replication queue takes a list of replicate() MethodCalls and wraps them in a single replicate call.
  +      List calls = new ArrayList();
  +
  +      Fqn f = new Fqn(new Object[]{"BlahBlah", new Integer(3), Boolean.FALSE});
  +      String k = "key", v = "value";
  +
  +      MethodCall actualCall = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, new Object[]{f, k, v});
  +      MethodCall replicateCall = MethodCallFactory.create(MethodDeclarations.replicateMethod, new Object[]{actualCall});
  +
  +      calls.add(replicateCall);
  +
  +      actualCall = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, new Object[]{f, k, v});
  +      replicateCall = MethodCallFactory.create(MethodDeclarations.replicateMethod, new Object[]{actualCall});
  +
  +      calls.add(replicateCall);
  +
  +      MethodCall call = MethodCallFactory.create(MethodDeclarations.replicateAllMethod, new Object[]{calls});
  +
  +      byte[] buf = marshaller.objectToByteBuffer(call);
  +
  +      assertMethodCallsEquals(call, (MethodCall) marshaller.objectFromByteBuffer(buf));
  +   }
  +
  +   public void testHandleLegacyStream() throws Exception
  +   {
  +      // create a 'legacy' stream.
  +      ByteArrayOutputStream bout = new ByteArrayOutputStream();
  +      ObjectOutputStream out = new ObjectOutputStream(bout);
  +
  +      out.writeObject("hello");
  +
  +      Object unmarshalled = marshaller.objectFromByteBuffer(bout.toByteArray());
  +
  +      assertEquals("hello", unmarshalled);
  +   }
  +
  +}
  
  
  
  1.1.2.2   +22 -0     JBossCache/tests/functional/org/jboss/cache/marshall/TreeCacheMarshaller140Test.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TreeCacheMarshaller140Test.java
  ===================================================================
  RCS file: TreeCacheMarshaller140Test.java
  diff -N TreeCacheMarshaller140Test.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ TreeCacheMarshaller140Test.java	30 Aug 2006 11:30:46 -0000	1.1.2.2
  @@ -0,0 +1,22 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +package org.jboss.cache.marshall;
  +
  +/**
  + * //TODO: MANIK: Javadoc this class
  + *
  + * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
  + */
  +public class TreeCacheMarshaller140Test extends BaseTreeCacheMarshallerTest
  +{
  +   public TreeCacheMarshaller140Test()
  +   {
  +      currentVersion = "1.4.0.GA";
  +      currentVersionShort = 14;
  +      expectedMarshallerClass = TreeCacheMarshaller140.class;
  +   }
  +}
  
  
  



More information about the jboss-cvs-commits mailing list