db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olegn...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/otm LockTestBase.java LockTestCommittedReads.java LockTestRepeatableReads.java LockTestSerializable.java LockTestUncommittedReads.java AllTests.java
Date Sun, 25 May 2003 20:59:53 GMT
olegnitz    2003/05/25 13:59:53

  Modified:    src/test/org/apache/ojb/otm AllTests.java
  Added:       src/test/org/apache/ojb/otm LockTestBase.java
                        LockTestCommittedReads.java
                        LockTestRepeatableReads.java
                        LockTestSerializable.java
                        LockTestUncommittedReads.java
  Log:
  OTM transaction isolation tests (based on ODMG tests)
  
  Revision  Changes    Path
  1.6       +4 -0      db-ojb/src/test/org/apache/ojb/otm/AllTests.java
  
  Index: AllTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/otm/AllTests.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AllTests.java	8 Apr 2003 20:19:30 -0000	1.5
  +++ AllTests.java	25 May 2003 20:59:53 -0000	1.6
  @@ -30,6 +30,10 @@
       {
           TestSuite suite = new TestSuite();
           suite.addTest(new TestSuite(OtmExamples.class));
  +        suite.addTest(new TestSuite(LockTestUncommittedReads.class));
  +        suite.addTest(new TestSuite(LockTestCommittedReads.class));
  +        suite.addTest(new TestSuite(LockTestRepeatableReads.class));
  +        suite.addTest(new TestSuite(LockTestSerializable.class));
           return suite;
       }
   
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/otm/LockTestBase.java
  
  Index: LockTestBase.java
  ===================================================================
  package org.apache.ojb.otm;
  
  /**
   * This is the base abstract class for all isolation TestSuites
   * based on the ODMG locking documentation
   */
  
  import junit.framework.TestCase;
  import org.apache.ojb.broker.Article;
  import org.apache.ojb.broker.Identity;
  import org.apache.ojb.broker.PersistenceBrokerFactory;
  import org.apache.ojb.otm.core.Transaction;
  import org.apache.ojb.otm.lock.ObjectLock;
  import org.apache.ojb.otm.lock.LockingException;
  import org.apache.ojb.otm.lock.isolation.TransactionIsolation;
  import org.apache.ojb.otm.lock.wait.NoWaitStrategy;
  import org.apache.ojb.otm.lock.wait.TimeoutStrategy;
  
  public abstract class LockTestBase extends TestCase
  {
      protected TestKit _kit;
      protected OTMConnection _conn1;
      protected OTMConnection _conn2;
      protected Transaction _tx1;
      protected Transaction _tx2;
      protected ObjectLock _lock;
      protected TransactionIsolation _isolation;
  
      public LockTestBase(String name)
      {
          super(name);
      }
  
      protected abstract TransactionIsolation newIsolation();
  
      public void setUp()
      {
          _kit = TestKit.getTestInstance();
          _kit.setLockWaitStrategy(new NoWaitStrategy());
          _isolation = newIsolation();
          try
          {
              _conn1 = _kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
              _tx1 = _kit.getTransaction(_conn1);
              _tx1.begin();
  
              _conn2 = _kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
              _tx2 = _kit.getTransaction(_conn2);
              _tx2.begin();
  
              Article obj =  Article.createInstance();
              obj.setArticleId(333);
              _lock = new ObjectLock(_conn1.getIdentity(obj));
          }
          catch (Exception ex)
          {
              ex.printStackTrace();
          }
  
      }
  
      protected boolean readLock(Transaction tx)
      {
          try
          {
              _isolation.readLock(tx, _lock);
              return true;
          }
          catch (LockingException ex)
          {
              return false;
          }
      }
  
      protected boolean writeLock(Transaction tx)
      {
          try
          {
              _isolation.writeLock(tx, _lock);
              return true;
          }
          catch (LockingException ex)
          {
              return false;
          }
      }
  
      protected boolean releaseLock(Transaction tx)
      {
          _lock.releaseLock(tx);
          return true;
      }
  
      public void tearDown()
      {
          try
          {
              _tx1.rollback();
              _conn1 = null;
  
              _tx2.rollback();
              _conn2 = null;
          }
          catch (Throwable t)
          {
          }
          _kit.setLockWaitStrategy(new TimeoutStrategy());
      }
  }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/otm/LockTestCommittedReads.java
  
  Index: LockTestCommittedReads.java
  ===================================================================
  package org.apache.ojb.otm;
  
  /**
   * This is the TestSuite based on the ODMG locking documentation
   */
  import org.apache.ojb.otm.lock.isolation.TransactionIsolation;
  import org.apache.ojb.otm.lock.isolation.ReadCommittedIsolation;
  
  public class LockTestCommittedReads extends LockTestBase
  {
      private static Class CLASS = LockTestCommittedReads.class;
  
      public LockTestCommittedReads(String name)
      {
          super(name);
      }
  
      protected TransactionIsolation newIsolation()
      {
          return new ReadCommittedIsolation();
      }
  
      /**
       * Test 1
       */
      public void testSingleReadLock()
      {
          assertTrue(readLock(_tx1));
      }
  
      /**
       * Test3
       */
      public void testReadThenWrite()
      {
          assertTrue(readLock(_tx1));
          assertTrue(writeLock(_tx1));
      }
  
      /**
       * Test 4
       */
      public void testSingleWriteLock()
      {
          assertTrue(writeLock(_tx1));
      }
  
      /**
       * Test 5
       */
      public void testWriteThenRead()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(readLock(_tx1));
      }
  
      /**
       * Test 6
       */
      public void testMultipleReadLock()
      {
          assertTrue(readLock(_tx1));
          assertTrue(readLock(_tx2));
      }
  
      /**
       * Test 8
       */
      public void testWriteWithExistingReader()
      {
          assertTrue(readLock(_tx1));
          assertTrue(writeLock(_tx2));
      }
  
      /**
       * Test 10
       */
      public void testWriteWithMultipleReaders()
      {
          assertTrue(readLock(_tx1));
          assertTrue(readLock(_tx2));
          assertTrue(writeLock(_tx2));
      }
  
      /**
       * Test 12
       */
      public void testWriteWithMultipleReadersOn1()
      {
          assertTrue(readLock(_tx1));
          assertTrue(readLock(_tx2));
          assertTrue(writeLock(_tx1));
      }
  
      /**
       * Test 13
       */
      public void testReadWithExistingWriter()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(!readLock(_tx2));
      }
  
      /**
       * Test 14
       */
      public void testMultipleWriteLock()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(!writeLock(_tx2));
      }
  
      /**
       * Test 15
       */
      public void testReleaseReadLock()
      {
          assertTrue(readLock(_tx1));
          assertTrue(releaseLock(_tx1));
          assertTrue(writeLock(_tx2));
      }
  
      /**
       * Test 17
       */
      public void testReleaseWriteLock()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(releaseLock(_tx1));
          assertTrue(writeLock(_tx2));
      }
  
      /**
       * Test 18
       */
      public void testReadThenRead()
      {
          assertTrue(readLock(_tx1));
          assertTrue(readLock(_tx1));
      }
  
      public static void main(String[] args)
      {
          String[] arr = {CLASS.getName()};
          junit.textui.TestRunner.main(arr);
      }
  }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/otm/LockTestRepeatableReads.java
  
  Index: LockTestRepeatableReads.java
  ===================================================================
  package org.apache.ojb.otm;
  
  /**
   * This is the TestSuite based on the ODMG locking documentation
   */
  import org.apache.ojb.otm.lock.isolation.TransactionIsolation;
  import org.apache.ojb.otm.lock.isolation.RepeatableReadIsolation;
  
  public class LockTestRepeatableReads extends LockTestBase
  {
      private static Class CLASS = LockTestRepeatableReads.class;
  
      public LockTestRepeatableReads(String name)
      {
          super(name);
      }
  
      protected TransactionIsolation newIsolation()
      {
          return new RepeatableReadIsolation();
      }
  
      /**
       * Test 1
       */
      public void testSingleReadLock()
      {
          assertTrue(readLock(_tx1));
      }
  
      /**
       * Test3
       */
      public void testReadThenWrite()
      {
          assertTrue(readLock(_tx1));
          assertTrue(writeLock(_tx1));
      }
  
      /**
       * Test 4
       */
      public void testSingleWriteLock()
      {
          assertTrue(writeLock(_tx1));
      }
  
      /**
       * Test 5
       */
      public void testWriteThenRead()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(readLock(_tx1));
      }
  
      /**
       * Test 6
       */
      public void testMultipleReadLock()
      {
          assertTrue(readLock(_tx1));
          assertTrue(readLock(_tx2));
      }
  
      /**
       * Test 8
       */
      public void testWriteWithExistingReader()
      {
          assertTrue(readLock(_tx1));
          assertTrue(!writeLock(_tx2));
      }
  
      /**
       * Test 10
       */
      public void testWriteWithMultipleReaders()
      {
          assertTrue(readLock(_tx1));
          assertTrue(readLock(_tx2));
          assertTrue(!writeLock(_tx2));
      }
  
      /**
       * Test 12
       */
      public void testWriteWithMultipleReadersOn1()
      {
          assertTrue(readLock(_tx1));
          assertTrue(readLock(_tx2));
          assertTrue(!writeLock(_tx1));
      }
  
      /**
       * Test 13
       */
      public void testReadWithExistingWriter()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(!readLock(_tx2));
      }
  
      /**
       * Test 14
       */
      public void testMultipleWriteLock()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(!writeLock(_tx2));
      }
  
      /**
       * Test 15
       */
      public void testReleaseReadLock()
      {
          assertTrue(readLock(_tx1));
          assertTrue(releaseLock(_tx1));
          assertTrue(writeLock(_tx2));
      }
  
      /**
       * Test 17
       */
      public void testReleaseWriteLock()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(releaseLock(_tx1));
          assertTrue(writeLock(_tx2));
      }
  
      /**
       * Test 18
       */
      public void testReadThenRead()
      {
          assertTrue(readLock(_tx1));
          assertTrue(readLock(_tx1));
      }
  
      public static void main(String[] args)
      {
          String[] arr = {CLASS.getName()};
          junit.textui.TestRunner.main(arr);
      }
  }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/otm/LockTestSerializable.java
  
  Index: LockTestSerializable.java
  ===================================================================
  package org.apache.ojb.otm;
  
  /**
   * This is the TestSuite based on the ODMG locking documentation
   */
  import org.apache.ojb.otm.lock.isolation.TransactionIsolation;
  import org.apache.ojb.otm.lock.isolation.SerializableIsolation;
  
  public class LockTestSerializable extends LockTestBase
  {
      private static Class CLASS = LockTestSerializable.class;
  
      public LockTestSerializable(String name)
      {
          super(name);
      }
  
      protected TransactionIsolation newIsolation()
      {
          return new SerializableIsolation();
      }
  
      /**
       * Test 1
       */
      public void testSingleReadLock()
      {
          assertTrue(readLock(_tx1));
      }
  
      /**
       * Test3
       */
      public void testReadThenWrite()
      {
          assertTrue(readLock(_tx1));
          assertTrue(writeLock(_tx1));
      }
  
      /**
       * Test 4
       */
      public void testSingleWriteLock()
      {
          assertTrue(writeLock(_tx1));
      }
  
      /**
       * Test 5
       */
      public void testWriteThenRead()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(readLock(_tx1));
      }
  
      /**
       * Test 6
       */
      public void testMultipleReadLock()
      {
          assertTrue(readLock(_tx1));
          assertTrue(!readLock(_tx2));
      }
  
      /**
       * Test 8
       */
      public void testWriteWithExistingReader()
      {
          assertTrue(readLock(_tx1));
          assertTrue(!writeLock(_tx2));
      }
  
      /**
       * Test 10
       */
      public void testWriteWithMultipleReaders()
      {
          assertTrue(readLock(_tx1));
          assertTrue(!readLock(_tx2));
          assertTrue(!writeLock(_tx2));
      }
  
      /**
       * Test 12
       */
      public void testWriteWithMultipleReadersOn1()
      {
          assertTrue(readLock(_tx1));
          assertTrue(!readLock(_tx2));
          assertTrue(writeLock(_tx1));
      }
  
      /**
       * Test 13
       */
      public void testReadWithExistingWriter()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(!readLock(_tx2));
      }
  
      /**
       * Test 14
       */
      public void testMultipleWriteLock()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(!writeLock(_tx2));
      }
  
      /**
       * Test 15
       */
      public void testReleaseReadLock()
      {
          assertTrue(readLock(_tx1));
          assertTrue(releaseLock(_tx1));
          assertTrue(writeLock(_tx2));
      }
  
      /**
       * Test 17
       */
      public void testReleaseWriteLock()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(releaseLock(_tx1));
          assertTrue(writeLock(_tx2));
      }
  
      /**
       * Test 18
       */
      public void testReadThenRead()
      {
          assertTrue(readLock(_tx1));
          assertTrue(readLock(_tx1));
      }
  
      public static void main(String[] args)
      {
          String[] arr = {CLASS.getName()};
          junit.textui.TestRunner.main(arr);
      }
  
  }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/otm/LockTestUncommittedReads.java
  
  Index: LockTestUncommittedReads.java
  ===================================================================
  package org.apache.ojb.otm;
  
  /**
   * This is the TestSuite based on the ODMG locking documentation
   */
  import org.apache.ojb.otm.lock.isolation.TransactionIsolation;
  import org.apache.ojb.otm.lock.isolation.ReadUncommittedIsolation;
  
  public class LockTestUncommittedReads extends LockTestBase
  {
      private static Class CLASS = LockTestUncommittedReads.class;
  
      public LockTestUncommittedReads(String name)
      {
          super(name);
      }
  
      protected TransactionIsolation newIsolation()
      {
          return new ReadUncommittedIsolation();
      }
  
      /**
       * Test 1
       */
      public void testSingleReadLock()
      {
          assertTrue(readLock(_tx1));
      }
  
      /**
       * Test3
       */
      public void testReadThenWrite()
      {
          assertTrue(readLock(_tx1));
          assertTrue(writeLock(_tx1));
      }
  
      /**
       * Test 4
       */
      public void testSingleWriteLock()
      {
          assertTrue(writeLock(_tx1));
      }
  
      /**
       * Test 5
       */
      public void testWriteThenRead()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(readLock(_tx1));
      }
  
      /**
       * Test 6
       */
      public void testMultipleReadLock()
      {
          assertTrue(readLock(_tx1));
          assertTrue(readLock(_tx2));
      }
  
      /**
       * Test 8
       */
      public void testWriteWithExistingReader()
      {
          assertTrue(readLock(_tx1));
          assertTrue(writeLock(_tx2));
      }
  
      /**
       * Test 10
       */
      public void testWriteWithMultipleReaders()
      {
          assertTrue(readLock(_tx1));
          assertTrue(readLock(_tx2));
          assertTrue(writeLock(_tx2));
      }
  
      /**
       * Test 12
       */
      public void testWriteWithMultipleReadersOn1()
      {
          assertTrue(readLock(_tx1));
          assertTrue(readLock(_tx2));
          assertTrue(writeLock(_tx1));
      }
  
      /**
       * Test 13
       */
      public void testReadWithExistingWriter()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(readLock(_tx2));
      }
  
      /**
       * Test 14
       */
      public void testMultipleWriteLock()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(!writeLock(_tx2));
      }
  
      /**
       * Test 15
       */
      public void testReleaseReadLock()
      {
          assertTrue(readLock(_tx1));
          assertTrue(releaseLock(_tx1));
          assertTrue(writeLock(_tx2));
      }
  
      /**
       * Test 17
       */
      public void testReleaseWriteLock()
      {
          assertTrue(writeLock(_tx1));
          assertTrue(releaseLock(_tx1));
          assertTrue(writeLock(_tx2));
      }
  
      /**
       * Test 18
       */
      public void testReadThenRead()
      {
          assertTrue(readLock(_tx1));
          assertTrue(readLock(_tx1));
      }
  
      public static void main(String[] args)
      {
          String[] arr = {CLASS.getName()};
          junit.textui.TestRunner.main(arr);
      }
  }
  
  
  

Mime
View raw message