X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Flogging%2FLogReader.java;h=1e84b629d91eb100d9323ed8328725a8521787ad;hb=08f6801fc93c4b39a8e870974100cd24ec9450a0;hp=0c4de64021c7c1d22271f79a088479496f62b752;hpb=716e7f240c2f4a71d48e7708aa27194db2dd7f21;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 0c4de64..1e84b62 100644 --- a/src/test/java/org/onap/aai/babel/logging/LogReader.java +++ b/src/test/java/org/onap/aai/babel/logging/LogReader.java @@ -1,5 +1,5 @@ /** - * ============LICENSE_START======================================================= + * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.babel.logging; import java.io.BufferedReader; @@ -27,10 +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.lang3.time.StopWatch; import org.junit.Assert; @@ -57,9 +60,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 +76,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 +87,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();