Skip to content

Commit

Permalink
Speeding up logging related tests in model-intest.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Nov 12, 2014
1 parent 14c5ad0 commit a810e82
Showing 1 changed file with 19 additions and 6 deletions.
Expand Up @@ -17,12 +17,15 @@

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -49,7 +52,8 @@ public class LogfileTestTailer {
public static final String LEVEL_INFO = "INFO";
public static final String LEVEL_DEBUG = "DEBUG";
public static final String LEVEL_TRACE = "TRACE";


// see also the 'optimization' at the beginning of processLogLine() - interfering with these patterns
private static final Pattern markerPattern = Pattern.compile(".*\\[[^]]*\\]\\s+(\\w+)\\s+\\S+\\s+"+MARKER+"\\s+(\\w+).*");
private static final Pattern markerPatternPrefix = Pattern.compile(".*\\[[^]]*\\]\\s+(\\w+)\\s+\\S+\\s+.*"+MARKER+"\\s+(\\w+).*");
public static final Pattern auditPattern =
Expand All @@ -60,7 +64,7 @@ public class LogfileTestTailer {

final static Trace LOGGER = TraceManager.getTrace(LogfileTestTailer.class);

private FileReader fileReader;
private Reader fileReader;
private BufferedReader reader;
private boolean seenMarker;
private Set<String> loggedMarkers;
Expand All @@ -78,11 +82,16 @@ public LogfileTestTailer() throws IOException {
public LogfileTestTailer(boolean skipCurrentContent) throws IOException {
reset();
File file = new File(LOG_FILENAME);
fileReader = new FileReader(file);
reader = new BufferedReader(fileReader);

// doing skipping on FileInputStream instead of BufferedReader, hoping it is faster
// as the sequential scanning of the file is eliminated
FileInputStream fileInputStream = new FileInputStream(file);
if (skipCurrentContent) {
reader.skip(file.length());
long skipped = fileInputStream.skip(file.length());
LOGGER.info("Skipped = {}", skipped);
}
fileReader = new InputStreamReader(fileInputStream);
reader = new BufferedReader(fileReader);
}

public boolean isAllowPrefix() {
Expand Down Expand Up @@ -127,11 +136,15 @@ public void tail() throws IOException {
if (line == null) {
break;
}
processLogLine(line);
processLogLine(line);
}
}

private void processLogLine(String line) {

if (line.length() > 0 && Character.isWhitespace(line.charAt(0))) {
return; // ugly hack: getting rid of long 'continuation' lines that are not matched by any patterns but terribly slow down the processing
}

// Match marker
Pattern pattern = markerPattern;
Expand Down

0 comments on commit a810e82

Please sign in to comment.