[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/replicated ...
Manik Surtani
msurtani at belmont.prod.atl2.jboss.com
Tue Aug 29 12:35:52 EDT 2006
User: msurtani
Date: 06/08/29 12:35:52
Modified: tests/functional/org/jboss/cache/replicated
AsyncReplTest.java
Added: tests/functional/org/jboss/cache/replicated
SyncReplTest.java
Log:
Fixed basic replication issues
Revision Changes Path
1.10 +106 -117 JBossCache/tests/functional/org/jboss/cache/replicated/AsyncReplTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AsyncReplTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/replicated/AsyncReplTest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- AsyncReplTest.java 20 Jul 2006 11:14:17 -0000 1.9
+++ AsyncReplTest.java 29 Aug 2006 16:35:52 -0000 1.10
@@ -15,7 +15,6 @@
import junit.framework.TestSuite;
import org.jboss.cache.Fqn;
import org.jboss.cache.TreeCache;
-import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.misc.TestingUtil;
@@ -25,28 +24,32 @@
* Unit test for replicated async TreeCache. Use locking and multiple threads to test
* concurrent access to the tree.
*
- * @version $Revision: 1.9 $
+ * @version $Revision: 1.10 $
*/
-public class AsyncReplTest extends TestCase {
+public class AsyncReplTest extends TestCase
+{
TreeCache cache1, cache2;
- String props=null;
+ String props = null;
- public AsyncReplTest(String name) {
+ public AsyncReplTest(String name)
+ {
super(name);
}
- public void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
super.setUp();
log("creating cache1");
- cache1=createCache("CacheGroup");
+ cache1 = createCache("CacheGroup");
log("creating cache2");
- cache2=createCache("CacheGroup");
+ cache2 = createCache("CacheGroup");
}
- private TreeCache createCache(String name) throws Exception {
- TreeCache tree=new TreeCache();
+ private TreeCache createCache(String name) throws Exception
+ {
+ TreeCache tree = new TreeCache();
tree.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replAsync-service.xml"));
tree.getConfiguration().setClusterName(name);
tree.createService();
@@ -54,16 +57,21 @@
return tree;
}
- public void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
super.tearDown();
- if(cache1 != null) {
+ if (cache1 != null)
+ {
log("stopping cache1");
cache1.stopService();
+ cache1 = null;
}
- if(cache2 != null) {
+ if (cache2 != null)
+ {
log("stopping cache2");
cache2.stopService();
+ cache2 = null;
}
}
@@ -76,7 +84,7 @@
cache1.put(fqn, key, "value1");
// allow for replication
- TestingUtil.sleepThread((long)500);
+ TestingUtil.sleepThread((long) 500);
Assert.assertEquals("value1", cache1.get(fqn, key));
Assert.assertEquals("value1", cache2.get(fqn, key));
@@ -89,7 +97,7 @@
mgr.commit();
- TestingUtil.sleepThread((long)500);
+ TestingUtil.sleepThread((long) 500);
Assert.assertEquals("value2", cache1.get(fqn, key));
Assert.assertEquals("value2", cache2.get(fqn, key));
@@ -101,7 +109,7 @@
mgr.rollback();
- TestingUtil.sleepThread((long)500);
+ TestingUtil.sleepThread((long) 500);
Assert.assertEquals("value2", cache1.get(fqn, key));
Assert.assertEquals("value2", cache2.get(fqn, key));
@@ -120,39 +128,50 @@
}
- public void testPutShouldNotReplicateToDifferentCluster() {
- TreeCache cache3=null;
- try {
- cache3=createCache("DifferentGroup");
+ public void testPutShouldNotReplicateToDifferentCluster()
+ {
+ TreeCache cache3 = null;
+ try
+ {
+ cache3 = createCache("DifferentGroup");
cache1.put("/a/b/c", "age", new Integer(38));
// because we use async repl, modfication may not yet have been propagated to cache2, so
// we have to wait a little
- TestingUtil.sleepThread((long)1000);
+ TestingUtil.sleepThread((long) 1000);
assertNull("Should not have replicated", cache3.get("/a/b/c", "age"));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
- finally {
- if(cache3 != null)
+ finally
+ {
+ if (cache3 != null)
+ {
cache3.stopService();
}
}
+ }
- public void testStateTransfer() {
- TreeCache cache4=null;
- try {
+ public void testStateTransfer()
+ {
+ TreeCache cache4 = null;
+ try
+ {
cache1.put("a/b/c", "age", new Integer(38));
- cache4=createCache("CacheGroup");
+ cache4 = createCache("CacheGroup");
System.out.println("" + cache4.getMembers());
assertEquals(3, cache4.getMembers().size()); // cache1, cache2 and cache4
assertEquals("\"age\" should be 38", new Integer(38), cache4.get("/a/b/c", "age"));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
- finally {
- if(cache4 != null) {
+ finally
+ {
+ if (cache4 != null)
+ {
System.out.println("cache4's view: " + cache4.getMembers());
cache4.stopService();
}
@@ -160,90 +179,60 @@
}
- public void testAsyncReplDelay() {
+ public void testAsyncReplDelay()
+ {
Integer age;
- try {
+ try
+ {
cache1.put("/a/b/c", "age", new Integer(38));
// value on cache2 may be 38 or not yet replicated
- age=(Integer)cache2.get("/a/b/c", "age");
+ age = (Integer) cache2.get("/a/b/c", "age");
log("attr \"age\" of \"/a/b/c\" on cache2=" + age);
assertTrue("should be either null or 38", age == null || age.intValue() == 38);
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testAsyncReplTxDelay() {
+ public void testAsyncReplTxDelay()
+ {
Integer age;
- try {
+ try
+ {
TransactionManager tm = cache1.getTransactionManager();
tm.begin();
cache1.put("/a/b/c", "age", new Integer(38));
tm.commit();
// value on cache2 may be 38 or not yet replicated
- age=(Integer)cache2.get("/a/b/c", "age");
+ age = (Integer) cache2.get("/a/b/c", "age");
log("attr \"age\" of \"/a/b/c\" on cache2=" + age);
assertTrue("should be either null or 38", age == null || age.intValue() == 38);
}
- catch(Exception e) {
- fail(e.toString());
- }
- }
-
- public void testSyncRepl() throws Exception {
- Fqn fqn = Fqn.fromString("/JSESSIONID/1010.10.5:3000/1234567890/1");
- Integer age;
- cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
- cache1.getConfiguration().setSyncCommitPhase(true);
- cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
- cache2.getConfiguration().setSyncCommitPhase(true);
-
-
- try {
- cache1.put(fqn, "age", new Integer(38));
-
- // value on cache2 must be 38
- age=(Integer)cache2.get(fqn, "age");
- assertNotNull("\"age\" obtained from cache2 is null ", age);
- assertTrue("\"age\" must be 38", age.intValue() == 38);
- }
- catch(Exception e) {
- e.printStackTrace();
- fail(e.toString());
- }
- }
-
- public void testSyncReplSimple() throws Exception {
- cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
- cache1.getConfiguration().setSyncCommitPhase(true);
- cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
- cache2.getConfiguration().setSyncCommitPhase(true);
-
- try {
- cache1.put("/a", "x", "y");
- assertEquals("y", cache2.get("/a", "x"));
- }
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
-
- void log(String msg) {
+ void log(String msg)
+ {
System.out.println("-- [" + Thread.currentThread() + "]: " + msg);
}
- public static Test suite() {
+ public static Test suite()
+ {
return new TestSuite(AsyncReplTest.class);
}
- public static void main(String[] args) {
+ public static void main(String[] args)
+ {
junit.textui.TestRunner.run(suite());
}
}
1.1 date: 2006/08/29 16:35:52; author: msurtani; state: Exp;JBossCache/tests/functional/org/jboss/cache/replicated/SyncReplTest.java
Index: SyncReplTest.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.replicated;
import junit.framework.TestCase;
import org.jboss.cache.Cache;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.TreeCacheProxyImpl;
import org.jboss.cache.factories.DefaultCacheFactory;
import org.jboss.cache.misc.TestingUtil;
/**
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
*/
public class SyncReplTest extends TestCase
{
private Cache[] caches;
protected void setUp()
{
System.out.println("*** In setUp()");
caches = new Cache[2];
caches[0] = new DefaultCacheFactory().createCache("META-INF/replSync-service.xml");
caches[1] = new DefaultCacheFactory().createCache("META-INF/replSync-service.xml");
TestingUtil.blockUntilViewsReceived(caches, 5000);
System.out.println("*** Finished setUp()");
}
protected void tearDown()
{
System.out.println("*** In tearDown()");
if (caches != null)
{
for (Cache c : caches)
{
c.stop();
c = null;
}
caches = null;
}
System.out.println("*** Finished tearDown()");
}
public void testBasicOperation()
{
assertClusterSize("Should only be 2 caches in the cluster!!!", 2);
Fqn f = Fqn.fromString("/test/data");
String k = "key", v = "value";
assertNull("Should be null", caches[0].getChild(f));
assertNull("Should be null", caches[1].getChild(f));
Node node = caches[0].addChild(f);
assertNotNull("Should not be null", node);
node.put(k, v);
assertEquals(v, node.get(k));
assertEquals(v, caches[0].get(f, k));
assertEquals("Should have replicated", v, caches[1].get(f, k));
}
public void testSyncRepl()
{
assertClusterSize("Should only be 2 caches in the cluster!!!", 2);
Fqn fqn = Fqn.fromString("/JSESSIONID/1010.10.5:3000/1234567890/1");
Integer age;
caches[0].getConfiguration().setSyncCommitPhase(true);
caches[1].getConfiguration().setSyncCommitPhase(true);
caches[0].put(fqn, "age", new Integer(38));
// value on cache2 must be 38
age = (Integer) caches[1].get(fqn, "age");
assertNotNull("\"age\" obtained from caches[1] is null ", age);
assertTrue("\"age\" must be 38", age.intValue() == 38);
}
private void assertClusterSize(String message, int size)
{
for (Cache c : caches)
{
assertClusterSize(message, size, (TreeCacheProxyImpl) c);
}
}
private void assertClusterSize(String message, int size, TreeCacheProxyImpl tcpi)
{
assertEquals(message, size, tcpi.treeCache.getMembers().size());
}
}
More information about the jboss-cvs-commits
mailing list