From jbosscache-commits at lists.jboss.org Fri Oct 19 13:37:24 2007 Content-Type: multipart/mixed; boundary="===============4411078428166009829==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r4650 - core/trunk/src/test/java/org/jboss/cache/statetransfer. Date: Fri, 19 Oct 2007 13:37:24 -0400 Message-ID: --===============4411078428166009829== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: manik.surtani(a)jboss.com Date: 2007-10-19 13:37:24 -0400 (Fri, 19 Oct 2007) New Revision: 4650 Added: core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTransf= erTest.java Log: Added test for JBCACHE-1202 Added: core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTr= ansferTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTrans= ferTest.java (rev 0) +++ core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTrans= ferTest.java 2007-10-19 17:37:24 UTC (rev 4650) @@ -0,0 +1,216 @@ +package org.jboss.cache.statetransfer; + +import org.jboss.cache.Cache; +import org.jboss.cache.DefaultCacheFactory; +import org.jboss.cache.Fqn; +import org.jboss.cache.NodeSPI; +import org.jboss.cache.config.Configuration; +import org.jboss.cache.misc.TestingUtil; +import org.jboss.cache.optimistic.DataVersion; +import org.jboss.cache.optimistic.DataVersioningException; +import org.jboss.cache.optimistic.DefaultDataVersion; +import org.jboss.cache.transaction.DummyTransactionManagerLookup; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.List; + +/** + * Tests whether data versions are transferred along with state + * + * @author Manik Surtani + * @since 2.1.0 + */ +(a)Test(groups =3D {"functional"}) +public class DataVersionTransferTest +{ + private List> caches =3D new ArrayList>(2); + + @BeforeMethod + public void setUp() + { + + caches.add(DefaultCacheFactory.getInstance().createCache(false)); + caches.get(0).getConfiguration().setTransactionManagerLookupClass(Du= mmyTransactionManagerLookup.class.getName()); + caches.get(0).getConfiguration().setNodeLockingScheme(Configuration.= NodeLockingScheme.OPTIMISTIC); + caches.get(0).getConfiguration().setCacheMode(Configuration.CacheMod= e.REPL_SYNC); + caches.get(0).start(); + + caches.add(DefaultCacheFactory.getInstance().createCache(false)); + caches.get(1).getConfiguration().setTransactionManagerLookupClass(Du= mmyTransactionManagerLookup.class.getName()); + caches.get(1).getConfiguration().setNodeLockingScheme(Configuration.= NodeLockingScheme.OPTIMISTIC); + caches.get(1).getConfiguration().setCacheMode(Configuration.CacheMod= e.REPL_SYNC); + } + + @AfterMethod + public void tearDown() + { + if (caches !=3D null) + { + for (Cache cache: caches) + { + try + { + cache.getConfiguration().getRuntimeConfig().getTransactionM= anager().rollback(); + } + catch (Exception e) + { + // do nothing? + } + cache.stop(); + } + } + } + + public void testStateTransferDefaultVersions() throws Exception + { + Fqn f =3D Fqn.fromString("/one/two/three"); + caches.get(0).put(f, "k", "v"); + caches.get(0).put(f, "k1", "v1"); + caches.get(0).remove(f, "k1"); + + NodeSPI n =3D (NodeSPI) caches.get(0).getRoot().getChild(f); + DataVersion dv =3D n.getVersion(); + + assert dv instanceof DefaultDataVersion : "Should be an instance of = DefaultDataVersion"; + + assert ((DefaultDataVersion) dv).getRawVersion() =3D=3D 3 : "Should = have accurate data version"; + + // now start next cache instance + caches.get(1).start(); + + TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get= (1)); + + assert caches.get(1).get(f, "k").equals("v") : "Value should have tr= ansferred"; + + n =3D (NodeSPI) caches.get(1).getRoot().getChild(f); + + dv =3D n.getVersion(); + + assert dv instanceof DefaultDataVersion : "Should be an instance of = DefaultDataVersion"; + + assert ((DefaultDataVersion) dv).getRawVersion() =3D=3D 3 : "Version= should have transferred"; + } + + public void testStateTransferCustomVersion() throws Exception + { + Fqn f =3D Fqn.fromString("/one/two/three"); + caches.get(0).getInvocationContext().getOptionOverrides().setDataVer= sion(new CharVersion('A')); + caches.get(0).put(f, "k", "v"); + caches.get(0).getInvocationContext().getOptionOverrides().setDataVer= sion(new CharVersion('B')); + caches.get(0).put(f, "k1", "v1"); + caches.get(0).getInvocationContext().getOptionOverrides().setDataVer= sion(new CharVersion('C')); + caches.get(0).remove(f, "k1"); + + NodeSPI n =3D (NodeSPI) caches.get(0).getRoot().getChild(f); + DataVersion dv =3D n.getVersion(); + + assert dv instanceof CharVersion : "Should be an instance of CharVer= sion"; + + assert ((CharVersion) dv).version =3D=3D 'C' : "Should have accurate= data version"; + + // now start next cache instance + caches.get(1).start(); + + TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get= (1)); + + assert caches.get(1).get(f, "k").equals("v") : "Value should have tr= ansferred"; + + n =3D (NodeSPI) caches.get(1).getRoot().getChild(f); + + dv =3D n.getVersion(); + + assert dv instanceof CharVersion : "Should be an instance of CharVer= sion"; + + assert ((CharVersion) dv).version =3D=3D 'C' : "Version should have = transferred"; + } + + public void testStateTransferDefaultVersionAfterRemoval() throws Except= ion + { + Fqn f =3D Fqn.fromString("/one/two/three"); + caches.get(0).put(f, "k", "v"); + caches.get(0).put(f, "k1", "v1"); + caches.get(0).removeNode(f); + + NodeSPI n =3D (NodeSPI) caches.get(0).getRoot().getChild(f); + DataVersion dv =3D n.getVersion(); + + assert dv instanceof DefaultDataVersion : "Should be an instance of = DefaultDataVersion"; + + assert ((DefaultDataVersion) dv).getRawVersion() =3D=3D 3 : "Should = have accurate data version"; + + // now start next cache instance + caches.get(1).start(); + + TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get= (1)); + + assert caches.get(1).get(f, "k")=3D=3D null : "Should be removed"; + + n =3D (NodeSPI) caches.get(1).getRoot().getChild(f); + + dv =3D n.getVersion(); + + assert dv instanceof DefaultDataVersion : "Should be an instance of = DefaultDataVersion"; + + assert ((DefaultDataVersion) dv).getRawVersion() =3D=3D 3 : "Version= should have transferred"; + } + + public void testStateTransferCustomVersionAfterRemoval() throws Excepti= on + { + Fqn f =3D Fqn.fromString("/one/two/three"); + caches.get(0).getInvocationContext().getOptionOverrides().setDataVer= sion(new CharVersion('A')); + caches.get(0).put(f, "k", "v"); + caches.get(0).getInvocationContext().getOptionOverrides().setDataVer= sion(new CharVersion('B')); + caches.get(0).put(f, "k1", "v1"); + caches.get(0).getInvocationContext().getOptionOverrides().setDataVer= sion(new CharVersion('C')); + caches.get(0).removeNode(f); + + NodeSPI n =3D (NodeSPI) caches.get(0).getRoot().getChild(f); + DataVersion dv =3D n.getVersion(); + + assert dv instanceof CharVersion : "Should be an instance of CharVer= sion"; + + assert ((CharVersion) dv).version =3D=3D 'C' : "Should have accurate= data version"; + + // now start next cache instance + caches.get(1).start(); + + TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get= (1)); + + assert caches.get(1).get(f, "k")=3D=3D null : "Should be removed"; + + n =3D (NodeSPI) caches.get(1).getRoot().getChild(f); + + dv =3D n.getVersion(); + + assert dv instanceof CharVersion : "Should be an instance of CharVer= sion"; + + assert ((CharVersion) dv).version =3D=3D 'C' : "Version should have = transferred"; + } + + public static class CharVersion implements DataVersion + { + private char version =3D 'A'; + + public CharVersion(char version) + { + this.version =3D version; + } + + public boolean newerThan(DataVersion other) + { + if (other instanceof CharVersion) + { + CharVersion otherVersion =3D (CharVersion) other; + return version > otherVersion.version; + } + else + { + throw new DataVersioningException("Incompatible version types"= ); + } + } + } + +} --===============4411078428166009829==--