[logback-dev] svn commit: r984 - logback/trunk/logback-access/src/test/java/ch/qos/logback/access/filter
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Wed Nov 22 13:19:12 CET 2006
Author: ceki
Date: Wed Nov 22 13:19:12 2006
New Revision: 984
Added:
logback/trunk/logback-access/src/test/java/ch/qos/logback/access/filter/StatsByDayTest.java
Modified:
logback/trunk/logback-access/src/test/java/ch/qos/logback/access/filter/AccessStatsTest.java
logback/trunk/logback-access/src/test/java/ch/qos/logback/access/filter/PackageTest.java
Log:
refactored Statistical tests
Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/filter/AccessStatsTest.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/filter/AccessStatsTest.java (original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/filter/AccessStatsTest.java Wed Nov 22 13:19:12 2006
@@ -20,65 +20,7 @@
}
public void testBasic() {
-
- CountingFilter cf = new CountingFilter();
- AccessStatsImpl asi = new AccessStatsImpl(cf);
- asi.start();
- // Tue Nov 21 18:05:36 CET 2006
- long now = 1164128736369L;
-
- // test fresh start
- asi.refresh(now);
- assertEquals(0, asi.getLastDaysCount());
- assertEquals(0, asi.getDailyAverage(), 0.01);
-
- // first event
- cf.decide(null);
-
- asi.refresh(now);
- assertEquals(0, asi.getLastDaysCount());
- assertEquals(0.0, asi.getDailyAverage(), 0.01);
-
- long nextDay0 = TimeUtil.computeStartOfNextDay(now);
- nextDay0 += 99;
-
- // there should be one event the next day, avg should also be 1
- asi.refresh(nextDay0);
- assertEquals(1.0, asi.getLastDaysCount(), 0.01);
- assertEquals(1.0, asi.getDailyAverage(), 0.01);
-
- cf.decide(null); // 2nd event
- cf.decide(null); // 3rd event
-
- asi.refresh(nextDay0);
- assertEquals(1, asi.getLastDaysCount());
- assertEquals(1.0, asi.getDailyAverage(), 0.01);
-
- long nextDay1 = TimeUtil.computeStartOfNextDay(nextDay0) + 6747;
- asi.refresh(nextDay1);
- assertEquals(2, asi.getLastDaysCount());
- assertEquals(1.5, asi.getDailyAverage(), 0.01);
-
- nextDay1 += 4444;
- cf.decide(null); // 4th event
- cf.decide(null); // 5th event
- cf.decide(null); // 6th event
- cf.decide(null); // 7th event
-
- asi.refresh(nextDay1);
- // values should remain unchanged
- assertEquals(2, asi.getLastDaysCount());
- assertEquals(1.5, asi.getDailyAverage(), 0.01);
-
-
- long nextDay2 = TimeUtil.computeStartOfNextDay(nextDay1) + 11177;
-
- asi.refresh(nextDay2);
- // values should remain unchanged
- assertEquals(4, asi.getLastDaysCount());
- assertEquals(7.0/3, asi.getDailyAverage(), 0.01);
-
-
-
+ //CountingFilter cf = new CountingFilter();
+ //AccessStatsImpl asi = new AccessStatsImpl(cf);
}
}
Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/filter/PackageTest.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/filter/PackageTest.java (original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/filter/PackageTest.java Wed Nov 22 13:19:12 2006
@@ -16,6 +16,7 @@
public static Test suite() {
TestSuite suite = new TestSuite();
+ suite.addTestSuite(StatsByDayTest.class);
suite.addTestSuite(AccessStatsTest.class);
return suite;
}
Added: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/filter/StatsByDayTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/filter/StatsByDayTest.java Wed Nov 22 13:19:12 2006
@@ -0,0 +1,73 @@
+package ch.qos.logback.access.filter;
+
+import ch.qos.logback.core.util.TimeUtil;
+import junit.framework.TestCase;
+
+public class StatsByDayTest extends TestCase {
+
+ public StatsByDayTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testBasic() {
+ // Tue Nov 21 18:05:36 CET 2006
+ long now = 1164128736369L;
+ StatsByDay statsByDay = new StatsByDay(now);
+
+ int total = 0;
+ // test fresh start
+ statsByDay.update(now, 0);
+ assertEquals(0, statsByDay.getLastCount());
+ assertEquals(0, statsByDay.getAverage(), 0.01);
+
+
+ total++;
+ statsByDay.update(now, total);
+ assertEquals(0, statsByDay.getLastCount());
+ assertEquals(0.0, statsByDay.getAverage(), 0.01);
+
+ long nextDay0 = TimeUtil.computeStartOfNextDay(now);
+ nextDay0 += 99;
+
+ // there should be one event the next day, avg should also be 1
+ statsByDay.update(nextDay0, total);
+ assertEquals(1.0, statsByDay.getLastCount(), 0.01);
+ assertEquals(1.0, statsByDay.getAverage(), 0.01);
+
+ total += 2;
+
+ statsByDay.update(nextDay0, total);
+ assertEquals(1, statsByDay.getLastCount());
+ assertEquals(1.0, statsByDay.getAverage(), 0.01);
+
+ long nextDay1 = TimeUtil.computeStartOfNextDay(nextDay0) + 6747;
+ statsByDay.update(nextDay1, total);
+ assertEquals(2, statsByDay.getLastCount());
+ assertEquals(1.5, statsByDay.getAverage(), 0.01);
+
+ nextDay1 += 4444;
+ total += 4;
+
+ statsByDay.update(nextDay1, total);
+ // values should remain unchanged
+ assertEquals(2, statsByDay.getLastCount());
+ assertEquals(1.5, statsByDay.getAverage(), 0.01);
+
+
+ long nextDay2 = TimeUtil.computeStartOfNextDay(nextDay1) + 11177;
+
+ statsByDay.update(nextDay2, total);
+ // values should remain unchanged
+ assertEquals(4, statsByDay.getLastCount());
+ assertEquals(7.0/3, statsByDay.getAverage(), 0.01);
+ }
+
+}
More information about the logback-dev
mailing list