DomGarguilo commented on code in PR #5547:
URL: https://github.com/apache/accumulo/pull/5547#discussion_r2124324391
##########
test/src/main/java/org/apache/accumulo/test/AuditMessageIT.java:
##########
@@ -124,36 +125,24 @@ private ArrayList<String> getAuditMessages(String
stepName) throws IOException {
// Grab the audit messages
System.out.println("Start of captured audit messages for step " +
stepName);
- ArrayList<String> result = new ArrayList<>();
- File[] files = getCluster().getConfig().getLogDir().listFiles();
- assertNotNull(files);
- for (File file : files) {
- // We want to grab the files called .out
- if (file.getName().contains(".out") && file.isFile() && file.canRead()) {
- try (java.util.Scanner it = new java.util.Scanner(file, UTF_8)) {
- // strip off prefix, because log4j.properties does
- final var pattern = Pattern.compile(".* \\["
- + AuditedSecurityOperation.AUDITLOG.replace("org.apache.",
"").replace(".", "[.]")
- + "\\] .*");
- while (it.hasNext()) {
- String line = it.nextLine();
- if (pattern.matcher(line).matches()) {
- // Only include the message if startTimestamp is null. or the
message occurred after
- // the startTimestamp value
- if ((lastAuditTimestamp == null)
- || (line.substring(0, 23).compareTo(lastAuditTimestamp) >
0)) {
- result.add(line);
- }
+ ArrayList<String> result;
+ final var pattern = Pattern.compile(
+ ".* \\[" + AuditedSecurityOperation.AUDITLOG.replace("org.apache.",
"").replace(".", "[.]")
+ + "\\] .*");
+ try (var paths =
Files.list(getCluster().getConfig().getLogDir().toPath())) {
+ result = paths.filter(file ->
file.getFileName().toString().contains(".out"))
+ .filter(file -> Files.isRegularFile(file) &&
Files.isReadable(file)).flatMap(path -> {
+ try {
+ return Files.lines(path, UTF_8);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
- }
- }
- }
+ }).filter(pattern.asPredicate())
+ .filter(line -> lastAuditTimestamp == null
+ || line.substring(0, 23).compareTo(lastAuditTimestamp) > 0)
+
.sorted().peek(System.out::println).collect(Collectors.toCollection(ArrayList::new));
Review Comment:
Added some comments here. Hopefully an improvement on what was there before.
--
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]