diff options
Diffstat (limited to 'src/test/java/org/onap/aai/validation/logging/LogReader.java')
-rw-r--r-- | src/test/java/org/onap/aai/validation/logging/LogReader.java | 60 |
1 files changed, 28 insertions, 32 deletions
diff --git a/src/test/java/org/onap/aai/validation/logging/LogReader.java b/src/test/java/org/onap/aai/validation/logging/LogReader.java index 096221d..9faf0fb 100644 --- a/src/test/java/org/onap/aai/validation/logging/LogReader.java +++ b/src/test/java/org/onap/aai/validation/logging/LogReader.java @@ -1,20 +1,24 @@ -/* - * ============LICENSE_START=================================================== - * Copyright (c) 2018 Amdocs - * ============================================================================ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2018-2019 European Software Marketing Ltd. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * ============LICENSE_END===================================================== + * ============LICENSE_END========================================================= */ + package org.onap.aai.validation.logging; import java.io.BufferedReader; @@ -25,31 +29,23 @@ 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.junit.Assert; public class LogReader { - private Map<String, Path> cachedLogMap = new HashMap<>(); - private Map<String, BufferedReader> readersMap = new HashMap<>(); private BufferedReader cachedReader; + private Path cachedLog; public LogReader(String logDirectory, String logFilePrefix) throws IOException { cachedReader = getReader(logDirectory, logFilePrefix); } private BufferedReader getReader(String logDirectory, String logFilePrefix) throws IOException { - BufferedReader reader = readersMap.get(logFilePrefix); - if (reader == null) { - reader = new BufferedReader(new FileReader(getLogFile(logDirectory, logFilePrefix))); - while (reader.readLine() != null) { - // Consume all lines - } - readersMap.put(logFilePrefix, reader); + BufferedReader reader = new BufferedReader(new FileReader(getLogFile(logDirectory, logFilePrefix))); + while (reader.readLine() != null) { + // Consume all lines } return reader; } @@ -59,24 +55,24 @@ public class LogReader { * @return the most recently created log file. * @throws IOException */ - public File getLogFile(String logDirectory, String filenamePrefix) throws IOException { - Path cachedLog = cachedLogMap.get(filenamePrefix); - - if (cachedLog == null) { - Optional<Path> latestFilePath = Files.list(Paths.get(logDirectory)) - .filter(f -> Files.isDirectory(f) == false && f.getFileName().toString().startsWith(filenamePrefix)) - .max(Comparator.comparingLong(f -> f.toFile().lastModified())); - if (latestFilePath.isPresent()) { - cachedLog = latestFilePath.get(); - } else { - throw new IOException("No validation log files were found!"); - } + private File getLogFile(String logDirectory, String filenamePrefix) throws IOException { + Optional<Path> latestFilePath = Files.list(Paths.get(logDirectory)) + .filter(f -> Files.isDirectory(f) == false // + && f.getFileName().toString().startsWith(filenamePrefix) + && !f.getFileName().toString().endsWith(".zip")) + .max(Comparator.comparingLong(f -> f.toFile().lastModified())); + if (latestFilePath.isPresent()) { + cachedLog = latestFilePath.get(); + } else { + throw new IOException("No validation log files were found!"); } return cachedLog.toFile(); } /** + * Read newly appended lines from the log. + * * @return new lines appended to the log file * @throws IOException */ @@ -85,8 +81,8 @@ public class LogReader { stopwatch.start(); while (!cachedReader.ready()) { - if (stopwatch.getTime() > TimeUnit.SECONDS.toMillis(30)) { - Assert.fail("Test took too long"); + if (stopwatch.getTime() > TimeUnit.SECONDS.toMillis(10)) { + throw new IOException("Test took too long - waiting on " + cachedLog); } // else keep waiting } |