[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/api ...
Ben Wang
bwang at jboss.com
Fri Sep 1 09:56:08 EDT 2006
User: bwang
Date: 06/09/01 09:56:08
Added: tests/functional/org/jboss/cache/api SyncReplTest.java
Log:
no message
Revision Changes Path
1.1 date: 2006/09/01 13:56:08; author: bwang; state: Exp;JBossCache/tests/functional/org/jboss/cache/api/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.api;
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.InvocationContext;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.config.Option;
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.factories.DefaultCacheFactory;
import java.util.Map;
import java.util.HashMap;
/**
* @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);
assertInvocationContextInitState();
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);
assertInvocationContextInitState();
Fqn fqn = Fqn.fromString("/JSESSIONID/1010.10.5:3000/1234567890/1");
caches[0].getConfiguration().setSyncCommitPhase(true);
caches[1].getConfiguration().setSyncCommitPhase(true);
caches[0].put(fqn, "age", 38);
assertEquals("Value should be set", 38, caches[0].get(fqn, "age"));
assertEquals("Value should have replicated", 38, caches[1].get(fqn, "age"));
}
public void testPutMap()
{
assertClusterSize("Should only be 2 caches in the cluster!!!", 2);
assertInvocationContextInitState();
Fqn fqn = Fqn.fromString("/JSESSIONID/1010.10.5:3000/1234567890/1");
Map map = new HashMap();
map.put("1", "1");
map.put("2", "2");
caches[0].getRoot().addChild(fqn).put(map);
assertEquals("Value should be set", "1", caches[0].get(fqn, "1"));
}
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());
}
private void assertInvocationContextInitState()
{
for (Cache c : caches)
{
assertInvocationContextInitState(c);
}
}
private void assertInvocationContextInitState(Cache c)
{
InvocationContext ctx = ((CacheSPI) c).getInvocationContext();
InvocationContext control = null;
try
{
control = ctx.clone();
}
catch (CloneNotSupportedException e)
{
fail("Unable to clone InvocationCOntext");
}
control.reset();
control.setOptionOverrides(new Option());
assertEquals("Should be equal", control, ctx);
}
}
More information about the jboss-cvs-commits
mailing list