[logback-dev] svn commit: r1680 - in logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic: . stopwatch

noreply.ceki at qos.ch noreply.ceki at qos.ch
Sat May 3 21:44:53 CEST 2008


Author: ceki
Date: Sat May  3 21:44:52 2008
New Revision: 1680

Added:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/PackageTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/ProfilerTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/StopWatchTest.java
      - copied, changed from r1666, /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/StopWatchTest.java
Modified:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllTest.java

Log:
- ongoing work on StopWatch and poor man's profiler functionality

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	Sat May  3 21:44:52 2008
@@ -31,6 +31,7 @@
     suite.addTest(ch.qos.logback.classic.db.PackageTest.suite()); 
     suite.addTest(ch.qos.logback.classic.spi.PackageTest.suite()); 
     suite.addTest(ch.qos.logback.classic.turbo.PackageTest.suite()); 
+    suite.addTest(ch.qos.logback.classic.stopwatch.PackageTest.suite()); 
     
     return suite;
   }

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/PackageTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/PackageTest.java	Sat May  3 21:44:52 2008
@@ -0,0 +1,23 @@
+/**
+ * Logback: the reliable, generic, 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.stopwatch;
+
+
+import junit.framework.*;
+
+public class PackageTest extends TestCase {
+
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTestSuite(StopWatchTest.class);
+    suite.addTest(new JUnit4TestAdapter(ProfilerTest.class));
+    return suite;
+  }
+}
\ No newline at end of file

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/ProfilerTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/ProfilerTest.java	Sat May  3 21:44:52 2008
@@ -0,0 +1,82 @@
+package ch.qos.logback.classic.stopwatch;
+
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.core.BasicStatusManager;
+import ch.qos.logback.core.status.ErrorStatus;
+import ch.qos.logback.core.status.InfoStatus;
+import ch.qos.logback.core.status.Status;
+import ch.qos.logback.core.status.StatusManager;
+import ch.qos.logback.core.util.StatusPrinter;
+
+public class ProfilerTest {
+
+  Logger logger = LoggerFactory.getLogger(ProfilerTest.class);
+  
+  @Test
+  public void smoke() {
+    Profiler profiler = new Profiler("SMOKE");
+    System.out.println("Hello");
+    profiler.stop();
+  }
+
+  @Test
+  public void X() {
+    StatusManager sm = new BasicStatusManager();
+    Status g = new InfoStatus("global", this);
+    Status g1 = new InfoStatus("g1", this);
+    Status g2 = new InfoStatus("g2", this);
+    Status g11 = new InfoStatus("g11", this);
+    Status g12 = new InfoStatus("g11", this);
+    Status g21 = new InfoStatus("g21", this);
+    
+    
+    g.add(g1);
+    g.add(g2);
+    
+    g1.add(g11);
+    g1.add(g12);
+    g2.add(g21);
+    
+    sm.add(g);
+    StatusPrinter.print(sm);
+    
+  }
+  @Test
+  public void testBasicProfiling() {
+    Profiler profiler = new Profiler("BAS");
+  
+    profiler.start("doX");
+    doX(1);
+    
+    profiler.start("doYYYYY");
+    for(int i = 0; i < 5; i++) {
+      doY(i);
+    }
+    profiler.start("doZ");
+    doZ(2);
+    profiler.stop();
+  }
+  
+  void doX(int millis) {
+    delay(millis);
+  }
+  
+  void doY(int millis) {
+    delay(millis);    
+  }
+ 
+  void doZ(int millis) {
+    delay(millis);    
+  }
+ 
+  void delay(int millis) {
+    try {
+      Thread.sleep(millis);
+    } catch (InterruptedException e) {
+    }
+  }
+}

Copied: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/StopWatchTest.java (from r1666, /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/StopWatchTest.java)
==============================================================================
--- /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/StopWatchTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/StopWatchTest.java	Sat May  3 21:44:52 2008
@@ -1,4 +1,4 @@
-package ch.qos.logback.core;
+package ch.qos.logback.classic.stopwatch;
 
 import junit.framework.TestCase;
 
@@ -26,42 +26,36 @@
     }
     
     { 
-      long d = sw.startTime+9*StopWatch.NANOS_IN_ONE_MICROSECOND;
+      long d = sw.startTime+9*Util.NANOS_IN_ONE_MICROSECOND;
       String s = sw.stop(d).toString();
       assertTrue(s.endsWith("9000 nanoseconds."));
     }
 
     { 
-      long d = sw.startTime+11*StopWatch.NANOS_IN_ONE_MICROSECOND;
+      long d = sw.startTime+11*Util.NANOS_IN_ONE_MICROSECOND;
       String s = sw.stop(d).toString();
       assertTrue(s.endsWith("11 microseconds."));
     }
     { 
-      long d = sw.startTime+9*StopWatch.NANOS_IN_ONE_MILLISECOND;
+      long d = sw.startTime+9*Util.NANOS_IN_ONE_MILLISECOND;
       String s = sw.stop(d).toString();
       assertTrue(s.endsWith("9000 microseconds."));
     }
     { 
-      long d = sw.startTime+3*StopWatch.NANOS_IN_ONE_SECOND;
+      long d = sw.startTime+3*Util.NANOS_IN_ONE_SECOND;
       String s = sw.stop(d).toString();
-      assertTrue(s.endsWith("3000 milliseconds."));
-    }    
-    { 
-      long d = sw.startTime+6*StopWatch.NANOS_IN_ONE_SECOND;
-      String s = sw.stop(d).toString();
-      assertTrue(s.endsWith("6.000 seconds."));
-    }    
+      System.out.println(s);
+      assertTrue(s.endsWith("3.000 seconds."));
+    } 
   }
 
   public void testSelectDurationUnitForDisplay() throws InterruptedException {
-    StopWatch sw = new StopWatch("testBasic");
-    assertEquals(StopWatch.DurationUnit.NANOSECOND, sw.selectDurationUnitForDisplay(10));
-    assertEquals(StopWatch.DurationUnit.NANOSECOND, sw.selectDurationUnitForDisplay(9*StopWatch.NANOS_IN_ONE_MICROSECOND));
-    assertEquals(StopWatch.DurationUnit.MICROSECOND, sw.selectDurationUnitForDisplay(11*StopWatch.NANOS_IN_ONE_MICROSECOND));
-    assertEquals(StopWatch.DurationUnit.MICROSECOND, sw.selectDurationUnitForDisplay(9*StopWatch.NANOS_IN_ONE_MILLISECOND));
-    assertEquals(StopWatch.DurationUnit.MILLISSECOND, sw.selectDurationUnitForDisplay(11*StopWatch.NANOS_IN_ONE_MILLISECOND));
-    assertEquals(StopWatch.DurationUnit.MILLISSECOND, sw.selectDurationUnitForDisplay(3*StopWatch.NANOS_IN_ONE_SECOND));
-    assertEquals(StopWatch.DurationUnit.SECOND, sw.selectDurationUnitForDisplay(6*StopWatch.NANOS_IN_ONE_SECOND));
+    assertEquals(DurationUnit.NANOSECOND, Util.selectDurationUnitForDisplay(10));
+    assertEquals(DurationUnit.NANOSECOND, Util.selectDurationUnitForDisplay(9*Util.NANOS_IN_ONE_MICROSECOND));
+    assertEquals(DurationUnit.MICROSECOND, Util.selectDurationUnitForDisplay(11*Util.NANOS_IN_ONE_MICROSECOND));
+    assertEquals(DurationUnit.MICROSECOND, Util.selectDurationUnitForDisplay(9*Util.NANOS_IN_ONE_MILLISECOND));
+    assertEquals(DurationUnit.MILLISSECOND, Util.selectDurationUnitForDisplay(11*Util.NANOS_IN_ONE_MILLISECOND));
+    assertEquals(DurationUnit.SECOND, Util.selectDurationUnitForDisplay(3*Util.NANOS_IN_ONE_SECOND));
   }
   
 }



More information about the logback-dev mailing list