-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LOGMGR-161] Make best attempt to only calculate caller information i…
…f the formatter being used requires it.
- Loading branch information
Showing
7 changed files
with
156 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,13 +20,14 @@ | |
package org.jboss.logmanager.handlers; | ||
|
||
import org.jboss.logmanager.ExtHandler; | ||
import org.jboss.logmanager.formatters.PatternFormatter; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
public class HandlerTest { | ||
public class ExtHandlerTests { | ||
|
||
@Test | ||
public void testHandlerClose() throws Exception { | ||
|
@@ -67,9 +68,62 @@ public void testHandlerClose() throws Exception { | |
|
||
} | ||
|
||
@Test | ||
public void testCallerCalculationCheckFormatterChange() throws Exception { | ||
final CloseHandler parent = new CloseHandler(); | ||
|
||
// Create a formatter for the parent that will require caller calculation | ||
final PatternFormatter formatter = new PatternFormatter("%d %M %s%e%n"); | ||
parent.setFormatter(formatter); | ||
|
||
Assert.assertTrue(parent.isCallerCalculationRequired()); | ||
|
||
// Change the formatter to not require calculation, this should trigger false to be returned | ||
formatter.setPattern("%d %s%e%n"); | ||
Assert.assertFalse(parent.isCallerCalculationRequired()); | ||
} | ||
|
||
@Test | ||
public void testCallerCalculationCheckNewFormatter() throws Exception { | ||
final CloseHandler parent = new CloseHandler(); | ||
|
||
// Create a formatter for the parent that will require caller calculation | ||
final PatternFormatter formatter = new PatternFormatter("%d %M %s%e%n"); | ||
parent.setFormatter(formatter); | ||
|
||
Assert.assertTrue(parent.isCallerCalculationRequired()); | ||
|
||
// Add a new formatter which should result in the caller calculation not to be required | ||
parent.setFormatter(new PatternFormatter("%d %s%e%n")); | ||
Assert.assertFalse(parent.isCallerCalculationRequired()); | ||
} | ||
|
||
@Test | ||
public void testCallerCalculationCheckChildFormatter() throws Exception { | ||
final CloseHandler parent = new CloseHandler(); | ||
final CloseHandler child = new CloseHandler(); | ||
parent.addHandler(child); | ||
|
||
// Create a formatter for the parent that will require caller calculation | ||
final PatternFormatter formatter = new PatternFormatter("%d %M %s%e%n"); | ||
child.setFormatter(formatter); | ||
Assert.assertTrue(parent.isCallerCalculationRequired()); | ||
|
||
// Remove the child handler which should result in the caller calculation not to be required | ||
parent.removeHandler(child); | ||
Assert.assertFalse(parent.isCallerCalculationRequired()); | ||
|
||
// Add a formatter to the parent and add he child back, the parent handler will not require calculation, but | ||
// the child should | ||
parent.setFormatter(new PatternFormatter("%d %s%e%n")); | ||
parent.addHandler(child); | ||
Assert.assertTrue(parent.isCallerCalculationRequired()); | ||
} | ||
|
||
static class CloseHandler extends ExtHandler { | ||
private boolean closed = false; | ||
|
||
|
||
@Override | ||
public void close() { | ||
closed = true; | ||
|