Skip to content

Commit

Permalink
minor changes in RollingFileAppenderTest
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <[email protected]>
  • Loading branch information
ceki committed Sep 24, 2024
1 parent 42caff8 commit 67c24f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ private boolean checkSizeBasedTrigger(File activeFile, long currentTime) {
}

public Duration getCheckIncrement() {
return checkIncrement;
return null;
}

public void setCheckIncrement(Duration checkIncrement) {
this.checkIncrement = checkIncrement;
addWarn("Since version 1.5.8, 'checkIncrement' property has no effect");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import ch.qos.logback.core.util.Duration;
import ch.qos.logback.core.util.FileSize;
import ch.qos.logback.core.util.FileUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -275,21 +276,24 @@ public void collidingFileNamePattern() {
@Test
@DisplayName("Checks header and footer are written when the files are rolled")
public void testHeaderFooterWritten() throws IOException, InterruptedException {
for (int i = 0; i < 8; i++) {
File file = new File(CoreTestConstants.OUTPUT_DIR_PREFIX + "header-" + i + ".log");
file.deleteOnExit();
}

String folderPrefix = CoreTestConstants.OUTPUT_DIR_PREFIX+diff+"/";
String namePrefix = folderPrefix+"header-";
File folderFile = new File(folderPrefix);
FileUtil.createMissingParentDirectories(folderFile);


encoder.setFileHeader("HEADER");
encoder.setFileFooter("FOOTER");
rfa.setContext(context);
FixedWindowRollingPolicy fixedWindowRollingPolicy = new FixedWindowRollingPolicy();
fixedWindowRollingPolicy.setContext(context);
fixedWindowRollingPolicy.setParent(rfa);
fixedWindowRollingPolicy.setMaxIndex(3);
String fileNamePattern = CoreTestConstants.OUTPUT_DIR_PREFIX + "header-%i.log";
String fileNamePattern = namePrefix + "%i.log";
fixedWindowRollingPolicy.setFileNamePattern(fileNamePattern);
rfa.setRollingPolicy(fixedWindowRollingPolicy);
rfa.setFile(CoreTestConstants.OUTPUT_DIR_PREFIX + "header-0.log");
rfa.setFile(namePrefix+"0.log");
fixedWindowRollingPolicy.start();
rfa.setImmediateFlush(true);
SizeBasedTriggeringPolicy<Object> sbtp = new SizeBasedTriggeringPolicy<>();
Expand All @@ -302,7 +306,7 @@ public void testHeaderFooterWritten() throws IOException, InterruptedException {

for (int i = 0; i < 100; i++) {
rfa.doAppend("data" + i);
File file = new File(CoreTestConstants.OUTPUT_DIR_PREFIX + "header-" + fixedWindowRollingPolicy.getMaxIndex() + ".log");
File file = new File(namePrefix + fixedWindowRollingPolicy.getMaxIndex() + ".log");
if (file.exists()) {
break;
}
Expand All @@ -311,7 +315,7 @@ public void testHeaderFooterWritten() throws IOException, InterruptedException {
rfa.stop();

for (int i = 0; i < fixedWindowRollingPolicy.getMaxIndex(); i++) {
File file = new File(CoreTestConstants.OUTPUT_DIR_PREFIX + "header-" + i + ".log");
File file = new File(namePrefix + i + ".log");
Assertions.assertTrue(file.exists());
List<String> lines = Files.readAllLines(file.toPath());
Assertions.assertTrue(lines.size() > 2, "At least 2 lines per file are expected in " + file);
Expand Down

0 comments on commit 67c24f6

Please sign in to comment.