[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/api ...
Manik Surtani
msurtani at jboss.com
Wed Sep 13 13:10:42 EDT 2006
User: msurtani
Date: 06/09/13 13:10:42
Added: tests/functional/org/jboss/cache/api NodeAPITest.java
Log:
- Added equals and hashcode for TCPI
- Started unit tests for Node api
Revision Changes Path
1.1 date: 2006/09/13 17:10:42; author: msurtani; state: Exp;JBossCache/tests/functional/org/jboss/cache/api/NodeAPITest.java
Index: NodeAPITest.java
===================================================================
package org.jboss.cache.api;
import junit.framework.TestCase;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.TreeCacheProxyImpl;
import org.jboss.cache.factories.DefaultCacheFactory;
import javax.transaction.TransactionManager;
/**
* Tests {@link org.jboss.cache.Node}-centric operations
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
* @since 2.0.0
*/
public class NodeAPITest extends TestCase
{
private Node rootNode;
private CacheSPI cache;
private TransactionManager tm;
private static final Fqn A = Fqn.fromString("/a"), B = Fqn.fromString("/b"), C = Fqn.fromString("/c"), D = Fqn.fromString("/d");
protected void setUp()
{
// start a single cache instance
cache = (CacheSPI) new DefaultCacheFactory().createCache("META-INF/local-tx-service.xml");
rootNode = cache.getRoot();
tm = cache.getTransactionManager();
}
protected void tearDown()
{
if (cache != null) cache.stop();
if (rootNode != null) rootNode = null;
}
/**
* Remember, Fqns are relative!!
*/
public void testParentsAndChildren()
{
Node nodeA = rootNode.addChild(A);
Node nodeB = nodeA.addChild(B);
Node nodeC = nodeA.addChild(C);
Node nodeD = rootNode.addChild(D);
assertEquals(rootNode, nodeA.getParent());
assertEquals(nodeA, nodeB.getParent());
assertEquals(nodeA, nodeC.getParent());
assertEquals(rootNode, nodeD.getParent());
assertTrue(rootNode.hasChild(A));
assertFalse(rootNode.hasChild(B));
assertFalse(rootNode.hasChild(C));
assertTrue(rootNode.hasChild(D));
assertTrue(nodeA.hasChild(B));
assertTrue(nodeA.hasChild(C));
assertEquals(nodeA, rootNode.getChild(A));
assertEquals(nodeD, rootNode.getChild(D));
assertEquals(nodeB, nodeA.getChild(B));
assertEquals(nodeC, nodeA.getChild(C));
assertTrue(nodeA.getChildren().contains(nodeB));
assertTrue(nodeA.getChildren().contains(nodeC));
assertEquals(2, nodeA.getChildren().size());
assertTrue(rootNode.getChildren().contains(nodeA));
assertTrue(rootNode.getChildren().contains(nodeD));
assertEquals(2, rootNode.getChildren().size());
}
public void testLocking() throws Exception
{
tm.begin();
Node nodeA = rootNode.addChild(A);
Node nodeB = nodeA.addChild(B);
Node nodeC = nodeB.addChild(C);
assertEquals(3, cache.getNumberOfNodes());
assertEquals(3, ((TreeCacheProxyImpl) cache).treeCache.getNumberOfLocksHeld());
tm.commit();
tm.begin();
assertEquals(0, ((TreeCacheProxyImpl) cache).treeCache.getNumberOfLocksHeld());
nodeC.put("key", "value");
assertEquals(3, ((TreeCacheProxyImpl) cache).treeCache.getNumberOfLocksHeld());
tm.commit();
}
// TODO: MANIK: More Node API tests
}
More information about the jboss-cvs-commits
mailing list