Skip to content

Commit 7f65340

Browse files
committed
minor changes
Signed-off-by: ceki <[email protected]>
1 parent 8d2262d commit 7f65340

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

logback-core/src/test/java/ch/qos/logback/core/rolling/RenameUtilTest.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
import ch.qos.logback.core.testUtil.CoreTestConstants;
2222
import ch.qos.logback.core.testUtil.RandomUtil;
2323
import ch.qos.logback.core.status.testUtil.StatusChecker;
24+
import ch.qos.logback.core.util.EnvUtil;
2425
import ch.qos.logback.core.util.StatusPrinter;
2526

27+
import ch.qos.logback.core.util.StatusPrinter2;
2628
import org.junit.jupiter.api.BeforeEach;
2729
import org.junit.jupiter.api.Disabled;
2830
import org.junit.jupiter.api.Test;
@@ -32,6 +34,7 @@
3234
import java.io.FileNotFoundException;
3335
import java.io.FileOutputStream;
3436
import java.io.IOException;
37+
import java.nio.channels.FileLock;
3538

3639
import static org.junit.jupiter.api.Assertions.assertEquals;
3740
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -41,6 +44,7 @@ public class RenameUtilTest {
4144
Encoder<Object> encoder;
4245
Context context = new ContextBase();
4346
StatusChecker statusChecker = new StatusChecker(context);
47+
StatusPrinter2 statusPrinter2 = new StatusPrinter2();
4448

4549
long currentTime = System.currentTimeMillis();
4650
int diff = RandomUtil.getPositiveInt();
@@ -66,12 +70,18 @@ public void renameToNonExistingDirectory() throws IOException, RolloverFailure {
6670
String randomTARGETDir = CoreTestConstants.OUTPUT_DIR_PREFIX + diff2;
6771

6872
renameUtil.rename(fromFile.toString(), new File(randomTARGETDir + "/to.test").toString());
69-
StatusPrinter.printInCaseOfErrorsOrWarnings(context);
73+
statusPrinter2.printInCaseOfErrorsOrWarnings(context);
7074
assertTrue(statusChecker.isErrorFree(0));
7175
}
7276

7377
@Test // LOGBACK-1054
7478
public void renameLockedAbstractFile_LOGBACK_1054() throws IOException, RolloverFailure {
79+
80+
// this tests only works on windows
81+
if(!EnvUtil.isWindows()) {
82+
return;
83+
}
84+
7585
RenameUtil renameUtil = new RenameUtil();
7686
renameUtil.setContext(context);
7787

@@ -82,12 +92,15 @@ public void renameLockedAbstractFile_LOGBACK_1054() throws IOException, Rollover
8292

8393
makeFile(src);
8494

85-
FileInputStream fisLock = new FileInputStream(src);
95+
// open file in a way preventing simple rename in order to force call to
96+
// areOnDifferentVolumes() method. This only works on Windows
97+
98+
FileInputStream fis = new FileInputStream(src);
8699
renameUtil.rename(src, target);
87100
// release the lock
88-
fisLock.close();
101+
fis.close();
89102

90-
StatusPrinter.print(context);
103+
statusPrinter2.print(context);
91104
assertEquals(0, statusChecker.matchCount("Parent of target file ." + target + ". is null"));
92105
}
93106

@@ -101,7 +114,7 @@ public void MANUAL_renamingOnDifferentVolumesOnLinux() throws IOException, Rollo
101114
makeFile(src);
102115

103116
renameUtil.rename(src, "/tmp/foo" + diff + ".txt");
104-
StatusPrinter.print(context);
117+
statusPrinter2.print(context);
105118
}
106119

107120
@Test
@@ -114,7 +127,7 @@ public void MANUAL_renamingOnDifferentVolumesOnWindows() throws IOException, Rol
114127
makeFile(src);
115128

116129
renameUtil.rename(src, "d:/tmp/foo" + diff + ".txt");
117-
StatusPrinter.print(context);
130+
statusPrinter2.print(context);
118131
assertTrue(statusChecker.isErrorFree(0));
119132
}
120133

0 commit comments

Comments
 (0)