Skip to content

Commit

Permalink
Clean imports, scopes, and unused vars in unit test
Browse files Browse the repository at this point in the history
Updated ch.qos.logback.core.rolling.TimeBasedRollingWithArchiveRemoval_Test
to remove several unused imports and variables. It also had several package
scoped members that should've been private/static as they were intended to
be used only by that unit test.
  • Loading branch information
tony19 committed Sep 12, 2015
1 parent 3dc9701 commit 130144d
Showing 1 changed file with 31 additions and 38 deletions.
Expand Up @@ -13,12 +13,7 @@
*/
package ch.qos.logback.core.rolling;

import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.encoder.EchoEncoder;
import ch.qos.logback.core.rolling.helper.RollingCalendar;
import ch.qos.logback.core.testUtil.RandomUtil;
import ch.qos.logback.core.util.CoreTestConstants;
import ch.qos.logback.core.util.StatusPrinter;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -28,7 +23,6 @@
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -37,32 +31,31 @@
import static org.junit.Assert.assertTrue;

public class TimeBasedRollingWithArchiveRemoval_Test extends ScaffoldingForRollingTests {
String MONTHLY_DATE_PATTERN = "yyyy-MM";
String MONTHLY_CRONOLOG_DATE_PATTERN = "yyyy/MM";
final String DAILY_CRONOLOG_DATE_PATTERN = "yyyy/MM/dd";
private String MONTHLY_CRONOLOG_DATE_PATTERN = "yyyy/MM";
private final String DAILY_CRONOLOG_DATE_PATTERN = "yyyy/MM/dd";


RollingFileAppender<Object> rfa = new RollingFileAppender<Object>();
TimeBasedRollingPolicy<Object> tbrp = new TimeBasedRollingPolicy<Object>();
private TimeBasedRollingPolicy<Object> tbrp = new TimeBasedRollingPolicy<Object>();

// by default tbfnatp is an instance of DefaultTimeBasedFileNamingAndTriggeringPolicy
TimeBasedFileNamingAndTriggeringPolicy<Object> tbfnatp = new DefaultTimeBasedFileNamingAndTriggeringPolicy<Object>();
private TimeBasedFileNamingAndTriggeringPolicy<Object> tbfnatp = new DefaultTimeBasedFileNamingAndTriggeringPolicy<Object>();

long MILLIS_IN_MINUTE = 60 * 1000;
long MILLIS_IN_HOUR = 60 * MILLIS_IN_MINUTE;
long MILLIS_IN_DAY = 24 * MILLIS_IN_HOUR;
long MILLIS_IN_MONTH = (long) ((365.242199 / 12) * MILLIS_IN_DAY);
int MONTHS_IN_YEAR = 12;
private long MILLIS_IN_MINUTE = 60 * 1000;
private long MILLIS_IN_HOUR = 60 * MILLIS_IN_MINUTE;
private long MILLIS_IN_DAY = 24 * MILLIS_IN_HOUR;
private long MILLIS_IN_MONTH = (long) ((365.242199 / 12) * MILLIS_IN_DAY);
private int MONTHS_IN_YEAR = 12;

int slashCount = 0;
private int slashCount = 0;

@Before
public void setUp() {
super.setUp();
}


private int computeSlashCount(String datePattern) {
private static int computeSlashCount(String datePattern) {
if (datePattern == null)
return 0;
else {
Expand Down Expand Up @@ -103,14 +96,14 @@ public void monthlyRolloverOverManyPeriods() {
check(expectedCountWithFolders(maxHistory, withExtraFolder));
}

void generateDailyRollover(long now, int maxHistory, int simulatedNumberOfPeriods, int startInactivity,
private void generateDailyRollover(long now, int maxHistory, int simulatedNumberOfPeriods, int startInactivity,
int numInactivityPeriods) {
slashCount = computeSlashCount(DAILY_DATE_PATTERN);
logOverMultiplePeriods(now, randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt", MILLIS_IN_DAY, maxHistory, simulatedNumberOfPeriods, startInactivity, numInactivityPeriods);
check(expectedCountWithoutFoldersWithInactivity(maxHistory, simulatedNumberOfPeriods, startInactivity + numInactivityPeriods));
}

void generateDailyRolloverWithCompression(long now, int maxHistory, int simulatedNumberOfPeriods, int startInactivity,
private void generateDailyRolloverWithCompression(long now, int maxHistory, int simulatedNumberOfPeriods, int startInactivity,
int numInactivityPeriods, String fileExtension) {
slashCount = computeSlashCount(DAILY_DATE_PATTERN);
logOverMultiplePeriods(now, randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}." + fileExtension, MILLIS_IN_DAY, maxHistory, simulatedNumberOfPeriods, startInactivity, numInactivityPeriods);
Expand Down Expand Up @@ -224,7 +217,7 @@ public void dailyChronologSizeBasedRolloverWithSecondPhase() {
}


void logOncePeriod(long currentTime, String fileNamePattern, int maxHistory) {
private void logOncePeriod(long currentTime, String fileNamePattern, int maxHistory) {
buildRollingFileAppender(currentTime, fileNamePattern, maxHistory, DO_CLEAN_HISTORY_ON_START);
rfa.doAppend("Hello ----------------------------------------------------------" + new Date(currentTime));
rfa.stop();
Expand Down Expand Up @@ -269,12 +262,12 @@ public void cleanHistoryOnStartWithHourPattern() {
check(expectedCountWithoutFolders(maxHistory));
}

int expectedCountWithoutFolders(int maxHistory) {
private static int expectedCountWithoutFolders(int maxHistory) {
return maxHistory + 1;
}


int expectedCountWithFolders(int maxHistory, boolean withExtraFolder) {
private int expectedCountWithFolders(int maxHistory, boolean withExtraFolder) {
int numLogFiles = (maxHistory + 1);
int numLogFilesAndFolders = numLogFiles * 2;
int result = numLogFilesAndFolders + slashCount;
Expand All @@ -283,7 +276,7 @@ int expectedCountWithFolders(int maxHistory, boolean withExtraFolder) {
}


void buildRollingFileAppender(long currentTime, String fileNamePattern, int maxHistory,
private void buildRollingFileAppender(long currentTime, String fileNamePattern, int maxHistory,
boolean cleanHistoryOnStart) {
rfa.setContext(context);
rfa.setEncoder(encoder);
Expand All @@ -299,17 +292,17 @@ void buildRollingFileAppender(long currentTime, String fileNamePattern, int maxH
rfa.start();
}

boolean DO_CLEAN_HISTORY_ON_START = true;
boolean DO_NOT_CLEAN_HISTORY_ON_START = false;
private boolean DO_CLEAN_HISTORY_ON_START = true;
private boolean DO_NOT_CLEAN_HISTORY_ON_START = false;


long logOverMultiplePeriodsContinuously(long simulatedTime, String fileNamePattern, long periodDurationInMillis, int maxHistory,
private long logOverMultiplePeriodsContinuously(long simulatedTime, String fileNamePattern, long periodDurationInMillis, int maxHistory,
int simulatedNumberOfPeriods) {
return logOverMultiplePeriods(simulatedTime, fileNamePattern, periodDurationInMillis, maxHistory,
simulatedNumberOfPeriods, 0, 0);
}

long logOverMultiplePeriods(long simulatedTime, String fileNamePattern, long periodDurationInMillis, int maxHistory,
private long logOverMultiplePeriods(long simulatedTime, String fileNamePattern, long periodDurationInMillis, int maxHistory,
int simulatedNumberOfPeriods, int startInactivity,
int numInactivityPeriods) {
buildRollingFileAppender(simulatedTime, fileNamePattern, maxHistory, DO_NOT_CLEAN_HISTORY_ON_START);
Expand All @@ -332,17 +325,17 @@ long logOverMultiplePeriods(long simulatedTime, String fileNamePattern, long per
return tbrp.timeBasedFileNamingAndTriggeringPolicy.getCurrentTime();
}

boolean extraFolder(int numPeriods, int periodsPerEra, int beginPeriod, int maxHistory) {
private static boolean extraFolder(int numPeriods, int periodsPerEra, int beginPeriod, int maxHistory) {
int valueOfLastMonth = ((beginPeriod) + numPeriods) % periodsPerEra;
return (valueOfLastMonth < maxHistory);
}

long addTime(long time, long timeToWait) {
private static long addTime(long time, long timeToWait) {
return time + timeToWait;
}


void expectedFileAndDirCount(int expectedFileAndDirCount, int expectedDirCountMin, int expectedDirCountMax) {
private void expectedFileAndDirCount(int expectedFileAndDirCount, int expectedDirCountMin, int expectedDirCountMax) {
File dir = new File(randomOutputDir);
List<File> fileList = new ArrayList<File>();
findFilesInFolderRecursivelyByPatterMatch(dir, fileList, "clean");
Expand All @@ -353,14 +346,14 @@ void expectedFileAndDirCount(int expectedFileAndDirCount, int expectedDirCountMi
}


void check(int expectedCount) {
private void check(int expectedCount) {
File dir = new File(randomOutputDir);
List<File> fileList = new ArrayList<File>();
findAllDirsOrStringContainsFilesRecursively(dir, fileList, "clean");
assertEquals(expectedCount, fileList.size());
}

int expectedCountWithoutFoldersWithInactivity(int maxHistory, int totalPeriods, int endOfInactivity) {
private static int expectedCountWithoutFoldersWithInactivity(int maxHistory, int totalPeriods, int endOfInactivity) {
int availableHistory = (totalPeriods + 1) - endOfInactivity;
int actualHistory = Math.min(availableHistory, maxHistory + 1);
return actualHistory;
Expand All @@ -383,7 +376,7 @@ public boolean accept(File f) {
}
}

private void findAllFoldersInFolderRecursively(File dir, List<File> fileList) {
private static void findAllFoldersInFolderRecursively(File dir, List<File> fileList) {
FileMatchFunction alwaysFalse = new FileMatchFunction() {
public boolean match(File f, String pattern) {
return false;
Expand All @@ -392,7 +385,7 @@ public boolean match(File f, String pattern) {
genericFindMatching(alwaysFalse, dir, fileList, null, true);
}

private void findAllDirsOrStringContainsFilesRecursively(File dir, List<File> fileList, String pattern) {
private static void findAllDirsOrStringContainsFilesRecursively(File dir, List<File> fileList, String pattern) {
FileMatchFunction matchFunction = new FileMatchFunction() {
public boolean match(File f, String pattern) {
Pattern p = Pattern.compile(pattern);
Expand All @@ -412,7 +405,7 @@ public boolean match(File f, String pattern) {
genericFindMatching(matchByPattern, dir, fileList, pattern, false);
}

Set<String> groupByClass(List<File> fileList, String regex) {
private static Set<String> groupByClass(List<File> fileList, String regex) {
Pattern p = Pattern.compile(regex);
Set<String> set = new HashSet<String>();
for (File f : fileList) {
Expand All @@ -427,15 +420,15 @@ Set<String> groupByClass(List<File> fileList, String regex) {
}


void checkPatternCompliance(int expectedClassCount, String regex) {
private void checkPatternCompliance(int expectedClassCount, String regex) {
File dir = new File(randomOutputDir);
List<File> fileList = new ArrayList<File>();
findFilesInFolderRecursivelyByPatterMatch(dir, fileList, regex);
Set<String> set = groupByClass(fileList, regex);
assertEquals(expectedClassCount, set.size());
}

void checkDirPatternCompliance(int expectedClassCount) {
private void checkDirPatternCompliance(int expectedClassCount) {
File dir = new File(randomOutputDir);
List<File> fileList = new ArrayList<File>();
findAllFoldersInFolderRecursively(dir, fileList);
Expand Down

0 comments on commit 130144d

Please sign in to comment.