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

Manik Surtani msurtani at jboss.com
Sat Nov 11 14:55:19 EST 2006


  User: msurtani
  Date: 06/11/11 14:55:19

  Modified:    tests/functional/org/jboss/cache/options  
                        ExplicitVersionsTest.java
  Added:       tests/functional/org/jboss/cache/options  
                        ExplicitVersionsReplTest.java
  Log:
  JBCACHE-842 and JBCACHE-843
  
  Revision  Changes    Path
  1.7       +17 -0     JBossCache/tests/functional/org/jboss/cache/options/ExplicitVersionsTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ExplicitVersionsTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/options/ExplicitVersionsTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- ExplicitVersionsTest.java	7 Sep 2006 15:42:16 -0000	1.6
  +++ ExplicitVersionsTest.java	11 Nov 2006 19:55:19 -0000	1.7
  @@ -143,4 +143,21 @@
         }
         else throw new IllegalArgumentException("version type mismatch");
      }
  +
  +
  +   public String toString()
  +   {
  +      return "TestVersion-" + myVersion;
  +   }
  +
  +   public boolean equals(Object other)
  +   {
  +      if (other instanceof TestVersion)
  +      {
  +         TestVersion oVersion = (TestVersion) other;
  +         if (oVersion.myVersion == null && myVersion == null) return true;
  +         if (myVersion != null) return myVersion.equals(oVersion.myVersion);
  +      }
  +      return false;
  +   }
   }
  \ No newline at end of file
  
  
  
  1.2       +290 -0    JBossCache/tests/functional/org/jboss/cache/options/ExplicitVersionsReplTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ExplicitVersionsReplTest.java
  ===================================================================
  RCS file: ExplicitVersionsReplTest.java
  diff -N ExplicitVersionsReplTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ ExplicitVersionsReplTest.java	11 Nov 2006 19:55:19 -0000	1.2
  @@ -0,0 +1,290 @@
  +package org.jboss.cache.options;
  +
  +import junit.framework.Assert;
  +import junit.framework.TestCase;
  +import org.jboss.cache.Fqn;
  +import org.jboss.cache.OptimisticTreeNode;
  +import org.jboss.cache.TreeCache;
  +import org.jboss.cache.config.Configuration;
  +import org.jboss.cache.misc.TestingUtil;
  +import org.jboss.cache.optimistic.DataVersion;
  +import org.jboss.cache.optimistic.DefaultDataVersion;
  +
  +import javax.transaction.RollbackException;
  +import javax.transaction.TransactionManager;
  +
  +/**
  + * Tests the passing in of explicit {@see DataVersion} instances when using optimistic locking + replication.
  + *
  + * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
  + */
  +public class ExplicitVersionsReplTest extends TestCase
  +{
  +   private TreeCache cache[];
  +   private Fqn fqn = Fqn.fromString("/a");
  +   private String key = "key";
  +
  +   protected void setUp() throws Exception
  +   {
  +      if (cache != null) tearDown();
  +      cache = new TreeCache[2];
  +      cache[0] = createCache();
  +      cache[1] = createCache();
  +      TestingUtil.blockUntilViewsReceived(cache, 20000);
  +   }
  +
  +   private TreeCache createCache() throws Exception
  +   {
  +      TreeCache cache = new TreeCache();
  +      Configuration c = cache.getConfiguration();
  +      c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
  +      c.setNodeLockingScheme("OPTIMISTIC");
  +      // give us lots of time to trace and debug shit
  +      c.setSyncCommitPhase(true);
  +      c.setSyncRollbackPhase(true);
  +      c.setSyncReplTimeout(600000);
  +      c.setLockAcquisitionTimeout(600000);
  +      c.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
  +
  +      cache.setConfiguration(c);
  +      cache.start();
  +      return cache;
  +   }
  +
  +   protected void tearDown()
  +   {
  +      if (cache != null)
  +      {
  +         for (TreeCache aCache : cache) destroyCache(aCache);
  +         cache = null;
  +      }
  +   }
  +
  +   private void destroyCache(TreeCache c)
  +   {
  +      TransactionManager tm = c.getTransactionManager();
  +      try
  +      {
  +         if (tm != null && tm.getTransaction() != null) tm.getTransaction().rollback();
  +      }
  +      catch (Exception e)
  +      {
  +      }
  +      c.stop();
  +   }
  +
  +   /**
  +    * This test sets a custom data version first, expects it to replicate, and then does a put on the remote
  +    * cache using an implicit data version.  Should fail with a CCE.
  +    *
  +    * @throws Exception
  +    */
  +   public void testIncompatibleVersionTypes1() throws Exception
  +   {
  +      DataVersion version = new TestVersion("99");
  +      cache[0].getInvocationContext().getOptionOverrides().setDataVersion(version);
  +      cache[0].put(fqn, key, "value"); // TestVersion-99 should be on both caches now
  +
  +      TransactionManager mgr = cache[0].getTransactionManager();
  +      mgr.begin();
  +      // don't explicitly set a data version.
  +
  +      System.out.println("************ stage 2");
  +
  +      // force an IC scrub
  +      //cache[1].getInvocationContext().setOptionOverrides(null);
  +      cache[1].put(fqn, key, "value2");
  +      try
  +      {
  +         mgr.commit();
  +
  +         System.out.println(cache[0].printDetails());
  +         System.out.println(cache[1].printDetails());
  +
  +         Assert.assertTrue("expected to fail", false);
  +      }
  +      catch (RollbackException e)
  +      {
  +         // should fail.
  +         Assert.assertTrue("expected to fail with a nested ClassCastException", true);
  +      }
  +   }
  +
  +   /**
  +    * This test sets a custom data version first, expects it to replicate, and then does a put on the remote
  +    * cache using a higher custom data version.  Should pass and not throw any exceptions.
  +    *
  +    * @throws Exception
  +    */
  +   public void testCompatibleVersionTypes1() throws Exception
  +   {
  +      DataVersion version = new TestVersion("99");
  +      cache[0].getInvocationContext().getOptionOverrides().setDataVersion(version);
  +      cache[0].put(fqn, key, "value"); // TestVersion-99 should be on both caches now
  +
  +      TransactionManager mgr = cache[0].getTransactionManager();
  +      mgr.begin();
  +
  +      version = new TestVersion("199");
  +      cache[0].getInvocationContext().getOptionOverrides().setDataVersion(version);
  +      cache[1].put(fqn, key, "value2");
  +      mgr.commit();
  +   }
  +
  +
  +   /**
  +    * This test sets a custom data version first, expects it to replicate, and then does a put on the remote
  +    * cache using a lower custom data version.  Should fail.
  +    *
  +    * @throws Exception
  +    */
  +   public void testCompatibleVersionTypesOutDatedVersion1() throws Exception
  +   {
  +      DataVersion version = new TestVersion("99");
  +      cache[0].getInvocationContext().getOptionOverrides().setDataVersion(version);
  +      cache[0].put(fqn, key, "value"); // TestVersion-99 should be on both caches now
  +
  +      TransactionManager mgr = cache[0].getTransactionManager();
  +      mgr.begin();
  +
  +      version = new TestVersion("29");
  +      cache[1].getInvocationContext().getOptionOverrides().setDataVersion(version);
  +      cache[1].put(fqn, key, "value2");
  +      try
  +      {
  +         mgr.commit();
  +         Assert.assertTrue("expected to fail", false);
  +      }
  +      catch (RollbackException e)
  +      {
  +         // should fail.
  +         Assert.assertTrue("expected to fail with a CacheException to do with a versioning mismatch", true);
  +      }
  +   }
  +
  +
  +   /**
  +    * This test sets an implicit data version first, expects it to replicate, and then does a put on the remote
  +    * cache using a custom data version.  Should fail with a CCE.
  +    *
  +    * @throws Exception
  +    */
  +   public void testIncompatibleVersionTypes2() throws Exception
  +   {
  +      cache[0].put(fqn, key, "value"); // default data version should be on both caches now
  +
  +      TransactionManager mgr = cache[0].getTransactionManager();
  +      mgr.begin();
  +
  +      // explicitly set data version
  +      DataVersion version = new TestVersion("99");
  +      cache[1].getInvocationContext().getOptionOverrides().setDataVersion(version);
  +
  +      try
  +      {
  +         cache[1].put(fqn, key, "value2");
  +         mgr.commit();
  +         Assert.assertTrue("expected to fail", false);
  +      }
  +      catch (Exception e)
  +      {
  +         // should fail.
  +         Assert.assertTrue("expected to fail", true);
  +      }
  +   }
  +
  +   /**
  +    * This test sets an implicit data version first, expects it to replicate, and then does a put on the remote
  +    * cache using a higher implicit data version.  Should pass and not throw any exceptions.
  +    *
  +    * @throws Exception
  +    */
  +   public void testCompatibleVersionTypes2() throws Exception
  +   {
  +      cache[0].put(fqn, key, "value"); // TestVersion-99 should be on both caches now
  +
  +      TransactionManager mgr = cache[0].getTransactionManager();
  +      mgr.begin();
  +
  +      DataVersion version = new DefaultDataVersion(300);
  +      cache[1].getInvocationContext().getOptionOverrides().setDataVersion(version);
  +      cache[1].put(fqn, key, "value2");
  +      mgr.commit();
  +   }
  +
  +
  +   /**
  +    * This test sets an implicit data version first, expects it to replicate, and then does a put on the remote
  +    * cache using a lower implicit data version.  Should fail.
  +    *
  +    * @throws Exception
  +    */
  +   public void testCompatibleVersionTypesOutDatedVersion2() throws Exception
  +   {
  +      DataVersion version = new DefaultDataVersion(200);
  +      cache[0].getInvocationContext().getOptionOverrides().setDataVersion(version);
  +      cache[0].put(fqn, key, "value"); // TestVersion-99 should be on both caches now
  +
  +      TransactionManager mgr = cache[0].getTransactionManager();
  +      mgr.begin();
  +
  +      version = new DefaultDataVersion(100);
  +      cache[1].getInvocationContext().getOptionOverrides().setDataVersion(version);
  +      cache[1].put(fqn, key, "value2");
  +      try
  +      {
  +         // this call will use implicit versioning and will hence fail.
  +         mgr.commit();
  +         Assert.assertTrue("expected to fail", false);
  +      }
  +      catch (Exception e)
  +      {
  +         // should fail.
  +         Assert.assertTrue("expected to fail with a CacheException to do with a versioning mismatch", true);
  +      }
  +   }
  +
  +   public void testPropagationOfDefaultVersions() throws Exception
  +   {
  +      DefaultDataVersion expected = new DefaultDataVersion();
  +      expected = (DefaultDataVersion) expected.increment();
  +
  +      cache[0].put(fqn, key, "value");
  +
  +      assertEquals("value", cache[0].get(fqn, key));
  +      assertEquals("value", cache[1].get(fqn, key));
  +      assertEquals(expected, ((OptimisticTreeNode) cache[0].get(fqn)).getVersion());
  +      assertEquals(expected, ((OptimisticTreeNode) cache[1].get(fqn)).getVersion());
  +
  +      cache[1].put(fqn, key, "value2");
  +      expected = (DefaultDataVersion) expected.increment();
  +
  +      assertEquals("value2", cache[0].get(fqn, key));
  +      assertEquals("value2", cache[1].get(fqn, key));
  +      assertEquals(expected, ((OptimisticTreeNode) cache[0].get(fqn)).getVersion());
  +      assertEquals(expected, ((OptimisticTreeNode) cache[1].get(fqn)).getVersion());
  +   }
  +
  +   public void testPropagationOfCustomVersions() throws Exception
  +   {
  +      TestVersion expected = new TestVersion("100");
  +      cache[0].getInvocationContext().getOptionOverrides().setDataVersion(expected);
  +      cache[0].put(fqn, key, "value");
  +
  +      assertEquals("value", cache[0].get(fqn, key));
  +      assertEquals("value", cache[1].get(fqn, key));
  +      assertEquals(expected, ((OptimisticTreeNode) cache[0].get(fqn)).getVersion());
  +      assertEquals(expected, ((OptimisticTreeNode) cache[1].get(fqn)).getVersion());
  +
  +      expected = new TestVersion("200");
  +      cache[0].getInvocationContext().getOptionOverrides().setDataVersion(expected);
  +      cache[1].put(fqn, key, "value2");
  +
  +      assertEquals("value2", cache[0].get(fqn, key));
  +      assertEquals("value2", cache[1].get(fqn, key));
  +      assertEquals(expected, ((OptimisticTreeNode) cache[0].get(fqn)).getVersion());
  +      assertEquals(expected, ((OptimisticTreeNode) cache[1].get(fqn)).getVersion());
  +   }
  +
  +
  +}
  
  
  



More information about the jboss-cvs-commits mailing list