[logback-dev] svn commit: r1948 - in logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic: . control jmx

noreply.ceki at qos.ch noreply.ceki at qos.ch
Thu Nov 6 18:16:38 CET 2008


Author: ceki
Date: Thu Nov  6 18:16:37 2008
New Revision: 1948

Added:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/ScenarioBasedLoggerContextTest.java
      - copied, changed from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/DynamicLoggerContextTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ScenarioAction.java
      - copied, changed from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ControlAction.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ScenarioRandomUtil.java
      - copied, changed from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/RandomUtil.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/TestScenario.java
      - copied, changed from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/Scenario.java
Removed:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/DynamicLoggerContextTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ControlAction.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/RandomUtil.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/Scenario.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ScenarioMakerTest.java
Modified:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PackageTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ControlLoggerContext.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/CreateLogger.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/RandomUtilTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ScenarioMaker.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/SetLevel.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/JMXConfiguratorTest.java

Log:

Refactoring test cases in relation to LBCLASSIC-83.

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PackageTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PackageTest.java	Thu Nov  6 18:16:37 2008
@@ -17,7 +17,7 @@
     TestSuite suite = new TestSuite();
     suite.addTest(new JUnit4TestAdapter(LoggerContextTest.class));
     suite.addTest(new JUnit4TestAdapter(LoggerPerfTest.class));
-    suite.addTest(new JUnit4TestAdapter(DynamicLoggerContextTest.class));
+    suite.addTest(new JUnit4TestAdapter(ScenarioBasedLoggerContextTest.class));
     suite.addTest(new JUnit4TestAdapter(PatternLayoutTest.class));
     suite.addTest(new JUnit4TestAdapter(LoggerTest.class));
     suite.addTest(new JUnit4TestAdapter(LoggerSerializationTest.class));

Copied: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/ScenarioBasedLoggerContextTest.java (from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/DynamicLoggerContextTest.java)
==============================================================================
--- /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/DynamicLoggerContextTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/ScenarioBasedLoggerContextTest.java	Thu Nov  6 18:16:37 2008
@@ -12,57 +12,57 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
 import org.junit.Test;
 
-import ch.qos.logback.classic.control.ControlAction;
 import ch.qos.logback.classic.control.ControlLogger;
 import ch.qos.logback.classic.control.ControlLoggerContext;
 import ch.qos.logback.classic.control.CreateLogger;
-import ch.qos.logback.classic.control.Scenario;
+import ch.qos.logback.classic.control.ScenarioAction;
 import ch.qos.logback.classic.control.ScenarioMaker;
 import ch.qos.logback.classic.control.SetLevel;
+import ch.qos.logback.classic.control.TestScenario;
 
 
-public class DynamicLoggerContextTest  {
+public class ScenarioBasedLoggerContextTest  {
   LoggerContext lc;
 
   
   @Test
-  public void test3() {
-    dynaTest(3);
+  public void testLen3() {
+    doScenarioedTest(3);
   }
 
   @Test
-  public void test30() {
-    dynaTest(30);
+  public void testLength_30() {
+    doScenarioedTest(30);
   }
 
   @Test
-  public void test1000() {
-    dynaTest(1000);
+  public void testLength_20000() {
+    doScenarioedTest(20*1000);
   }
-  //public void test50000() {
-    //dynaTest(50000);
-  //}
 
+  @Test
+  public void testLengthLong() {
+    doScenarioedTest(500*1000);
+  }
 
-  private void dynaTest(int len) {
+  private void doScenarioedTest(int len) {
     LoggerContext lc = new LoggerContext();
     ControlLoggerContext controlContext = new ControlLoggerContext();
-    Scenario s = ScenarioMaker.makeTypeBScenario(len);
+    TestScenario s = ScenarioMaker.makeRealisticCreationScenario(len);
     List actionList = s.getActionList();
     int size = actionList.size();
     for (int i = 0; i < size; i++) {
-      ControlAction action = (ControlAction) actionList.get(i);
+      ScenarioAction action = (ScenarioAction) actionList.get(i);
       if (action instanceof CreateLogger) {
         CreateLogger cl = (CreateLogger) action;
         lc.getLogger(cl.getLoggerName());
         controlContext.getLogger(cl.getLoggerName());
-      } else {
+      } else if (action instanceof SetLevel) {
         SetLevel sl = (SetLevel) action;
         Logger l = lc.getLogger(sl.getLoggerName());
         ControlLogger controlLogger = controlContext.getLogger(sl.getLoggerName());
@@ -71,29 +71,29 @@
       }
     }
 
-    compare(controlContext, lc);
+    compareLoggerContexts(controlContext, lc);
   }
 
-  void compare(ControlLoggerContext controlLC, LoggerContext lc) {
-    Map controlLoggerMap = controlLC.getLoggerMap();
+  void compareLoggerContexts(ControlLoggerContext controlLC, LoggerContext lc) {
+    Map<String, ControlLogger> controlLoggerMap = controlLC.getLoggerMap();
 
     assertEquals(controlLoggerMap.size()+1, lc.size());
 
-    for (Iterator i = controlLoggerMap.keySet().iterator(); i.hasNext();) {
-      String loggerName = (String) i.next();
+    for (String loggerName: controlLoggerMap.keySet()) {
+        
       Logger logger = lc.exists(loggerName);
       ControlLogger controlLogger = (ControlLogger) controlLoggerMap.get(loggerName);
       if (logger == null) {
-        throw new IllegalStateException("HLoggerr" + loggerName + " should exist");
+        throw new IllegalStateException("logger" + loggerName + " should exist");
       }
       assertEquals(loggerName, logger.getName());
       assertEquals(loggerName, controlLogger.getName());
 
-      assertCompare(controlLogger, logger);
+      compareLoggers(controlLogger, logger);
     }
   }
 
-  void assertCompare(ControlLogger controlLogger, Logger logger) {
+  void compareLoggers(ControlLogger controlLogger, Logger logger) {
     assertEquals(controlLogger.getName(), logger.getName());
     assertEquals(controlLogger.getEffectiveLevel(), logger.getEffectiveLevel());
 

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ControlLoggerContext.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ControlLoggerContext.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ControlLoggerContext.java	Thu Nov  6 18:16:37 2008
@@ -16,15 +16,18 @@
 import ch.qos.logback.classic.Level;
 
 /**
- * LoggerContext quite optimized for logger retrieval.
+ * This logger context quite optimized for logger retrieval.
  * 
- * It uses a single loggerMap where the key is the logger name and 
- * the value is the logger.
+ * <p>It uses a single loggerMap where the key is the logger name and the value
+ * is the logger.
  * 
- * This approach acts a lower limit for what is acheivable for low memory usage 
- * as well as low creation/retreival times. However, this simplicity also results 
- * in slow effective level evaluation, the most frequently exercised part of the API.
+ * <p>This approach acts a lower limit for what is achievable for low memory
+ * usage as well as low creation/retrieval times. However, this simplicity also
+ * results in slow effective level evaluation, the most frequently exercised
+ * part of the API.
  * 
+ * <p>This class is expected to contain correct results, and serve to verify
+ * the correctness of a more sophisticated implementation.
  * 
  * @author ceki
  */
@@ -33,8 +36,8 @@
   private ControlLogger root;
   //
   // Hashtable loggerMap = new Hashtable();
-   Map<String, ControlLogger> loggerMap = new HashMap<String, ControlLogger>();
-   
+  Map<String, ControlLogger> loggerMap = new HashMap<String, ControlLogger>();
+
   public ControlLoggerContext() {
     this.root = new ControlLogger("root", null);
     this.root.setLevel(Level.DEBUG);
@@ -42,7 +45,7 @@
 
   /**
    * Return this contexts root logger
-   *
+   * 
    * @return
    */
   public ControlLogger getRootLogger() {
@@ -75,7 +78,8 @@
       while (true) {
         i = name.indexOf(ClassicGlobal.LOGGER_SEPARATOR, i);
         if (i == -1) {
-          //System.out.println("FINAL-Creating logger named [" + name + "] with parent " + parent.getName());
+          // System.out.println("FINAL-Creating logger named [" + name + "] with
+          // parent " + parent.getName());
           cl = new ControlLogger(name, parent);
           loggerMap.put(name, cl);
           return cl;
@@ -83,7 +87,8 @@
           String parentName = name.substring(0, i);
           ControlLogger p = (ControlLogger) loggerMap.get(parentName);
           if (p == null) {
-            //System.out.println("INTERMEDIARY-Creating logger [" + parentName + "] with parent " + parent.getName());
+            // System.out.println("INTERMEDIARY-Creating logger [" + parentName
+            // + "] with parent " + parent.getName());
             p = new ControlLogger(parentName, parent);
             loggerMap.put(parentName, p);
           }
@@ -95,7 +100,7 @@
     }
   }
 
-  public Map getLoggerMap() {
+  public Map<String, ControlLogger> getLoggerMap() {
     return loggerMap;
   }
 }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/CreateLogger.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/CreateLogger.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/CreateLogger.java	Thu Nov  6 18:16:37 2008
@@ -10,7 +10,7 @@
 package ch.qos.logback.classic.control;
 
 
-public class CreateLogger extends ControlAction {
+public class CreateLogger extends ScenarioAction {
 
   final String loggerName;
 

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/RandomUtilTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/RandomUtilTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/RandomUtilTest.java	Thu Nov  6 18:16:37 2008
@@ -21,7 +21,7 @@
     int len = 100000;
     int AVERAGE = 5;
     for(int i = 0; i < len; i++) {
-      sum += RandomUtil.gaussianAsPositiveInt(AVERAGE, 2);
+      sum += ScenarioRandomUtil.gaussianAsPositiveInt(AVERAGE, 2);
     }
 
     double resultingAverage =   sum/(1.0*len);

Copied: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ScenarioAction.java (from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ControlAction.java)
==============================================================================
--- /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ControlAction.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ScenarioAction.java	Thu Nov  6 18:16:37 2008
@@ -1,14 +1,14 @@
 /**
- * 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.
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 2000-2008, 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.control;
 
-public class ControlAction {
+public class ScenarioAction {
 
 }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ScenarioMaker.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ScenarioMaker.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ScenarioMaker.java	Thu Nov  6 18:16:37 2008
@@ -1,80 +1,92 @@
-/** 
- * LOGBack: the reliable, fast and flexible logging library for Java.
- *
- * Copyright (C) 1999-2005, QOS.ch, LOGBack.com
- *
- * 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.
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 2000-2008, 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.control;
 
 import java.util.LinkedList;
 
 import ch.qos.logback.classic.ClassicGlobal;
+import ch.qos.logback.classic.Level;
 
 public class ScenarioMaker {
 
-
   private final static int AVERAGE_LOGGER_DEPTH = 4;
   private final static int LOGGER_DEPT_DEV = 2;
-
+  // the frequency of a set levelInt event for every create logger event
+  private final static int CREATE_LOGGER_TO_SET_LEVEL_FREQUENCY = 5;
+  private final static int SECOND_SET_LEVEL_FREQUENCY = 3;
+  
+  
   /**
-   * Makes a scenario with len logger creations. Logger names are generated independently such that the overwhelming
-   * majority of logger names will unrelated to each other. Each logger creation may be followed with a randomly
-   * generated set levelInt action on that logger.
-   *
+   * Makes a scenario with len logger creations. Logger names are generated
+   * independently such that the overwhelming majority of logger names will be
+   * unrelated to each other. Each logger creation may be followed with a
+   * randomly generated set levelInt action on that logger.
+   * 
    * @param len
    * @return
    */
-  static public Scenario makeTypeAScenario(int len) {
-    Scenario scenario = new Scenario();
+  static public TestScenario makeTypeAScenario(int len) {
+    TestScenario scenario = new TestScenario();
     ;
     for (int i = 0; i < len; i++) {
-      String loggerName = RandomUtil.randomLoggerName(AVERAGE_LOGGER_DEPTH, LOGGER_DEPT_DEV);
-      scenario.addAction(new CreateLogger(loggerName));
+      String loggerName = ScenarioRandomUtil.randomLoggerName(AVERAGE_LOGGER_DEPTH,
+          LOGGER_DEPT_DEV);
+      scenario.add(new CreateLogger(loggerName));
     }
     return scenario;
   }
 
-  static public Scenario makeTypeBScenario(int len) {
-    Scenario scenario = new Scenario();
+  static public TestScenario makeRealisticCreationScenario(int len) {
+    TestScenario scenario = new TestScenario();
     LinkedList<String> queue = new LinkedList<String>();
     int loggerCreationCount = 0;
 
     // add an empty string to get going
     queue.add("");
 
-    // add another string to reduce the probability of having an 
-    // empty queue (this happens when we create several leaf nodes
-    // successively
-    queue.add("xxxx");
-    
     while (loggerCreationCount < len) {
-      if (queue.isEmpty()) {
-        throw new IllegalStateException("Queue cannot be empty.");
-      }
-
       String loggerName = (String) queue.removeFirst();
-      //System.out.println("logger name is [" + loggerName + "]");
-      int childrenCount = RandomUtil.randomChildrenCount(loggerName);
-      //System.out.println("children count is " + childrenCount);
-      // add only leaf loggers
-      if (childrenCount == 0) {
-        scenario.addAction(new CreateLogger(loggerName));
+      int randomChildrenCount = ScenarioRandomUtil.randomChildrenCount(loggerName);
+     
+      if (randomChildrenCount == 0) {
+        scenario.add(new CreateLogger(loggerName));
+        addSetLevelSubScenario(scenario, loggerName);
         loggerCreationCount++;
       } else {
-        for (int i = 0; i < childrenCount; i++) {
+        for (int i = 0; i < randomChildrenCount; i++) {
           String childName;
           if (loggerName.equals("")) {
-            childName = RandomUtil.randomId();
+            childName = ScenarioRandomUtil.randomId();
           } else {
-            childName = loggerName + ClassicGlobal.LOGGER_SEPARATOR + RandomUtil.randomId();
+            childName = loggerName + ClassicGlobal.LOGGER_SEPARATOR
+                + ScenarioRandomUtil.randomId();
           }
           queue.add(childName);
+          addSetLevelSubScenario(scenario, loggerName);
+          loggerCreationCount++;
         }
       }
     }
     return scenario;
   }
+  
+  static void addSetLevelSubScenario(TestScenario scenario, String loggerName) {
+    if(ScenarioRandomUtil.oneInFreq(CREATE_LOGGER_TO_SET_LEVEL_FREQUENCY)) {
+      Level l = ScenarioRandomUtil.randomLevel();
+      scenario.add(new SetLevel(l, loggerName));
+      if(ScenarioRandomUtil.oneInFreq(SECOND_SET_LEVEL_FREQUENCY)) {
+        l = ScenarioRandomUtil.randomLevel();
+        scenario.add(new SetLevel(l, loggerName));
+      }
+    }
+  }
+  
+  
 }
\ No newline at end of file

Copied: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ScenarioRandomUtil.java (from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/RandomUtil.java)
==============================================================================
--- /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/RandomUtil.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/ScenarioRandomUtil.java	Thu Nov  6 18:16:37 2008
@@ -13,7 +13,7 @@
 
 import ch.qos.logback.classic.Level;
 
-public class RandomUtil {
+public class ScenarioRandomUtil {
   private final static long SEED = 74130;
 
   private final static Random random = new Random(SEED);
@@ -28,18 +28,23 @@
   }
 
   public static Level randomLevel() {
-    int rl = random.nextInt(4);
+    int rl = random.nextInt(6);
     switch (rl) {
-      case 0:
-        return Level.DEBUG;
-      case 1:
-        return Level.INFO;
-      case 2:
-        return Level.WARN;
-      case 3:
-        return Level.ERROR;
-      default:
-        throw new IllegalStateException("rl should have been a value between 0 to 3, but it is " + rl);
+    case 0:
+      return null;
+    case 1:
+      return Level.TRACE;
+    case 2:
+      return Level.DEBUG;
+    case 3:
+      return Level.INFO;
+    case 4:
+      return Level.WARN;
+    case 5:
+      return Level.ERROR;
+    default:
+      throw new IllegalStateException(
+          "rl should have been a value between 0 to 5, but it is " + rl);
     }
   }
 
@@ -69,18 +74,20 @@
 
   /**
    * Approximate a gaussian distrib with only only positive integer values
-   *
+   * 
    * @param average
    * @param stdDeviation
    * @return
    */
   public static int gaussianAsPositiveInt(int average, int stdDeviation) {
     if (average < 1) {
-      throw new IllegalArgumentException("The average must not be smaller than 1.");
+      throw new IllegalArgumentException(
+          "The average must not be smaller than 1.");
     }
 
     if (stdDeviation < 1) {
-      throw new IllegalArgumentException("The stdDeviation must not be smaller than 1.");
+      throw new IllegalArgumentException(
+          "The stdDeviation must not be smaller than 1.");
     }
 
     double d = random.nextGaussian() * stdDeviation + average;
@@ -92,23 +99,21 @@
   }
 
   /**
-   * Returns 3 for root, 3 for children of root, 9 for offspring of generation 2 and 3, and for generations 4
-   * and later, return 0 wuth probabbility 0.5 and a guassion (average=AVERAGE_CHILDREN_COUNT) with probability 0.5.
-   *
+   * Returns 3 for root, 3 for children of root, 9 for offspring of generation 2
+   * and 3, and for generations 4 and later, return 0 with probability 0.5 and a
+   * gaussian (average=AVERAGE_CHILDREN_COUNT) with probability 0.5.
+   * 
    * @param name
    * @return
    */
   public static int randomChildrenCount(String name) {
-    if ("".equals(name)) {
-      return 3;
-    }
     int dots = dotCount(name);
-    if (dots == 1) {
+    if (dots <= 1) {
       return 3;
     } else if (dots == 2 || dots == 3) {
       return 9;
     } else {
-      if (hasChildren(0.5)) {
+      if (shouldHaveChildrenWithProbabilitz(0.5)) {
         return gaussianAsPositiveInt(AVERAGE_CHILDREN_COUNT, CHILDREN_COUNT_VAR);
       } else {
         return 0;
@@ -119,13 +124,14 @@
 
   /**
    * Returns true with probability p.
-   *
+   * 
    * @param p
    * @return
    */
-  static boolean hasChildren(double p) {
+  static boolean shouldHaveChildrenWithProbabilitz(double p) {
     if (p < 0 || p > 1.0) {
-      throw new IllegalArgumentException("p must be a value between 0 and 1.0, it was " + p + " instead.");
+      throw new IllegalArgumentException(
+          "p must be a value between 0 and 1.0, it was " + p + " instead.");
     }
     double r = random.nextDouble();
     if (r < p) {

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/SetLevel.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/SetLevel.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/SetLevel.java	Thu Nov  6 18:16:37 2008
@@ -11,7 +11,7 @@
 
 import ch.qos.logback.classic.Level;
 
-public class SetLevel extends ControlAction {
+public class SetLevel extends ScenarioAction {
   final String loggerName;
   final Level level;
 

Copied: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/TestScenario.java (from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/Scenario.java)
==============================================================================
--- /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/Scenario.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/TestScenario.java	Thu Nov  6 18:16:37 2008
@@ -13,31 +13,23 @@
 import java.util.List;
 import java.util.Vector;
 
-import ch.qos.logback.classic.Level;
+public class TestScenario {
 
-public class Scenario {
-  // the frequency of a set levelInt event for every create logger event
-  private final static int CREATE_LOGGER_TO_SET_LEVEL_FREQUENCY = 5;
+  private List<ScenarioAction> actionList = new Vector<ScenarioAction>();
 
-  private List<ControlAction> actionList = new Vector<ControlAction>();
-
-  public void addAction(CreateLogger action) {
+  public void add(ScenarioAction action) {
     actionList.add(action);
-    if(RandomUtil.oneInFreq(CREATE_LOGGER_TO_SET_LEVEL_FREQUENCY)) {
-      Level l = RandomUtil.randomLevel();
-      actionList.add(new SetLevel(l, action.getLoggerName()));
-    }
   }
 
-  public List<ControlAction> getActionList() {
-    return new ArrayList<ControlAction>(actionList);
+  public List<ScenarioAction> getActionList() {
+    return new ArrayList<ScenarioAction>(actionList);
   }
 
   public int size() {
     return actionList.size();
   }
 
-  public ControlAction get(int i) {
-    return (ControlAction) actionList.get(i);
+  public ScenarioAction get(int i) {
+    return (ScenarioAction) actionList.get(i);
   }
 }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/JMXConfiguratorTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/JMXConfiguratorTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/JMXConfiguratorTest.java	Thu Nov  6 18:16:37 2008
@@ -2,6 +2,7 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.lang.management.ManagementFactory;
@@ -13,8 +14,9 @@
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.slf4j.Logger;
 
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.LoggerContext;
 import ch.qos.logback.classic.spi.LoggerContextListener;
 import ch.qos.logback.core.testUtil.RandomUtil;
@@ -86,13 +88,31 @@
   }
 
   @Test
-  public void getLoggerLevel() {
+  public void getLoggerLevel_LBCLASSIC_78() {
     String objectNameAsStr = "ch.qos"+diff + ":Name=" + lc.getName()
         + ",Type=" + this.getClass().getName();
 
     ObjectName on = MBeanUtil.string2ObjectName(lc, this, objectNameAsStr);
     JMXConfigurator configurator = new JMXConfigurator(lc, mbs, on);
-    configurator.getLoggerLevel(testLogger.getName());
+    assertEquals("", configurator.getLoggerLevel(testLogger.getName()));
+    MBeanUtil.unregister(lc, mbs, on, this);
+  }
+
+  
+  @Test
+  public void setLoggerLevel_LBCLASSIC_79() {
+    String objectNameAsStr = "ch.qos"+diff + ":Name=" + lc.getName()
+        + ",Type=" + this.getClass().getName();
+
+    ObjectName on = MBeanUtil.string2ObjectName(lc, this, objectNameAsStr);
+    JMXConfigurator configurator = new JMXConfigurator(lc, mbs, on);
+    configurator.setLoggerLevel(testLogger.getName(), "DEBUG");
+    assertEquals(Level.DEBUG,  testLogger.getLevel());
+    
+    configurator.setLoggerLevel(testLogger.getName(), "null");
+    assertNull(testLogger.getLevel());
+       
+    MBeanUtil.unregister(lc, mbs, on, this);
   }
 
 }


More information about the logback-dev mailing list