X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Flogging%2FLogReader.java;h=f18fb6d585d9dc1b22bbc128436d4cd333f1a663;hb=refs%2Fchanges%2F87%2F72287%2F2;hp=c2a8e648a8d1da36c8cf60e45178253b4a73a644;hpb=66b3afa06776e9944ad515206d281d67747c9770;p=aai%2Fbabel.git diff --git a/src/test/java/org/onap/aai/babel/logging/LogReader.java b/src/test/java/org/onap/aai/babel/logging/LogReader.java index c2a8e64..f18fb6d 100644 --- a/src/test/java/org/onap/aai/babel/logging/LogReader.java +++ b/src/test/java/org/onap/aai/babel/logging/LogReader.java @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.babel.logging; import java.io.BufferedReader; @@ -27,11 +28,12 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.concurrent.TimeUnit; -import org.apache.commons.lang.time.StopWatch; +import org.apache.commons.lang3.time.StopWatch; import org.junit.Assert; public class LogReader { @@ -57,9 +59,15 @@ public class LogReader { } /** + * Find the most recently modified log file with a name starting with the specified prefix. + * * @param logDirectory - * @return the most recently created log file. + * the root folder storing log files + * @param filenamePrefix + * the log file name prefix + * @return the most recently created log file * @throws IOException + * if an I/O error occurs */ public File getLogFile(String logDirectory, String filenamePrefix) throws IOException { Path cachedLog = cachedLogMap.get(filenamePrefix); @@ -67,7 +75,7 @@ public class LogReader { if (cachedLog == null) { Optional latestFilePath = Files.list(Paths.get(logDirectory)) .filter(f -> Files.isDirectory(f) == false && f.getFileName().toString().startsWith(filenamePrefix)) - .max((f1, f2) -> (int) (f1.toFile().lastModified() - f2.toFile().lastModified())); + .max(Comparator.comparingLong(f -> f.toFile().lastModified())); if (latestFilePath.isPresent()) { cachedLog = latestFilePath.get(); } else { @@ -78,8 +86,11 @@ public class LogReader { } /** + * Wait for and read new log entries. + * * @return new lines appended to the log file * @throws IOException + * If an I/O error occurs */ public String getNewLines() throws IOException { StopWatch stopwatch = new StopWatch();