logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1104706 - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src: main/java/org/apache/logging/log4j/core/filter/TimeFilter.java test/java/org/apache/logging/log4j/core/filter/TimeFilterTest.java
Date Wed, 18 May 2011 06:45:34 GMT
Author: rgoers
Date: Wed May 18 06:45:34 2011
New Revision: 1104706

URL: http://svn.apache.org/viewvc?rev=1104706&view=rev
Log:
Add unit test for TimeFilter

Added:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/TimeFilterTest.java
      - copied, changed from r1074871, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThresholdFilterTest.java
Modified:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java?rev=1104706&r1=1104705&r2=1104706&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java
Wed May 18 06:45:34 2011
@@ -47,7 +47,7 @@ public class TimeFilter extends FilterBa
     /**
      * Timezone.
      */
-    private final Calendar calendar;
+    private final TimeZone timezone;
 
 
     /**
@@ -69,11 +69,12 @@ public class TimeFilter extends FilterBa
         super(onMatch, onMismatch);
         this.start = start;
         this.end = end;
-        calendar = Calendar.getInstance(tz);
+        timezone = tz;
     }
 
     @Override
     public Result filter(LogEvent event) {
+        Calendar calendar = Calendar.getInstance(timezone);
         calendar.setTimeInMillis(event.getMillis());
         //
         //   get apparent number of milliseconds since midnight
@@ -102,7 +103,7 @@ public class TimeFilter extends FilterBa
                 logger.warn("Error parsing start value " + start, ex);
             }
         }
-        long e = 0;
+        long e = Long.MAX_VALUE;
         if (end != null) {
             stf.setTimeZone(TimeZone.getTimeZone("UTC"));
             try {

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/TimeFilterTest.java
(from r1074871, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThresholdFilterTest.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/TimeFilterTest.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/TimeFilterTest.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThresholdFilterTest.java&r1=1074871&r2=1104706&rev=1104706&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThresholdFilterTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/TimeFilterTest.java
Wed May 18 06:45:34 2011
@@ -23,25 +23,34 @@ import org.apache.logging.log4j.core.Log
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.junit.Test;
 
+import java.util.Calendar;
+import java.util.TimeZone;
+
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertEquals;
 
 /**
  *
  */
-public class ThresholdFilterTest {
+public class TimeFilterTest {
 
     @Test
-    public void testThresholds() {
-        ThresholdFilter filter = ThresholdFilter.createFilter("ERROR", null, null);
+    public void testTime() {
+        TimeFilter filter = TimeFilter.createFilter("02:00:00", "03:00:00", "America/LosAngeles",
null, null);
         filter.start();
         assertTrue(filter.isStarted());
-        assertTrue(filter.filter(null, Level.DEBUG, null, null, (Throwable)null) == Filter.Result.DENY);
+        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("America/LosAngeles"));
+        cal.set(Calendar.HOUR_OF_DAY, 02);
+        long tod = cal.getTimeInMillis();
+        LogEvent event = new Log4jLogEvent(null, null, null, null, null, null, null, null,
null, null, tod);
         assertTrue(filter.filter(null, Level.ERROR, null, null, (Throwable)null) == Filter.Result.NEUTRAL);
-        LogEvent event = new Log4jLogEvent(null, null, null, Level.DEBUG, new SimpleMessage("Test"),
null);
-        assertTrue(filter.filter(event) == Filter.Result.DENY);
-        event = new Log4jLogEvent(null, null, null, Level.ERROR, new SimpleMessage("Test"),
null);        
         assertTrue(filter.filter(event) == Filter.Result.NEUTRAL);
+        cal.roll(Calendar.DAY_OF_MONTH, true);
+        tod = cal.getTimeInMillis();
+        event = new Log4jLogEvent(null, null, null, null, null, null, null, null, null, null,
tod);
+        assertTrue(filter.filter(event) == Filter.Result.NEUTRAL);
+        cal.set(Calendar.HOUR_OF_DAY, 04);
+        tod = cal.getTimeInMillis();
+        event = new Log4jLogEvent(null, null, null, null, null, null, null, null, null, null,
tod);
+        assertTrue(filter.filter(event) == Filter.Result.DENY);
     }
 }



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


Mime
View raw message