carnold     2005/07/22 11:57:40

  Modified:    src/java/org/apache/log4j Tag: v1_2-branch
                        AsyncAppender.java
               tests/src/java/org/apache/log4j Tag: v1_2-branch
                        AsyncAppenderTestCase.java
  Log:
  Bug 23021: AsyncAppender blocks on thread death
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.30.2.5  +10 -0     
logging-log4j/src/java/org/apache/log4j/AsyncAppender.java
  
  Index: AsyncAppender.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/AsyncAppender.java,v
  retrieving revision 1.30.2.4
  retrieving revision 1.30.2.5
  diff -u -r1.30.2.4 -r1.30.2.5
  --- AsyncAppender.java        24 May 2005 05:06:17 -0000      1.30.2.4
  +++ AsyncAppender.java        22 Jul 2005 18:57:40 -0000      1.30.2.5
  @@ -78,6 +78,16 @@
     }
   
     public void append(LoggingEvent event) {
  +    //
  +    //   if dispatcher thread has died then
  +    //      append subsequent events synchronously
  +    //   See bug 23021
  +    if (!dispatcher.isAlive()) {
  +        synchronized(aai) {
  +          aai.appendLoopOnAppenders(event);
  +        }
  +        return;
  +    }
       // Set the NDC and thread name for the calling thread as these
       // LoggingEvent fields were not set at event creation time.
       event.getNDC();
  
  
  
  No                   revision
  No                   revision
  1.1.2.4   +44 -7     
logging-log4j/tests/src/java/org/apache/log4j/AsyncAppenderTestCase.java
  
  Index: AsyncAppenderTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/tests/src/java/org/apache/log4j/AsyncAppenderTestCase.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- AsyncAppenderTestCase.java        30 Jun 2005 23:16:59 -0000      1.1.2.3
  +++ AsyncAppenderTestCase.java        22 Jul 2005 18:57:40 -0000      1.1.2.4
  @@ -105,13 +105,50 @@
       assertTrue(vectorAppender.isClosed());
     }
   
  +    private static class NullPointerAppender extends AppenderSkeleton {
  +          public NullPointerAppender() {
  +          }
   
  -  public static Test suite() {
  -    TestSuite suite = new TestSuite();
  -    suite.addTest(new AsyncAppenderTestCase("closeTest"));
  -    suite.addTest(new AsyncAppenderTestCase("test2"));
  -    suite.addTest(new AsyncAppenderTestCase("test3"));
  -    return suite;
  -  }
   
  +          /**
  +             This method is called by the [EMAIL PROTECTED] 
org.apache.log4j.AppenderSkeleton#doAppend}
  +             method.
  +
  +          */
  +          public void append(org.apache.log4j.spi.LoggingEvent event) {
  +              throw new NullPointerException();
  +          }
  +
  +          public void close() {
  +          }
  +
  +          public boolean requiresLayout() {
  +            return false;
  +          }
  +    }
  +
  +
  +    /**
  +     * Tests that a bad appender will switch async back to sync.
  +     * See bug 23021
  +     * @since 1.2.12
  +     * @throws Exception thrown if Thread.sleep is interrupted
  +     */
  +    public void testBadAppender() throws Exception {
  +        Appender nullPointerAppender = new NullPointerAppender();
  +        AsyncAppender asyncAppender = new AsyncAppender();
  +        asyncAppender.addAppender(nullPointerAppender);
  +        asyncAppender.setBufferSize(5);
  +        asyncAppender.activateOptions();
  +        Logger root = Logger.getRootLogger();
  +        root.addAppender(nullPointerAppender);
  +        try {
  +           root.info("Message");
  +           Thread.sleep(10);
  +           root.info("Message");
  +           fail("Should have thrown exception");
  +        } catch(NullPointerException ex) {
  +
  +        }
  +    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to