ERFATestCasepublic class ERFATestCase extends TestCase Test of ExternallyRolledFileAppender. |
Constructors Summary |
---|
public ERFATestCase(String name)Create new instance of test.
super(name);
|
Methods Summary |
---|
void | sendMessage(int port, java.lang.String msg, java.lang.String expectedResponse)Send a message to the ERFA.
Socket socket = new Socket((String) null, port);
DataInputStream reader = new DataInputStream(socket.getInputStream());
DataOutputStream writer = new DataOutputStream(socket.getOutputStream());
writer.writeUTF(msg);
String response = reader.readUTF();
assertEquals(expectedResponse, response);
reader.close();
writer.close();
socket.close();
| public void | tearDown()Reset configuration after test.
LogManager.resetConfiguration();
| public void | testConstructor()Test ExternallyRolledFileAppender constructor.
ExternallyRolledFileAppender appender =
new ExternallyRolledFileAppender();
assertEquals(0, appender.getPort());
| public void | testRollover()Test externally triggered rollover.
ExternallyRolledFileAppender erfa =
new ExternallyRolledFileAppender();
int port = 5500;
Logger logger = Logger.getLogger(RFATestCase.class);
Logger root = Logger.getRootLogger();
PatternLayout layout = new PatternLayout("%m\n");
erfa.setLayout(layout);
erfa.setAppend(false);
erfa.setMaxBackupIndex(2);
erfa.setPort(port);
erfa.setFile("output/ERFA-test2.log");
try {
erfa.activateOptions();
} catch(SecurityException ex) {
return;
}
try {
Thread.sleep(100);
} catch(InterruptedException ex) {
}
root.addAppender(erfa);
// Write exactly 10 bytes with each log
for (int i = 0; i < 55; i++) {
if (i < 10) {
logger.debug("Hello---" + i);
} else if (i < 100) {
logger.debug("Hello--" + i);
}
if ((i % 10) == 9) {
try {
sendMessage(port, "RollOver", "OK");
} catch(SecurityException ex) {
return;
}
}
}
try {
sendMessage(port,
"That's all folks.",
"Expecting [RollOver] string.");
} catch(SecurityException ex) {
return;
}
assertTrue(new File("output/ERFA-test2.log").exists());
assertTrue(new File("output/ERFA-test2.log.1").exists());
assertTrue(new File("output/ERFA-test2.log.2").exists());
assertFalse(new File("output/ERFA-test2.log.3").exists());
|
|