db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/odmg LockingTest.java
Date Wed, 19 Mar 2003 06:52:21 GMT
thma        2003/03/18 22:52:21

  Modified:    src/test/org/apache/ojb/odmg LockingTest.java
  Log:
  add test for optimistic locking
  
  Revision  Changes    Path
  1.7       +39 -0     db-ojb/src/test/org/apache/ojb/odmg/LockingTest.java
  
  Index: LockingTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/LockingTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- LockingTest.java	31 Jan 2003 17:50:02 -0000	1.6
  +++ LockingTest.java	19 Mar 2003 06:52:21 -0000	1.7
  @@ -2,6 +2,8 @@
   
   
   import junit.framework.TestCase;
  +
  +import org.apache.ojb.broker.LockedByVersion;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.TestHelper;
  @@ -13,6 +15,7 @@
   import org.odmg.Implementation;
   import org.odmg.OQLQuery;
   import org.odmg.Transaction;
  +import org.odmg.TransactionAbortedException;
   
   import java.util.List;
   
  @@ -105,6 +108,42 @@
           {
           }
       }
  +
  +	/**
  +	 * test proper treatment of Optimistic Locking in
  +	 * ODMG transactions
  +	 */
  +    public void testOptimisticLockBasics() throws Exception
  +    {
  +        TransactionImpl tx1 = (TransactionImpl) odmg1.newTransaction();
  +        TransactionImpl tx2 = (TransactionImpl) odmg2.newTransaction();
  +
  +        LockedByVersion obj = new LockedByVersion();
  +		
  +
  +        tx1.begin();
  +        
  +        tx1.lock(obj,Transaction.WRITE);
  +		obj.setValue("tx1");
  +		tx1.commit();
  +		
  +		obj.setVersion(obj.getVersion() - 1);
  +		tx2.begin();
  +		tx2.lock(obj,Transaction.WRITE);
  +
  +		obj.setValue("tx2");
  +		boolean signalOLException = false;
  +		try
  +		{
  +			tx2.commit();
  +		}
  +		catch (TransactionAbortedException ex)
  +		{
  +			signalOLException = true;	
  +		}
  +		assertTrue("expected that a OL exception is caught", signalOLException);
  +    }
  +
   
       /**
        * factory method that createa an PerformanceArticle
  
  
  

Mime
View raw message