ozeigermann    2004/06/02 07:58:01

  Modified:    transaction build.xml
  Added:       transaction/src/test/org/apache/commons/transaction/memory
                        MapWrapperTest.java
  Log:
  Added test for map wrapper. *This is work in progress*
  
  Revision  Changes    Path
  1.1                  
jakarta-commons-sandbox/transaction/src/test/org/apache/commons/transaction/memory/MapWrapperTest.java
  
  Index: MapWrapperTest.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/transaction/src/test/org/apache/commons/transaction/memory/MapWrapperTest.java,v
 1.1 2004/06/02 14:58:01 ozeigermann Exp $
   * $Revision: 1.1 $
   * $Date: 2004/06/02 14:58:01 $
   *
   * ====================================================================
   *
   * Copyright 1999-2002 The Apache Software Foundation 
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * 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 org.apache.commons.transaction.util.LoggerFacade;
  
  /**
   * Tests for FileResourceManager. 
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Oliver Zeigermann</a>
   */
  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 long BARRIER_TIMEOUT = 2000;
  
      // XXX need this, as JUnit seems to print only part of these strings
      private static void report(String should, String is) {
          if (!should.equals(is)) {
              fail("\nWrong output:\n'" + is + "'\nShould be:\n'" + should + "'\n");
          }
      }
  
      public static Test suite() {
          TestSuite suite = new TestSuite(MapWrapperTest.class);
          return suite;
      }
  
      public static void main(java.lang.String[] args) {
          junit.textui.TestRunner.run(suite());
      }
  
      public MapWrapperTest(String testName) {
          super(testName);
      }
  
      public void testBasic() throws Throwable {
                final Map map1 = new HashMap();
                
                final TransactionalMapWrapper txMap1 = new 
TransactionalMapWrapper(map1);
                
                // make sure changes are propagated to wrapped map outside tx
                txMap1.put("key1", "value1");
                report("value1", (String) map1.get("key1"));    
                
                // make sure changes are progated to wrapped map only after commit
                txMap1.startTransaction();
                txMap1.put("key1", "value2");
                report("value1", (String) map1.get("key1"));    
                report("value2", (String) txMap1.get("key1"));  
                txMap1.commitTransaction();
                report("value2", (String) map1.get("key1"));    
                report("value2", (String) txMap1.get("key1"));  
  
                // make sure changes are reverted after rollback
                txMap1.startTransaction();
                txMap1.put("key1", "value3");
                txMap1.rollbackTransaction();
                report("value2", (String) map1.get("key1"));    
                report("value2", (String) txMap1.get("key1"));  
      }
  
        public void xxxtestMulti() throws Throwable {
                final Map map1 = new HashMap();
                final Map map2 = new HashMap();
                
                final TransactionalMapWrapper txMap1 = new 
TransactionalMapWrapper(map1);
                final TransactionalMapWrapper txMap2 = new 
TransactionalMapWrapper(map2);
                
                Thread thread1 = new Thread(new Runnable() {
                        public void run() {
                        }
                }, "Thread1");
  
                // make sure changes are propagated to wrapped map outside tx
                txMap1.put("key1", "value1");
                String value = (String) map1.get("key1");
                assertEquals(value, "value1");  
                
                // make sure changes are progated to wrapped map only after commit
                txMap1.startTransaction();
                
                
        }
  }
  
  
  
  1.4       +1 -0      jakarta-commons-sandbox/transaction/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/transaction/build.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- build.xml 2 Jun 2004 13:29:11 -0000       1.3
  +++ build.xml 2 Jun 2004 14:58:01 -0000       1.4
  @@ -314,6 +314,7 @@
         <classpath refid="classpath" />
         <formatter type="plain" />
         <test name="org.apache.commons.transaction.file.FileResourceManagerTest" 
haltonfailure="yes" />
  +      <test name="org.apache.commons.transaction.memory.MapWrapperTest" 
haltonfailure="yes" />
       </junit>
     </target>
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to