edu.rice.cs.util
Class LogTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by edu.rice.cs.drjava.DrJavaTestCase
              extended by edu.rice.cs.drjava.model.MultiThreadedTestCase
                  extended by edu.rice.cs.util.LogTest
All Implemented Interfaces:
junit.framework.Test

public class LogTest
extends MultiThreadedTestCase

Test cases for Log.

Version:
$Id: LogTest.java 5175 2010-01-20 08:46:32Z mgricken $

Nested Class Summary
private static class LogTest.LogTestThread
          A thread class that adds a log message after sleeping a given number of milliseconds
 
Nested classes/interfaces inherited from class junit.framework.TestCase
junit.framework.TestCase.WrappedException
 
Field Summary
private static int DELAY
           
private static int NUM_THREADS
           
static int TOL
           
 
Fields inherited from class edu.rice.cs.drjava.model.MultiThreadedTestCase
_testFailed
 
Constructor Summary
LogTest()
           
 
Method Summary
private static String getStringAfterDate(String s)
          Returns the string after the date; returns null if there is no date.
 void testConcurrentWrites()
          Attempts to test Log's behavior when called concurrently from several sources.
 void testExceptionPrinting()
          Tests the Exception printing methods in the Log file by throwing two exceptions and using the two types of log methods (one with the Throwable itself and the other with the the StackTraceElement[])
 void testLog()
          Adds a couple of generic messages to a log, and then tests to make sure they are all correct, in the correct order, and their timestamps are within the past few seconds.
private static boolean withinTolerance(Date earlier, Date time0, Date now)
          Returns true if time0 is less than 5000 ms earlier than 'earlier', and now is less than 5000 ms earlier than time0.
 
Methods inherited from class edu.rice.cs.drjava.model.MultiThreadedTestCase
join, listenerFail, listenerFail, setUp, tearDown, wait
 
Methods inherited from class edu.rice.cs.drjava.DrJavaTestCase
setConfigSetting, setDocText
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TOL

public static final int TOL
See Also:
Constant Field Values

NUM_THREADS

private static final int NUM_THREADS
See Also:
Constant Field Values

DELAY

private static final int DELAY
See Also:
Constant Field Values
Constructor Detail

LogTest

public LogTest()
Method Detail

getStringAfterDate

private static String getStringAfterDate(String s)
Returns the string after the date; returns null if there is no date.


withinTolerance

private static boolean withinTolerance(Date earlier,
                                       Date time0,
                                       Date now)
Returns true if time0 is less than 5000 ms earlier than 'earlier', and now is less than 5000 ms earlier than time0. This is necessary because when we parse dates back, the millisecond part gets dropped, so a date later during the same second interval might appear earlier.


testLog

public void testLog()
             throws IOException
Adds a couple of generic messages to a log, and then tests to make sure they are all correct, in the correct order, and their timestamps are within the past few seconds.

Throws:
IOException

testExceptionPrinting

public void testExceptionPrinting()
                           throws IOException
Tests the Exception printing methods in the Log file by throwing two exceptions and using the two types of log methods (one with the Throwable itself and the other with the the StackTraceElement[])

Throws:
IOException

testConcurrentWrites

public void testConcurrentWrites()
                          throws IOException,
                                 InterruptedException
Attempts to test Log's behavior when called concurrently from several sources. Spawns NUM_THREADS LogTestThreads (see above)that wait a random number between 0 and DELAY milliseconds and then log a message. The function tests to make sure that the messages and dates are all intact (if the Log was not handling concurrent requests properly, the entries in the log may be corrupted).

Throws:
IOException
InterruptedException