[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/api ...
Ben Wang
bwang at jboss.com
Tue Sep 5 02:50:42 EDT 2006
User: bwang
Date: 06/09/05 02:50:42
Added: tests/functional/org/jboss/cache/api SyncReplTxTest.java
Log:
no message
Revision Changes Path
1.1 date: 2006/09/05 06:50:42; author: bwang; state: Exp;JBossCache/tests/functional/org/jboss/cache/api/SyncReplTxTest.java
Index: SyncReplTxTest.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.CacheSPI;
import org.jboss.cache.TreeCacheProxyImpl;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.config.Option;
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.factories.DefaultCacheFactory;
import javax.transaction.Transaction;
import javax.transaction.SystemException;
import javax.transaction.NotSupportedException;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.RollbackException;
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 SyncReplTxTest 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()");
}
Transaction beginTransaction() throws SystemException, NotSupportedException
{
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
return mgr.getTransaction();
}
public void testBasicOperation() throws SystemException, NotSupportedException, HeuristicMixedException, HeuristicRollbackException, RollbackException
{
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);
Transaction tx = beginTransaction();
node.put(k, v);
Transaction tx1 = ((CacheSPI)caches[0]).getInvocationContext().getTransaction();
assertNotNull("Transaction can't be null ", tx1);
tx.commit();
assertEquals(v, node.get(k));
assertEquals(v, caches[0].get(f, k));
assertEquals("Should have replicated", v, caches[1].get(f, k));
}
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