jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1381338 - in /jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb: migrate/AbstractTestTransaction.java transaction/AbstractTestTransSeq.java transaction/TestTransactionTDB.java
Date Wed, 05 Sep 2012 20:19:21 GMT
Author: andy
Date: Wed Sep  5 20:19:20 2012
New Revision: 1381338

URL: http://svn.apache.org/viewvc?rev=1381338&view=rev
Log:
Test for different errorenous transaction sequences

Modified:
    jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/migrate/AbstractTestTransaction.java
    jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/transaction/AbstractTestTransSeq.java
    jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransactionTDB.java

Modified: jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/migrate/AbstractTestTransaction.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/migrate/AbstractTestTransaction.java?rev=1381338&r1=1381337&r2=1381338&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/migrate/AbstractTestTransaction.java
(original)
+++ jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/migrate/AbstractTestTransaction.java
Wed Sep  5 20:19:20 2012
@@ -18,18 +18,28 @@
 
 package com.hp.hpl.jena.tdb.migrate;
 
+import static com.hp.hpl.jena.query.ReadWrite.READ ;
+import static com.hp.hpl.jena.query.ReadWrite.WRITE ;
+import org.junit.AfterClass ;
+import org.junit.BeforeClass ;
 import org.junit.Test ;
 import org.openjena.atlas.junit.BaseTest ;
+import org.openjena.atlas.logging.Log ;
 
 import com.hp.hpl.jena.query.Dataset ;
 import com.hp.hpl.jena.query.ReadWrite ;
+import com.hp.hpl.jena.sparql.JenaTransactionException ;
+import com.hp.hpl.jena.tdb.sys.SystemTDB ;
 
 public abstract class AbstractTestTransaction extends BaseTest
 {
+    @BeforeClass public static void beforeClassLoggingOff() { Log.disable(SystemTDB.errlog.getName())
; } 
+    @AfterClass public static void afterClassLoggingOn()    { Log.enable(SystemTDB.errlog.getName(),
"info") ; }
+    
     //MIGRATE
     protected abstract Dataset create() ;
     
-    @Test public void transaction_00()
+    @Test public void transaction_err_00()
     {
         Dataset ds = create() ;
         assertTrue(ds.supportsTransactions()) ;
@@ -131,6 +141,43 @@ public abstract class AbstractTestTransa
         read2(ds) ;
     }
 
+    // if parameterised tests had decent naming ...
+    @Test
+    public void transaction_err_01()    { testBeginBegin(WRITE, WRITE) ; }
+
+    @Test
+    public void transaction_err_02()    { testBeginBegin(WRITE, READ) ; }
+
+    @Test
+    public void transaction_err_03()    { testBeginBegin(READ, READ) ; }
+
+    @Test
+    public void transaction_err_04()    { testBeginBegin(READ, WRITE) ; }
+
+    @Test 
+    public void transaction_err_05()    { testCommitCommit(READ) ; }
+
+    @Test 
+    public void transaction_err_06()    { testCommitCommit(WRITE) ; }
+
+    @Test 
+    public void transaction_err_07()    { testCommitAbort(READ) ; }
+
+    @Test 
+    public void transaction_err_08()    { testCommitAbort(WRITE) ; }
+
+    @Test 
+    public void transaction_err_09()    { testAbortAbort(READ) ; }
+
+    @Test 
+    public void transaction_err_10()    { testAbortAbort(WRITE) ; }
+
+    @Test 
+    public void transaction_err_11()    { testAbortCommit(READ) ; }
+
+    @Test 
+    public void transaction_err_12()    { testAbortCommit(WRITE) ; }
+
     private void read1(Dataset ds)
     {
         ds.begin(ReadWrite.READ) ;
@@ -156,5 +203,70 @@ public abstract class AbstractTestTransa
         assertFalse(ds.isInTransaction()) ;
         ds.end() ;
     }
+    
+
+    // Error conditions that should be detected.
+    
+    private void testBeginBegin(ReadWrite mode1, ReadWrite mode2)
+    {
+        Dataset ds = create() ;
+        ds.begin(mode1) ;
+        try {
+            ds.begin(mode2) ;
+            fail("Expected transaction exception - begin-begin ("+mode1+", "+mode2+")") ;
+        } catch (JenaTransactionException ex)
+        { ds.end() ; }
+    }
+    
+    private void testCommitCommit(ReadWrite mode)
+    {
+        Dataset ds = create() ;
+        ds.begin(mode) ;
+        ds.commit() ;
+        try {
+            ds.commit() ;
+            fail("Expected transaction exception - commit-commit("+mode+")") ;
+        } catch (JenaTransactionException ex)
+        { ds.end() ; }
+    }
+    
+    private void testCommitAbort(ReadWrite mode)
+    {
+        Dataset ds = create() ;
+        ds.begin(mode) ;
+        ds.commit() ;
+        try {
+            ds.abort() ;
+            fail("Expected transaction exception - commit-commit("+mode+")") ;
+        } catch (JenaTransactionException ex)
+        { ds.end() ; }
+    }
+
+    private void testAbortAbort(ReadWrite mode)
+    {
+        Dataset ds = create() ;
+        ds.begin(mode) ;
+        ds.abort() ;
+        try {
+            ds.abort() ;
+            fail("Expected transaction exception - commit-commit("+mode+")") ;
+        } catch (JenaTransactionException ex)
+        { ds.end() ; }
+    }
+
+
+    private void testAbortCommit(ReadWrite mode)
+    {
+        Dataset ds = create() ;
+        ds.begin(mode) ;
+        ds.abort() ;
+        try {
+            ds.commit() ;
+            fail("Expected transaction exception - commit-commit("+mode+")") ;
+        } catch (JenaTransactionException ex)
+        { ds.end() ; }
+    }
+    
+
 }
 

Modified: jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/transaction/AbstractTestTransSeq.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/transaction/AbstractTestTransSeq.java?rev=1381338&r1=1381337&r2=1381338&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/transaction/AbstractTestTransSeq.java
(original)
+++ jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/transaction/AbstractTestTransSeq.java
Wed Sep  5 20:19:20 2012
@@ -38,7 +38,7 @@ import com.hp.hpl.jena.tdb.sys.SystemTDB
 public abstract class AbstractTestTransSeq extends BaseTest
 {
     @BeforeClass public static void beforeClassLoggingOff() { Log.disable(SystemTDB.errlog.getName())
; } 
-    @AfterClass public static void afterClassLoggingOn()   { Log.enable(SystemTDB.errlog.getName(),
"info") ; }
+    @AfterClass public static void afterClassLoggingOn()    { Log.enable(SystemTDB.errlog.getName(),
"info") ; }
     
     // Per test unique-ish.
     long x = System.currentTimeMillis() ;
@@ -55,6 +55,8 @@ public abstract class AbstractTestTransS
 
     // Basics.
     
+    
+    
     @Test public void trans_01()
     {
         StoreConnection sConn = getStoreConnection() ;

Modified: jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransactionTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransactionTDB.java?rev=1381338&r1=1381337&r2=1381338&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransactionTDB.java
(original)
+++ jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransactionTDB.java
Wed Sep  5 20:19:20 2012
@@ -18,6 +18,8 @@
 
 package com.hp.hpl.jena.tdb.transaction;
 
+import static com.hp.hpl.jena.query.ReadWrite.READ ;
+import static com.hp.hpl.jena.query.ReadWrite.WRITE ;
 import org.junit.After ;
 import org.junit.Before ;
 import org.junit.Test ;
@@ -25,7 +27,6 @@ import org.openjena.atlas.lib.FileOps ;
 
 import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.query.Dataset ;
-import com.hp.hpl.jena.query.ReadWrite ;
 import com.hp.hpl.jena.sparql.sse.SSE ;
 import com.hp.hpl.jena.tdb.ConfigTest ;
 import com.hp.hpl.jena.tdb.StoreConnection ;
@@ -67,20 +68,19 @@ public class TestTransactionTDB extends 
         Dataset ds1 = create() ;
         Dataset ds2 = create() ;
         
-        ds1.begin(ReadWrite.WRITE) ;
+        ds1.begin(WRITE) ;
         ds1.getDefaultModel().getGraph().add(triple1) ; 
         
-        ds2.begin(ReadWrite.READ) ;
+        ds2.begin(READ) ;
         assertTrue(ds2.getDefaultModel().isEmpty()) ;
         ds2.commit() ;
         
         ds1.commit() ;
 
-        ds2.begin(ReadWrite.READ) ;
+        ds2.begin(READ) ;
         assertFalse(ds2.getDefaultModel().isEmpty()) ;
         assertEquals(1, ds2.getDefaultModel().size()) ;
         ds2.commit() ;
     }
-
 }
 



Mime
View raw message