You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-cvs@jakarta.apache.org by ce...@apache.org on 2002/05/17 13:54:06 UTC

cvs commit: jakarta-log4j/tests/witness socketServer.5

ceki        02/05/17 04:54:06

  Modified:    docs     Tag: v1_2-branch HISTORY
               src/java/org/apache/log4j Tag: v1_2-branch NDC.java
               src/java/org/apache/log4j/spi Tag: v1_2-branch
                        LoggingEvent.java
               tests    Tag: v1_2-branch build.xml
               tests/src/java/org/apache/log4j/net Tag: v1_2-branch
                        ShortSocketServer.java SocketServerTestCase.java
  Added:       tests/input Tag: v1_2-branch socketServer5.properties
               tests/witness Tag: v1_2-branch socketServer.5
  Log:
  Fixed bug #9155 reported by Nicko Cadell. Added test5 to
  SocketServerTestCase in order to detect such bugs earlier in the
  release process.
  
  Also improved the documentation of LoggingEvent, NDC, ShortSocketServer
  and SocketServerTestCase.
  
  +----------------------------------------------------+
  |Note: These changes are committed on the v1_2-branch|
  +----------------------------------------------------+
  
  Relase of log4j 1.2.1 will follow shortly.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.97.2.1  +8 -0      jakarta-log4j/docs/HISTORY
  
  Index: HISTORY
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/docs/HISTORY,v
  retrieving revision 1.97
  retrieving revision 1.97.2.1
  diff -u -r1.97 -r1.97.2.1
  --- HISTORY	10 May 2002 08:00:54 -0000	1.97
  +++ HISTORY	17 May 2002 11:54:06 -0000	1.97.2.1
  @@ -5,6 +5,14 @@
          client code. 
    [***] Changes requiring important modifications to existing client code.
   
  + May 17th, 2002
  +
  + - Relase of version 1.2.1
  +
  + - This minor release fixes bug #9155 reported by Nicko Cadell.
  +   LoggingEvent.getMDCCopy() method now sets mdcCopyLookupRequired
  +   instead of ndcLookupRequired. [*]
  +
    May, 2002
    
    - Release of version 1.2 
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.13.2.1  +2 -1      jakarta-log4j/src/java/org/apache/log4j/NDC.java
  
  Index: NDC.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/NDC.java,v
  retrieving revision 1.13
  retrieving revision 1.13.2.1
  diff -u -r1.13 -r1.13.2.1
  --- NDC.java	3 Apr 2002 22:18:14 -0000	1.13
  +++ NDC.java	17 May 2002 11:54:06 -0000	1.13.2.1
  @@ -192,7 +192,8 @@
   
   
     /**
  -     Used when printing the diagnostic context.
  +     <font color="#FF4040"><b>Never use this method directly, use the {@link
  +     org.apache.log4j.spi.LoggingEvent#getNDC} method instead.</b></font>
     */
     static
     public
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.31.2.1  +21 -15    jakarta-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java
  
  Index: LoggingEvent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java,v
  retrieving revision 1.31
  retrieving revision 1.31.2.1
  diff -u -r1.31 -r1.31.2.1
  --- LoggingEvent.java	9 May 2002 17:44:54 -0000	1.31
  +++ LoggingEvent.java	17 May 2002 11:54:06 -0000	1.31.2.1
  @@ -62,18 +62,16 @@
   
   
     /** Have we tried to do an NDC lookup? If we did, there is no need
  -      to do it again.  Note that its value is always false when
  -      serialized. Thus, a receiving SocketNode will never use it's own
  -      (incorrect) NDC. See also writeObject method. */
  +   *  to do it again.  Note that its value is always false when
  +   *  serialized. Thus, a receiving SocketNode will never use it's own
  +   *  (incorrect) NDC. See also writeObject method. */
     private boolean ndcLookupRequired = true;
   
   
  - /** Have we tried to do an MDC lookup? If we did, there is no need to
  -      do it again.  Note that its value is always false when
  -      serialized. Thus, a receiving SocketNode will never use it's own
  -      (incorrect) MDC. See also writeObject method. */
  -  private boolean mdcLookupRequired = true;
  -
  +  /** Have we tried to do an MDC lookup? If we did, there is no need
  +   *  to do it again.  Note that its value is always false when
  +   *  serialized. See also the getMDC and getMDCCopy methods.  */
  +  private boolean mdcCopyLookupRequired = true;
   
     /** The application supplied message of logging event. */
     transient private Object message;
  @@ -187,6 +185,11 @@
       }
     }
   
  +  /**
  +   * This method returns the NDC for this event. It will return the
  +   * correct content even if the event was generated in a different
  +   * thread or even on a different machine. The {@link NDC#get} method
  +   * should <em>never</em> be called directly.  */
     public
     String getNDC() {
       if(ndcLookupRequired) {
  @@ -199,9 +202,11 @@
   
     /**
         Returns the the context corresponding to the <code>key</code>
  -      parameter. If there is a local MDC copy (probably from a remote
  -      machine, the we use it, if that fails then the current thread's
  -      <code>MDC</code> is used. 
  +      parameter. If there is a local MDC copy, possibly because we are
  +      in a logging server or running inside AsyncAppender, then we
  +      search for the key in MDC copy, if a value is found it is
  +      returned. Otherwise, if the search in MDC copy returns a null
  +      result, then the current thread's <code>MDC</code> is used.
         
         <p>Note that <em>both</em> the local MDC copy and the current
         thread's MDC are searched.
  @@ -223,11 +228,12 @@
   
     /**
        Obtain a copy of this thread's MDC prior to serialization or
  -     asynchronous logging.  */
  +     asynchronous logging.  
  +  */
     public
     void getMDCCopy() {
  -    if(mdcLookupRequired) {
  -      ndcLookupRequired = false;
  +    if(mdcCopyLookupRequired) {
  +      mdcCopyLookupRequired = false;
         // the clone call is required for asynchronous logging.
         // See also bug #5932.
         Hashtable t = (Hashtable) MDC.getContext();
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.16.2.1  +1 -1      jakarta-log4j/tests/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/build.xml,v
  retrieving revision 1.16
  retrieving revision 1.16.2.1
  diff -u -r1.16 -r1.16.2.1
  --- build.xml	10 May 2002 07:57:36 -0000	1.16
  +++ build.xml	17 May 2002 11:54:06 -0000	1.16.2.1
  @@ -172,7 +172,7 @@
     <target name="SocketServer" depends="build">
       <parallel>
         <java classname="org.apache.log4j.net.ShortSocketServer" fork="yes">
  -	<arg value="4"/> 
  +	<arg value="5"/> 
   	<arg value="input/socketServer"/> 
   	<classpath refid="tests.classpath"/>
         </java>
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +8 -0      jakarta-log4j/tests/input/Attic/socketServer5.properties
  
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +10 -5     jakarta-log4j/tests/src/java/org/apache/log4j/net/ShortSocketServer.java
  
  Index: ShortSocketServer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/src/java/org/apache/log4j/net/ShortSocketServer.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- ShortSocketServer.java	16 Apr 2002 14:36:15 -0000	1.1
  +++ ShortSocketServer.java	17 May 2002 11:54:06 -0000	1.1.2.1
  @@ -20,10 +20,15 @@
   import org.apache.log4j.net.SocketServer;
   
   /**
  -   This SocketServer exits after just one connection from a client.
  -
  -   @author Ceki Gulcu
  -*/
  + * This SocketServer exits after certain number of connections from a
  + * client. This number is determined the totalsTest parameter, that is
  + * the first argument on the commmand line. The second argument,
  + * prefix, determines the prefix of the configuration file to
  + * use. Each run of the server will use a different properties
  + * file. For the i-th run, the path to the file is
  + * (prefix+i+".properties").
  + *
  + * @author Ceki Gulcu */
   
   public class ShortSocketServer  {
   
  @@ -61,7 +66,7 @@
   
     
     static
  -  void  usage(String msg) {
  +  void usage(String msg) {
       System.err.println(msg);
       System.err.println(
         "Usage: java " +ShortSocketServer.class.getName() + " totalTests configFilePrefix");
  
  
  
  1.2.2.1   +72 -3     jakarta-log4j/tests/src/java/org/apache/log4j/net/SocketServerTestCase.java
  
  Index: SocketServerTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/src/java/org/apache/log4j/net/SocketServerTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- SocketServerTestCase.java	16 Apr 2002 14:36:15 -0000	1.2
  +++ SocketServerTestCase.java	17 May 2002 11:54:06 -0000	1.2.2.1
  @@ -55,6 +55,9 @@
     static String PAT4 = "^(DEBUG| INFO| WARN|ERROR|FATAL|LETHAL) some T4 MDC-TEST4 \\[main]\\"
                          + " (root|SocketServerTestCase) - Message \\d{1,2}";
   
  +  static String PAT5 = "^(DEBUG| INFO| WARN|ERROR|FATAL|LETHAL) some5 T5 MDC-TEST5 \\[main]\\"
  +                       + " (root|SocketServerTestCase) - Message \\d{1,2}";
  +
   
     static String EXCEPTION1 = "java.lang.Exception: Just testing";
     static String EXCEPTION2 = "\\s*at .*\\(.*:\\d{1,4}\\)";
  @@ -72,8 +75,6 @@
   
     public void setUp() {
       System.out.println("Setting up test case.");
  -    socketAppender = new SocketAppender("localhost", PORT);
  -    rootLogger.addAppender(socketAppender);
     }
     
     public void tearDown() {
  @@ -81,8 +82,15 @@
       socketAppender = null;
       rootLogger.removeAllAppenders();
     }
  -  
  +
  +  /**
  +   * The pattern on the server side: %5p %x [%t] %c %m%n     
  +   *
  +   * We are testing NDC functionality across the wire.  
  +   */
     public void test1() throws Exception {
  +    socketAppender = new SocketAppender("localhost", PORT);
  +    rootLogger.addAppender(socketAppender);
       common("T1", "key1", "MDC-TEST1");
       delay(1);
       ControlFilter cf = new ControlFilter(new String[]{PAT1, EXCEPTION1, 
  @@ -93,7 +101,16 @@
       assertTrue(Compare.compare(FILTERED, "witness/socketServer.1"));
     }
   
  +  /**
  +   * The pattern on the server side: %5p %x [%t] %C (%F:%L) %m%n
  +   *
  +   * We are testing NDC across the wire. Localization is turned off by
  +   * default so it is not tested here even if the conversion pattern
  +   * uses localization. */
     public void test2() throws Exception {
  +    socketAppender = new SocketAppender("localhost", PORT);
  +    rootLogger.addAppender(socketAppender);
  +
       common("T2", "key2", "MDC-TEST2");
       delay(1);
       ControlFilter cf = new ControlFilter(new String[]{PAT2, EXCEPTION1, 
  @@ -104,8 +121,15 @@
       assertTrue(Compare.compare(FILTERED, "witness/socketServer.2"));
     }
   
  +  /**
  +   *  The pattern on the server side: %5p %x [%t] %C (%F:%L) %m%n
  +   *  meaning that we are testing NDC and locatization functionality
  +   *  across the wire.  */
     public void test3() throws Exception {
  +    socketAppender = new SocketAppender("localhost", PORT);
       socketAppender.setLocationInfo(true);
  +    rootLogger.addAppender(socketAppender);
  +
       common("T3", "key3", "MDC-TEST3");
       delay(1);
       ControlFilter cf = new ControlFilter(new String[]{PAT3, EXCEPTION1, 
  @@ -116,10 +140,19 @@
       assertTrue(Compare.compare(FILTERED, "witness/socketServer.3"));
     }
   
  +  /**
  +   *  The pattern on the server side: %5p %x %X{key1}%X{key4} [%t] %c{1} - %m%n 
  +   *  meaning that we are testing NDC, MDC and localization functionality across 
  +   *  the wire.  
  +  */
     public void test4() throws Exception {
  +    socketAppender = new SocketAppender("localhost", PORT);
       socketAppender.setLocationInfo(true);
  +    rootLogger.addAppender(socketAppender);
  +
       NDC.push("some");
       common("T4", "key4", "MDC-TEST4");
  +    NDC.pop();
       delay(1);
       ControlFilter cf = new ControlFilter(new String[]{PAT4, EXCEPTION1, 
   						       EXCEPTION2, EXCEPTION3});
  @@ -129,6 +162,41 @@
       assertTrue(Compare.compare(FILTERED, "witness/socketServer.4"));
     }
   
  +  /**
  +   *  The pattern on the server side: %5p %x %X{key1}%X{key5} [%t] %c{1} - %m%n 
  +   *
  +   *  The test case uses wraps an AsyncAppender around the
  +   *  SocketAppender. This tests was written specifically for bug
  +   *  report #9155.  
  +
  +   * Prior to the bug fix the output on the server did not contain the
  +   * MDC-TEST5 string because the MDC clone operation (in getMDCCopy
  +   * method) operation is performed twice, once from the main thread
  +   * which is correct, and a second time from the AsyncAppender's
  +   * dispatch thread which is incrorrect.
  +
  +   */
  +  public void test5() throws Exception {
  +    socketAppender = new SocketAppender("localhost", PORT);
  +    socketAppender.setLocationInfo(true);
  +    AsyncAppender asyncAppender = new AsyncAppender();
  +    asyncAppender.setLocationInfo(true);
  +    asyncAppender.addAppender(socketAppender);
  +    rootLogger.addAppender(asyncAppender);
  +
  +    NDC.push("some5");
  +    common("T5", "key5", "MDC-TEST5");
  +    NDC.pop();
  +    delay(2);
  +    ControlFilter cf = new ControlFilter(new String[]{PAT5, EXCEPTION1, 
  +						       EXCEPTION2, EXCEPTION3});
  +    
  +    Transformer.transform(TEMP, FILTERED, new Filter[] {cf, new LineNumberFilter()});
  +
  +    assertTrue(Compare.compare(FILTERED, "witness/socketServer.5"));
  +  }
  +
  +
     static 
     void common(String dc, String key, Object o) {
       int i = -1; 
  @@ -161,6 +229,7 @@
       suite.addTest(new SocketServerTestCase("test2"));
       suite.addTest(new SocketServerTestCase("test3"));
       suite.addTest(new SocketServerTestCase("test4"));
  +    suite.addTest(new SocketServerTestCase("test5"));
       return suite;
     }
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +35 -0     jakarta-log4j/tests/witness/Attic/socketServer.5
  
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>