You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jo...@apache.org on 2007/01/07 00:37:32 UTC

svn commit: r493596 - in /jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction: file/FileResourceManagerTest.java memory/MapWrapperTest.java memory/OptimisticMapWrapperTest.java memory/PessimisticMapWrapperTest.java

Author: joerg
Date: Sat Jan  6 15:37:31 2007
New Revision: 493596

URL: http://svn.apache.org/viewvc?view=rev&rev=493596
Log:
modified tests to use CommonsLoggingLogger to make tests work with JDK 1.3,
minor clean up (direct static access to constants + removed unused local variables)

Modified:
    jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/file/FileResourceManagerTest.java
    jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/MapWrapperTest.java
    jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/OptimisticMapWrapperTest.java
    jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/PessimisticMapWrapperTest.java

Modified: jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/file/FileResourceManagerTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/file/FileResourceManagerTest.java?view=diff&rev=493596&r1=493595&r2=493596
==============================================================================
--- jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/file/FileResourceManagerTest.java (original)
+++ jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/file/FileResourceManagerTest.java Sat Jan  6 15:37:31 2007
@@ -1,10 +1,4 @@
 /*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//transaction/src/test/org/apache/commons/transaction/file/FileResourceManagerTest.java,v 1.3 2005/01/13 01:34:25 ozeigermann Exp $
- * $Revision$
- * $Date$
- *
- * ====================================================================
- *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -19,9 +13,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *
  */
-
 package org.apache.commons.transaction.file;
 
 import java.io.BufferedReader;
@@ -32,7 +24,6 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
-import java.util.logging.Logger;
 
 import javax.transaction.Status;
 
@@ -40,8 +31,11 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.commons.transaction.util.CommonsLoggingLogger;
 import org.apache.commons.transaction.util.FileHelper;
-import org.apache.commons.transaction.util.Jdk14Logger;
 import org.apache.commons.transaction.util.LoggerFacade;
 import org.apache.commons.transaction.util.RendezvousBarrier;
 
@@ -52,8 +46,8 @@
  */
 public class FileResourceManagerTest extends TestCase {
 
-    private static final Logger logger = Logger.getLogger(FileResourceManagerTest.class.getName());
-    private static final LoggerFacade sLogger = new Jdk14Logger(logger); 
+    private static final Log log = LogFactory.getLog(FileResourceManagerTest.class.getName());
+    private static final LoggerFacade sLogger = new CommonsLoggingLogger(log); 
 
     private static final String STORE = "tmp/store";
     private static final String WORK = "tmp/work";
@@ -185,18 +179,6 @@
         }
     }
 
-    private static final void deleteInDir(String dirPath, String[] fileNames) {
-        File dir = new File(dirPath);
-
-        if (dir.isDirectory()) {
-            for (int i = 0; i < fileNames.length; i++) {
-                String fileName = fileNames[i];
-                File file = new File(dir, fileName);
-                file.delete();
-            }
-        }
-    }
-
     private static final void checkIsEmpty(String dirPath) {
         checkExactlyContains(dirPath, null);
     }
@@ -590,7 +572,7 @@
         FileResourceManager.TransactionContext context = rm.getContext(txId);
         // needing synchronization in order not to interfer with shutdown thread
         synchronized (context) {
-            logger.fine("Committing Tx " + txId);
+            sLogger.logFine("Committing Tx " + txId);
 
             context.status = Status.STATUS_COMMITTING;
             context.saveState();
@@ -629,7 +611,7 @@
     }
 
     public void testConflict() throws Throwable {
-        logger.info("Checking concurrent transaction features");
+        sLogger.logInfo("Checking concurrent transaction features");
 
         reset();
         createInitialFiles();
@@ -662,7 +644,7 @@
                         rm.commitTransaction("tx1");
                     } catch (InterruptedException ie) {
                     } catch (ResourceManagerException e) {
-                        assertEquals(e.getStatus(), ResourceManagerException.ERR_DEAD_LOCK);
+                        assertEquals(e.getStatus(), ResourceManagerErrorCodes.ERR_DEAD_LOCK);
                         deadlockCnt++;
                         try {
                             rm.rollbackTransaction("tx1");
@@ -697,7 +679,7 @@
                 rm.deleteResource("tx2", "key2");
                 rm.commitTransaction("tx2");
             } catch (ResourceManagerException e) {
-                assertEquals(e.getStatus(), ResourceManagerException.ERR_DEAD_LOCK);
+                assertEquals(e.getStatus(), ResourceManagerErrorCodes.ERR_DEAD_LOCK);
                 deadlockCnt++;
                 try {
                     rm.rollbackTransaction("tx2");
@@ -726,7 +708,7 @@
     }
 
     public void testCopyRec() throws Throwable {
-        logger.info("Checking file copy");
+        sLogger.logInfo("Checking file copy");
         reset();
         createInitialFiles();
         FileHelper.copyRec(new File(INITIAL_FILES[0]), new File(STORE + "/olli/NewFile"));

Modified: jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/MapWrapperTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/MapWrapperTest.java?view=diff&rev=493596&r1=493595&r2=493596
==============================================================================
--- jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/MapWrapperTest.java (original)
+++ jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/MapWrapperTest.java Sat Jan  6 15:37:31 2007
@@ -1,10 +1,4 @@
 /*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//transaction/src/test/org/apache/commons/transaction/memory/MapWrapperTest.java,v 1.1 2004/11/18 23:27:19 ozeigermann Exp $
- * $Revision$
- * $Date$
- *
- * ====================================================================
- *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -19,20 +13,24 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *
  */
-
 package org.apache.commons.transaction.memory;
 
-import junit.framework.*;
-
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.logging.*;
 
-import org.apache.commons.transaction.util.Jdk14Logger;
+import javax.transaction.Status;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.commons.transaction.util.CommonsLoggingLogger;
 import org.apache.commons.transaction.util.LoggerFacade;
 import org.apache.commons.transaction.util.RendezvousBarrier;
 
@@ -43,8 +41,8 @@
  */
 public class MapWrapperTest extends TestCase {
 
-    private static final Logger logger = Logger.getLogger(MapWrapperTest.class.getName());
-    private static final LoggerFacade sLogger = new Jdk14Logger(logger);
+    private static final Log log = LogFactory.getLog(MapWrapperTest.class.getName());
+    private static final LoggerFacade sLogger = new CommonsLoggingLogger(log);
 
     protected static final long BARRIER_TIMEOUT = 20000;
 
@@ -91,7 +89,7 @@
 
     public void testBasic() throws Throwable {
 
-        logger.info("Checking basic transaction features");
+        sLogger.logInfo("Checking basic transaction features");
 
         final Map map1 = new HashMap();
 
@@ -124,7 +122,7 @@
 
     public void testContainsKeyWithNullValue() throws Throwable {
 
-        logger.info("Checking containsKey returns true when the value is null");
+        sLogger.logInfo("Checking containsKey returns true when the value is null");
 
         final Map map1 = new HashMap();
 
@@ -155,7 +153,7 @@
 
     public void testComplex() throws Throwable {
 
-        logger.info("Checking advanced and complex transaction features");
+        sLogger.logInfo("Checking advanced and complex transaction features");
 
         final Map map1 = new HashMap();
 
@@ -166,14 +164,14 @@
         txMap1.put("key2", "value2");
 
         // let's see if we have all values:
-        logger.info("Checking if global values are present");
+        sLogger.logInfo("Checking if global values are present");
 
         assertTrue(txMap1.containsValue("value1"));
         assertTrue(txMap1.containsValue("value2"));
         assertFalse(txMap1.containsValue("novalue"));
 
         // ... and all keys
-        logger.info("Checking if global keys are present");
+        sLogger.logInfo("Checking if global keys are present");
         assertTrue(txMap1.containsKey("key1"));
         assertTrue(txMap1.containsKey("key2"));
         assertFalse(txMap1.containsKey("nokey"));
@@ -184,7 +182,7 @@
         txMap1.put("key4", "value4");
 
         // let's see if we have all values:
-        logger.info("Checking if values inside transactions are present");
+        sLogger.logInfo("Checking if values inside transactions are present");
         assertTrue(txMap1.containsValue("value1"));
         assertTrue(txMap1.containsValue("value2"));
         assertTrue(txMap1.containsValue("value3"));
@@ -192,7 +190,7 @@
         assertFalse(txMap1.containsValue("novalue"));
 
         // ... and all keys
-        logger.info("Checking if keys inside transactions are present");
+        sLogger.logInfo("Checking if keys inside transactions are present");
         assertTrue(txMap1.containsKey("key1"));
         assertTrue(txMap1.containsKey("key2"));
         assertTrue(txMap1.containsKey("key3"));
@@ -200,7 +198,7 @@
         assertFalse(txMap1.containsKey("nokey"));
 
         // now let's delete some old stuff
-        logger.info("Checking remove inside transactions");
+        sLogger.logInfo("Checking remove inside transactions");
         txMap1.remove("key1");
         assertFalse(txMap1.containsKey("key1"));
         assertFalse(txMap1.containsValue("value1"));
@@ -214,7 +212,7 @@
         assertNull(txMap1.get("key3"));
         assertEquals(2, txMap1.size());
 
-        logger.info("Checking remove and propagation after commit");
+        sLogger.logInfo("Checking remove and propagation after commit");
         txMap1.commitTransaction();
 
         txMap1.remove("key1");
@@ -229,7 +227,7 @@
 
     public void testSets() throws Throwable {
 
-        logger.info("Checking set opertaions");
+        sLogger.logInfo("Checking set opertaions");
 
         final Map map1 = new HashMap();
 
@@ -330,7 +328,7 @@
     }
 
     public void testMulti() throws Throwable {
-        logger.info("Checking concurrent transaction features");
+        sLogger.logInfo("Checking concurrent transaction features");
 
         final Map map1 = new HashMap();
 
@@ -350,7 +348,7 @@
                     txMap1.commitTransaction();
                     afterCommitBarrier.call();
                 } catch (InterruptedException e) {
-                    logger.log(Level.WARNING, "Thread interrupted", e);
+                    sLogger.logWarning("Thread interrupted", e);
                     afterCommitBarrier.reset();
                     beforeCommitBarrier.reset();
                 }
@@ -378,15 +376,15 @@
     }
 
     public void testTxControl() throws Throwable {
-        logger.info("Checking advanced transaction control (heavily used in JCA implementation)");
+        sLogger.logInfo("Checking advanced transaction control (heavily used in JCA implementation)");
 
         final Map map1 = new HashMap();
 
         final TransactionalMapWrapper txMap1 = getNewWrapper(map1);
 
-        assertEquals(txMap1.getTransactionState(), TransactionalMapWrapper.STATUS_NO_TRANSACTION);
+        assertEquals(txMap1.getTransactionState(), Status.STATUS_NO_TRANSACTION);
         txMap1.startTransaction();
-        assertEquals(txMap1.getTransactionState(), TransactionalMapWrapper.STATUS_ACTIVE);
+        assertEquals(txMap1.getTransactionState(), Status.STATUS_ACTIVE);
 
         assertTrue(txMap1.isReadOnly());
         txMap1.put("key", "value");
@@ -404,7 +402,7 @@
         }
         assertTrue(failed);
         txMap1.rollbackTransaction();
-        assertEquals(txMap1.getTransactionState(), TransactionalMapWrapper.STATUS_NO_TRANSACTION);
+        assertEquals(txMap1.getTransactionState(), Status.STATUS_NO_TRANSACTION);
 
         txMap1.startTransaction();
         final TransactionalMapWrapper.TxContext ctx = txMap1.suspendTransaction();

Modified: jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/OptimisticMapWrapperTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/OptimisticMapWrapperTest.java?view=diff&rev=493596&r1=493595&r2=493596
==============================================================================
--- jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/OptimisticMapWrapperTest.java (original)
+++ jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/OptimisticMapWrapperTest.java Sat Jan  6 15:37:31 2007
@@ -1,10 +1,4 @@
 /*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//transaction/src/test/org/apache/commons/transaction/memory/OptimisticMapWrapperTest.java,v 1.1 2004/11/18 23:27:19 ozeigermann Exp $
- * $Revision$
- * $Date$
- *
- * ====================================================================
- *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -19,18 +13,19 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *
  */
-
 package org.apache.commons.transaction.memory;
 
-import junit.framework.*;
-
 import java.util.HashMap;
 import java.util.Map;
-import java.util.logging.*;
 
-import org.apache.commons.transaction.util.Jdk14Logger;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.commons.transaction.util.CommonsLoggingLogger;
 import org.apache.commons.transaction.util.LoggerFacade;
 import org.apache.commons.transaction.util.RendezvousBarrier;
 
@@ -41,8 +36,8 @@
  */
 public class OptimisticMapWrapperTest extends MapWrapperTest {
 
-    private static final Logger logger = Logger.getLogger(OptimisticMapWrapperTest.class.getName());
-    private static final LoggerFacade sLogger = new Jdk14Logger(logger);
+    private static final Log log = LogFactory.getLog(OptimisticMapWrapperTest.class.getName());
+    private static final LoggerFacade sLogger = new CommonsLoggingLogger(log);
 
     public static Test suite() {
         TestSuite suite = new TestSuite(OptimisticMapWrapperTest.class);
@@ -75,7 +70,7 @@
 	}
 
     public void testMulti() throws Throwable {
-        logger.info("Checking concurrent transaction features");
+        log.info("Checking concurrent transaction features");
 
         final Map map1 = new HashMap();
 
@@ -95,7 +90,7 @@
                     txMap1.commitTransaction();
                     afterCommitBarrier.call();
                 } catch (InterruptedException e) {
-                    logger.log(Level.WARNING, "Thread interrupted", e);
+                    sLogger.logWarning("Thread interrupted", e);
                     afterCommitBarrier.reset();
                     beforeCommitBarrier.reset();
                 }
@@ -123,7 +118,7 @@
     }
 
 	public void testConflict() throws Throwable {
-		logger.info("Checking concurrent transaction features");
+		log.info("Checking concurrent transaction features");
 
 		final Map map1 = new HashMap();
 
@@ -143,7 +138,7 @@
 					txMap1.commitTransaction();
 					afterCommitBarrier.call();
 				} catch (InterruptedException e) {
-					logger.log(Level.WARNING, "Thread interrupted", e);
+					sLogger.logWarning("Thread interrupted", e);
 					afterCommitBarrier.reset();
 					beforeCommitBarrier.reset();
 				}

Modified: jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/PessimisticMapWrapperTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/PessimisticMapWrapperTest.java?view=diff&rev=493596&r1=493595&r2=493596
==============================================================================
--- jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/PessimisticMapWrapperTest.java (original)
+++ jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/PessimisticMapWrapperTest.java Sat Jan  6 15:37:31 2007
@@ -1,10 +1,4 @@
 /*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//transaction/src/test/org/apache/commons/transaction/memory/PessimisticMapWrapperTest.java,v 1.3 2005/01/13 01:34:25 ozeigermann Exp $
- * $Revision$
- * $Date$
- *
- * ====================================================================
- *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -19,19 +13,20 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *
  */
-
 package org.apache.commons.transaction.memory;
 
-import junit.framework.*;
-
 import java.util.HashMap;
 import java.util.Map;
-import java.util.logging.*;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import org.apache.commons.transaction.locking.LockException;
-import org.apache.commons.transaction.util.Jdk14Logger;
+import org.apache.commons.transaction.util.CommonsLoggingLogger;
 import org.apache.commons.transaction.util.LoggerFacade;
 import org.apache.commons.transaction.util.RendezvousBarrier;
 
@@ -42,8 +37,8 @@
  */
 public class PessimisticMapWrapperTest extends MapWrapperTest {
 
-    private static final Logger logger = Logger.getLogger(PessimisticMapWrapperTest.class.getName());
-    private static final LoggerFacade sLogger = new Jdk14Logger(logger);
+    private static final Log log = LogFactory.getLog(PessimisticMapWrapperTest.class.getName());
+    private static final LoggerFacade sLogger = new CommonsLoggingLogger(log);
 
     protected static final long TIMEOUT = Long.MAX_VALUE;
 
@@ -80,17 +75,12 @@
     }
 
     public void testMulti() throws Throwable {
-        logger.info("Checking concurrent transaction features");
+        sLogger.logInfo("Checking concurrent transaction features");
 
         final Map map1 = new HashMap();
 
         final PessimisticMapWrapper txMap1 = (PessimisticMapWrapper) getNewWrapper(map1);
 
-        final RendezvousBarrier beforeCommitBarrier =
-            new RendezvousBarrier("Before Commit", 2, BARRIER_TIMEOUT, sLogger);
-
-        final RendezvousBarrier afterCommitBarrier = new RendezvousBarrier("After Commit", 2, BARRIER_TIMEOUT, sLogger);
-
         Thread thread1 = new Thread(new Runnable() {
             public void run() {
                 txMap1.startTransaction();
@@ -123,7 +113,7 @@
     }
 
     public void testConflict() throws Throwable {
-        logger.info("Checking concurrent transaction features");
+        sLogger.logInfo("Checking concurrent transaction features");
 
         final Map map1 = new HashMap();
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org