From: Bryan T. <tho...@us...> - 2006-03-14 21:43:49
|
Update of /cvsroot/cweb/concurrent/src/test/org/CognitiveWeb/concurrent/locking In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10793/src/test/org/CognitiveWeb/concurrent/locking Modified Files: TestAll.java TestTxDag.java Log Message: Developing test cases for the online transaction deadlock detection algorithm. Index: TestTxDag.java =================================================================== RCS file: /cvsroot/cweb/concurrent/src/test/org/CognitiveWeb/concurrent/locking/TestTxDag.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestTxDag.java 14 Mar 2006 16:03:34 -0000 1.1 --- TestTxDag.java 14 Mar 2006 21:43:41 -0000 1.2 *************** *** 44,61 **** /* * Created on Mar 14, 2006 * $Id$ */ package org.CognitiveWeb.concurrent.locking; import junit.framework.TestCase; /** ! * @author thompsonbry */ ! public class TestTxDag extends TestCase { public TestTxDag() { - } --- 44,72 ---- /* * Created on Mar 14, 2006 + * * $Id$ */ package org.CognitiveWeb.concurrent.locking; + import org.apache.log4j.Logger; + import junit.framework.TestCase; /** ! * Test suite for online transaction deadlock algorithm. ! * ! * @version $Id$ ! * @author <a href="mailto:tho...@us...">Bryan Thompson</a> */ ! ! public class TestTxDag extends TestCase ! { ! ! public static final Logger log = Logger.getLogger ! ( TestTxDag.class ! ); public TestTxDag() { } *************** *** 65,67 **** --- 76,226 ---- } + /** + * Test ability to generate unique transaction identifier used by + * {@link TxDag}to index into its internal arrays. This test verifies that + * insert is conditional, that lookup fails if tx was not registered, and + * that we can insert and then lookup a transaction in the DAG. The test + * also verifies that the {@link TxDag#size()}updates as vertices are added + * to the graph and does not update when the vertex already exists in the + * graph. + * + * @todo verify that we can recycle the internal transaction identifiers + * when a transaction is removed from the DAG (either through abort or + * commit actions). + */ + + public void test_lookup_001() + { + + final int CAPACITY = 5; + + TxDag dag = new TxDag( CAPACITY ); + + assertEquals( "capacity", CAPACITY, dag.capacity() ); + assertEquals( "size", 0, dag.size() ); + + /* + * Lookup a vertex that does not exist and verify that the vertex was + * not added. + */ + assertEquals( TxDag.UNKNOWN, dag.lookup( "v1", false ) ); + assertEquals( TxDag.UNKNOWN, dag.lookup( "v1", false ) ); + assertEquals( "size", 0, dag.size() ); + + /* + * Insert a vertex. + */ + final int t1 = dag.lookup( "v1", true ); + assertTrue(TxDag.UNKNOWN != t1 ); + assertEquals( "size", 1, dag.size() ); + + /* + * Lookup that vertex again. + */ + assertEquals( t1, dag.lookup( "v1", false ) ); + assertEquals( "size", 1, dag.size() ); + + log.info( dag.toString() ); + + } + + /** + * Correct rejection test when transaction object is <code>null</code>. + */ + public void test_lookup_002() + { + try { + TxDag dag = new TxDag( 1 ); + dag.lookup(null, false ); + fail( "Expecting: "+IllegalArgumentException.class ); + } + catch( IllegalArgumentException ex ) { + log.info( "Ignoring expected exception: "+ex); + } + } + + /** + * Test capacity limits. This test verifies that insert fails if capacity + * the graph (the maximum #of vertices) would be exceeded. + */ + public void test_capacity_001() + { + + final int CAPACITY = 5; + + TxDag dag = new TxDag( CAPACITY ); + + Object[] tx = new String[ CAPACITY ]; + + assertEquals( "capacity", 0, dag.size() ); + assertEquals( "size", 0, dag.size() ); + + for( int i=0; i<CAPACITY; i++ ) { + + tx[ i ] = ""+i; + dag.lookup( tx[i], true ); + assertEquals( "capacity", CAPACITY, dag.capacity() ); + assertEquals( "size", i+1, dag.size() ); + + } + + assertEquals( "capacity", CAPACITY, dag.size() ); + assertEquals( "size", CAPACITY, dag.size() ); + + try { + dag.lookup( ""+CAPACITY, true ); + fail( "Expecting: "+IllegalStateException.class ); + } + catch( IllegalStateException ex ) { + log.info( "Ignoring expected exception: "+ex); + } + + } + + /** + * Verify that the DAG state is correctly updated when adding a variety of + * WAITS_FOR relationships that do NOT form cycles. + * + * @todo Verify creation of an edge (vertices are created by lookup method). + * + * @todo In 2PL, it is common that a transaction will release all of its + * locks at once. If possible, this operation should be supported in + * such a manner as to make the updates of the {@link TxDag}maximally + * efficient. + * + * @todo Test the special case operations for removing a transactions in + * response to an abort (e.g., as motivated by a deadlock) or by a + * commit. + * + * @todo Implement and test methods to support the release of a single lock + * by a transaction. This feature would be used if a transaction + * chooses to either use non-2PL locking or if the transaction begins + * releasing locks incrementally rather than "all at once." When a + * transaction releases a single lock, all transactions which were + * blocked on that transaction need to have the WAITS_FOR edges + * corresponding to the block removed from the DAG. This operation is + * efficient since the tx which leaves the granted group will not be + * waiting on any other Tx. Therefore an entire row/column of the + * array is simply removed (and counts updated as appropriate). + */ + + public void test_noCycles_001() + { + + } + + /** + * Verify thast the DAG is correctly detecting updates when a set of new + * edges would result in a cycle. + * + * @todo The API for adding edges should probably accept an array of + * vertices for which to create new edges of the WAITS_FOR + * relationship since edges are created only by blocking on a resource + * queue and the tx WAITS_FOR all transactions in the granted group. + */ + public void test_deadlock_001() + { + + } + } Index: TestAll.java =================================================================== RCS file: /cvsroot/cweb/concurrent/src/test/org/CognitiveWeb/concurrent/locking/TestAll.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestAll.java 6 Mar 2006 18:01:48 -0000 1.1 --- TestAll.java 14 Mar 2006 21:43:41 -0000 1.2 *************** *** 84,87 **** --- 84,90 ---- // Test resource DAG (arrangements of database resources into a DAG). suite.addTestSuite(TestResourceDAG.class); + + // Test support for transaction deadlock detection. + suite.addTestSuite(TestTxDag.class); // Tests of lock mode basics. |