ceki        2004/12/09 05:27:21

  Modified:    src/java/org/apache/log4j/rolling
                        FixedWindowRollingPolicy.java
                        SizeBasedTriggeringPolicy.java
               tests/src/java/org/apache/log4j/rolling
                        SizeBasedRollingTest.java
  Log:
  - The SizeBasedRolling tests now run correctly on Unix.
  
  - ant runAll should be successful on both Unix and Windows now.
  
  Revision  Changes    Path
  1.3       +20 -17    
logging-log4j/src/java/org/apache/log4j/rolling/FixedWindowRollingPolicy.java
  
  Index: FixedWindowRollingPolicy.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/FixedWindowRollingPolicy.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FixedWindowRollingPolicy.java     8 Dec 2004 21:21:32 -0000       1.2
  +++ FixedWindowRollingPolicy.java     9 Dec 2004 13:27:20 -0000       1.3
  @@ -19,6 +19,7 @@
   import org.apache.log4j.rolling.helper.Compress;
   import org.apache.log4j.rolling.helper.IntegerTokenConverter;
   import org.apache.log4j.rolling.helper.Util;
  +import org.apache.log4j.rolling.helper.FileNamePattern;
   
   import java.io.File;
   
  @@ -94,6 +95,7 @@
       }
       
       if (fileNamePatternStr != null) {
  +      fileNamePattern = new FileNamePattern(fileNamePatternStr);
         determineCompressionMode();
       }
       
  @@ -119,27 +121,28 @@
   
         // Map {(maxIndex - 1), ..., minIndex} to {maxIndex, ..., minIndex+1}
         for (int i = maxIndex - 1; i >= minIndex; i--) {
  -        
  -        Util.rename(
  -          fileNamePattern.convert(i), fileNamePattern.convert(i + 1));
  +       String toRenameStr = fileNamePattern.convert(i);  
  +       File toRename = new File(toRenameStr);
  +       // no point in trying to rename an inexistent file
  +       if(toRename.exists()) {
  +           Util.rename(toRenameStr, fileNamePattern.convert(i + 1));
  +       } else {
  +           getLogger().info("Skipping rollover for inexistent file {}", 
toRenameStr); 
  +          }
         }
   
  -      if (activeFileName != null) {
  -        //move active file name to min
  -        switch (compressionMode) {
  -        case Compress.NONE:
  +
  +      //move active file name to min
  +      switch (compressionMode) {
  +      case Compress.NONE:
             Util.rename(activeFileName, fileNamePattern.convert(minIndex));
             break;
  -        case Compress.GZ:
  -          Compress.GZCompress(
  -            activeFileName, fileNamePattern.convert(minIndex));
  -          break;
  -        
  -        case Compress.ZIP:
  -        Compress.ZIPCompress(
  -          activeFileName, fileNamePattern.convert(minIndex));
  -        break;
  -        }
  +      case Compress.GZ:
  +          Compress.GZCompress(activeFileName, 
fileNamePattern.convert(minIndex));
  +          break;       
  +      case Compress.ZIP:
  +       Compress.ZIPCompress(activeFileName, 
fileNamePattern.convert(minIndex));
  +       break;
         }
       }
     }
  
  
  
  1.7       +3 -2      
logging-log4j/src/java/org/apache/log4j/rolling/SizeBasedTriggeringPolicy.java
  
  Index: SizeBasedTriggeringPolicy.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/SizeBasedTriggeringPolicy.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SizeBasedTriggeringPolicy.java    27 Feb 2004 16:47:33 -0000      1.6
  +++ SizeBasedTriggeringPolicy.java    9 Dec 2004 13:27:21 -0000       1.7
  @@ -20,10 +20,11 @@
   
   
   /**
  + * SizeBasedTriggeringPolicy looks at size of the file being
  + * currently written to.
  + * 
    * @author Ceki Gülcü
    *
  - * To change the template for this generated type comment go to
  - * Window>Preferences>Java>Code Generation>Code and Comments
    */
   public class SizeBasedTriggeringPolicy implements TriggeringPolicy {
     long maxFileSize = 10 * 1024 * 1024; // let 10 MB the default max size
  
  
  
  1.8       +4 -4      
logging-log4j/tests/src/java/org/apache/log4j/rolling/SizeBasedRollingTest.java
  
  Index: SizeBasedRollingTest.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/tests/src/java/org/apache/log4j/rolling/SizeBasedRollingTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SizeBasedRollingTest.java 8 Dec 2004 21:03:12 -0000       1.7
  +++ SizeBasedRollingTest.java 9 Dec 2004 13:27:21 -0000       1.8
  @@ -158,8 +158,8 @@
        if(!isWindows()) {
   
         assertTrue(Compare.compare("output/sbr-test3.log",  
"witness/rolling/sbr-test3.log"));
  -      assertTrue(Compare.compare("output/sbr-test3.0.gz", 
"witness/rolling/sbr-test3.0.gz"));
  -      assertTrue(Compare.compare("output/sbr-test3.1.gz", 
"witness/rolling/sbr-test3.1.gz"));
  +      assertTrue(Compare.gzCompare("output/sbr-test3.0.gz", 
"witness/rolling/sbr-test3.0.gz"));
  +      assertTrue(Compare.gzCompare("output/sbr-test3.1.gz", 
"witness/rolling/sbr-test3.1.gz"));
        }
   
   
  @@ -172,8 +172,8 @@
     public static Test suite() {
       TestSuite suite = new TestSuite();
   
  -    //suite.addTest(new SizeBasedRollingTest("test1"));
  -    //suite.addTest(new SizeBasedRollingTest("test2"));
  +    suite.addTest(new SizeBasedRollingTest("test1"));
  +    suite.addTest(new SizeBasedRollingTest("test2"));
       suite.addTest(new SizeBasedRollingTest("test3"));
   
       return suite;
  
  
  

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

Reply via email to