edu.rice.cs.util
Class LogTest
java.lang.Object
junit.framework.Assert
junit.framework.TestCase
edu.rice.cs.drjava.DrJavaTestCase
edu.rice.cs.drjava.model.MultiThreadedTestCase
edu.rice.cs.util.LogTest
- All Implemented Interfaces:
- 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 |
|
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 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 |
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
LogTest
public LogTest()
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