virajjasani commented on PR #5451:
URL: https://github.com/apache/hadoop/pull/5451#issuecomment-1455025728
> Do you mean to say we are reading via different mechanisms but reading
from the same place?
Basically they will read from their own WriterAppender so there is no sync
issue while reading.
The beauty of using `LogCapturer` is that every test that uses it gets to
use their own appender. Hence, every test with new instance of LogCapturer will
capture the logs of the given logger (audit log in our case) in their own
WriterAppender.
> The Appender logic will be catching output from other tests as well when
run in Parallel?
Absolutely, every test has their own new appender instance so no two tests
using different instance of LogCapturer has to worry about reading from common
place (like console or file) as they have their own private appender to read
the logs from. This part does that nice logic:
```
private LogCapturer(Logger logger) {
this.logger = logger;
Appender defaultAppender =
Logger.getRootLogger().getAppender("stdout");
if (defaultAppender == null) {
defaultAppender = Logger.getRootLogger().getAppender("console");
}
final Layout layout = (defaultAppender == null) ? new PatternLayout() :
defaultAppender.getLayout();
this.appender = new WriterAppender(layout, sw);
logger.addAppender(this.appender);
}
```
So, let's say tomorrow we write a new test that also needs to read namenode
audit logs, the test should just create new LogCapturer object and extract logs
from it, that's it. It doesn't interfere with any other tests, if run
simultaneously. TestFsck has it's own writer appender. TestAuditLogs on the
other hand is reading directly from the file which is used by log4j properties
as primary RFA appender, which I think is good so that at least we have one
test that also validates output from primary appender directly and verifies
regex. Now even if TestAuditLogs deletes the file such that every log produced
by TestFsck are gone, it's still not a concern for TestFsck because TestFsck
has it's own writer appender instance as a secondary appender and as part of
reading logs, it now uses this secondary appender and no longer relies on
primary appender (file).
FWIW, I believe LogCapturer is really nice utility.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]