[logback-dev] svn commit: r797 - in logback/trunk/logback-classic: . src/test/java/ch/qos/logback/classic src/test/java/ch/qos/logback/classic/boolex src/test/java/ch/qos/logback/classic/db src/test/java/ch/qos/logback/classic/html

noreply.ceki at qos.ch noreply.ceki at qos.ch
Fri Oct 27 06:23:34 CEST 2006


Author: ceki
Date: Fri Oct 27 06:23:34 2006
New Revision: 797

Added:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/PackageTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/PackageTest.java
Modified:
   logback/trunk/logback-classic/mdcfilter.xml
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java

Log:

- improvements to tests

Modified: logback/trunk/logback-classic/mdcfilter.xml
==============================================================================
--- logback/trunk/logback-classic/mdcfilter.xml	(original)
+++ logback/trunk/logback-classic/mdcfilter.xml	Fri Oct 27 06:23:34 2006
@@ -1,11 +1,12 @@
 <configuration>
 
   <appender name="STDOUT"
-    class="ch.qos.logback.core.ConsoleAppender">
+            class="ch.qos.logback.core.ConsoleAppender">
     <layout class="ch.qos.logback.classic.PatternLayout">
       <param name="Pattern"
         value="%-4relative [%thread] %-5level %X{testKey} - %msg%n" />
     </layout>
+
     <filter class="ch.qos.logback.core.filter.EvaluatorFilter">  
       <Name>myFilter</Name>
       <OnMatch>DENY</OnMatch>
@@ -13,11 +14,9 @@
         <Name>mdcEvaluator</Name>
         <Expression>mdc!=null &amp;&amp; "val".equals(mdc.get("key"))</Expression>
       </Evaluator>
-     
     </filter>
   </appender>
 
-
   <root>
     <level value="debug" />
     <appender-ref ref="STDOUT" />

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllTest.java	Fri Oct 27 06:23:34 2006
@@ -21,9 +21,13 @@
     suite.addTest(ch.qos.logback.classic.PackageTest.suite());
     suite.addTest(ch.qos.logback.classic.control.PackageTest.suite());
     suite.addTest(ch.qos.logback.classic.joran.PackageTest.suite());
+    suite.addTest(ch.qos.logback.classic.boolex.PackageTest.suite());
+
+    suite.addTest(ch.qos.logback.classic.html.PackageTest.suite()); 
     suite.addTest(ch.qos.logback.classic.net.PackageTest.suite());
     suite.addTest(ch.qos.logback.classic.pattern.PackageTest.suite()); 
-    
+    suite.addTest(ch.qos.logback.classic.db.PackageTest.suite()); 
+
     return suite;
   }
 }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java	Fri Oct 27 06:23:34 2006
@@ -4,16 +4,15 @@
 
 import org.slf4j.MarkerFactory;
 
-import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.boolex.JaninoEventEvaluator;
 import ch.qos.logback.classic.pattern.ConverterTest;
 import ch.qos.logback.classic.spi.LoggingEvent;
 import ch.qos.logback.core.boolex.EvaluationException;
+import ch.qos.logback.core.boolex.JaninoEventEvaluatorBase;
 import ch.qos.logback.core.boolex.Matcher;
 
-
 public class JaninoEventEvaluatorTest extends TestCase {
 
   LoggerContext loggerContext = new LoggerContext();
@@ -31,8 +30,9 @@
   }
 
   LoggingEvent makeLoggingEvent(Exception ex) {
-    LoggingEvent e = new LoggingEvent(ch.qos.logback.core.pattern.FormattingConverter.class
-        .getName(), logger, Level.INFO, "Some message", ex, null);
+    LoggingEvent e = new LoggingEvent(
+        ch.qos.logback.core.pattern.FormattingConverter.class.getName(),
+        logger, Level.INFO, "Some message", ex, null);
     return e;
   }
 
@@ -103,15 +103,16 @@
     try {
       jee.evaluate(event);
       fail("We should not reach this point");
-    }  catch(EvaluationException ee) {
-      
+    } catch (EvaluationException ee) {
+
     }
   }
-  
+
   public void testComplex() throws Exception {
 
     JaninoEventEvaluator jee = new JaninoEventEvaluator();
-    jee.setExpression("level >= INFO && x.matches(message) && marker.contains(\"BLUE\")");
+    jee
+        .setExpression("level >= INFO && x.matches(message) && marker.contains(\"BLUE\")");
     jee.setContext(loggerContext);
     jee.addMatcher(matcherX);
     jee.start();
@@ -121,7 +122,54 @@
     assertTrue(jee.evaluate(event));
   }
 
-  static final long LEN = 100 * 1000;
+  /**
+   * check that evaluator with bogis exp does not start
+   * 
+   * @throws Exception
+   */
+  public void testBogusExp1() {
+
+    JaninoEventEvaluator jee = new JaninoEventEvaluator();
+    jee.setExpression("mzzzz.get(\"key\").equals(null)");
+    jee.setContext(loggerContext);
+    jee.setName("bogus");
+    jee.start();
+
+    assertFalse(jee.isStarted());
+
+    // StatusPrinter.print(loggerContext);
+    // LoggingEvent event = makeLoggingEvent(null);
+    // event.setMarker(MarkerFactory.getMarker("BLUE"));
+    //    
+    // jee.evaluate(event);
+  }
+
+  // check that eval stops after errors
+  public void testBogusExp2() {
+
+    JaninoEventEvaluator jee = new JaninoEventEvaluator();
+    jee.setExpression("mdc.get(\"key\").equals(null)");
+    jee.setContext(loggerContext);
+    jee.setName("bogus");
+    jee.start();
+
+    assertTrue(jee.isStarted());
+
+    LoggingEvent event = makeLoggingEvent(null);
+
+    for (int i = 0; i < JaninoEventEvaluatorBase.ERROR_THRESHOLD; i++) {
+      try {
+        jee.evaluate(event);
+        fail("should throw an exception");
+      } catch (EvaluationException e) {
+      }
+    }
+    // after a few attempts the evaluator should stop
+    assertFalse(jee.isStarted());
+
+  }
+
+  static final long LEN = 10 * 1000;
 
   // with 6 parameters 400 nanos
   // with 7 parameters 460 nanos (all levels + selected fields from
@@ -130,7 +178,6 @@
   void loop(JaninoEventEvaluator jee, String msg) throws Exception {
     LoggingEvent event = makeLoggingEvent(null);
     final long start = System.nanoTime();
-    final long LEN = 500 * 1000;
     for (int i = 0; i < LEN; i++) {
       jee.evaluate(event);
     }
@@ -156,5 +203,5 @@
 
     loop(jee, "x.matches(message): ");
   }
- 
+
 }

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/PackageTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/PackageTest.java	Fri Oct 27 06:23:34 2006
@@ -0,0 +1,21 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 1999-2006, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.classic.boolex;
+
+import junit.framework.*;
+
+public class PackageTest extends TestCase {
+
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTestSuite(JaninoEventEvaluatorTest.class);
+    return suite;
+  }
+}
\ No newline at end of file

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java	Fri Oct 27 06:23:34 2006
@@ -0,0 +1,21 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 1999-2006, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.classic.db;
+
+import junit.framework.*;
+
+public class PackageTest extends TestCase {
+
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTestSuite(DBAppenderTest.class);
+    return suite;
+  }
+}
\ No newline at end of file

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/PackageTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/PackageTest.java	Fri Oct 27 06:23:34 2006
@@ -0,0 +1,21 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 1999-2006, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.classic.html;
+
+import junit.framework.*;
+
+public class PackageTest extends TestCase {
+
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTestSuite(HTMLLayoutTest.class);
+    return suite;
+  }
+}
\ No newline at end of file



More information about the logback-dev mailing list