|
28 | 28 |
|
29 | 29 | import hudson.model.TaskListener; |
30 | 30 | import java.io.File; |
| 31 | +import java.nio.charset.StandardCharsets; |
| 32 | +import org.apache.commons.io.FileUtils; |
31 | 33 | import org.junit.Before; |
32 | 34 | import org.junit.Rule; |
33 | 35 | import org.junit.Test; |
@@ -55,6 +57,48 @@ public class FileLogStorageTest extends LogStorageTestBase { |
55 | 57 | assertOverallLog(0, lines("stuff"), true); |
56 | 58 | } |
57 | 59 |
|
| 60 | + @Test public void corruptIndex() throws Exception { |
| 61 | + FileUtils.writeStringToFile(log, "before\n1\nbetween1\n2\nbetween2\n3\nafter", StandardCharsets.UTF_8); |
| 62 | + FileUtils.writeStringToFile(new File(log + "-index"), "7 1\n?\n18 2\n20\n29 3\n31", StandardCharsets.UTF_8); |
| 63 | + assertStepLog("1", 0, "", false); |
| 64 | + assertStepLog("2", 0, "2\n", false); |
| 65 | + assertStepLog("3", 0, "3\n", false); |
| 66 | + } |
| 67 | + |
| 68 | + @Test public void samePositionInIndex() throws Exception { |
| 69 | + FileUtils.writeStringToFile(log, "before\n1\nbetween1\n2\nbetween2\n3\nafter", StandardCharsets.UTF_8); |
| 70 | + FileUtils.writeStringToFile(new File(log + "-index"), "7 1\n7\n18 2\n20\n29 3\n31", StandardCharsets.UTF_8); |
| 71 | + assertStepLog("1", 0, "", false); |
| 72 | + assertStepLog("2", 0, "2\n", false); |
| 73 | + assertStepLog("3", 0, "3\n", false); |
| 74 | + } |
| 75 | + |
| 76 | + @Test public void decrementedPositionInIndex() throws Exception { |
| 77 | + FileUtils.writeStringToFile(log, "before\n1\nbetween1\n2\nbetween2\n3\nafter", StandardCharsets.UTF_8); |
| 78 | + FileUtils.writeStringToFile(new File(log + "-index"), "7 1\n0\n18 2\n20\n29 3\n31", StandardCharsets.UTF_8); |
| 79 | + assertStepLog("1", 0, "", false); |
| 80 | + assertStepLog("2", 0, "2\n", false); |
| 81 | + assertStepLog("3", 0, "3\n", false); |
| 82 | + } |
| 83 | + |
| 84 | + @Test public void corruptIndexAtEnd() throws Exception { |
| 85 | + FileUtils.writeStringToFile(log, "before\n1\nafter", StandardCharsets.UTF_8); |
| 86 | + FileUtils.writeStringToFile(new File(log + "-index"), "7 1\n?", StandardCharsets.UTF_8); |
| 87 | + assertStepLog("1", 0, "", false); |
| 88 | + } |
| 89 | + |
| 90 | + @Test public void samePositionInIndexAtEnd() throws Exception { |
| 91 | + FileUtils.writeStringToFile(log, "before\n1\nafter", StandardCharsets.UTF_8); |
| 92 | + FileUtils.writeStringToFile(new File(log + "-index"), "7 1\n7", StandardCharsets.UTF_8); |
| 93 | + assertStepLog("1", 0, "", false); |
| 94 | + } |
| 95 | + |
| 96 | + @Test public void decrementedPositionInIndexAtEnd() throws Exception { |
| 97 | + FileUtils.writeStringToFile(log, "before\n1\nafter", StandardCharsets.UTF_8); |
| 98 | + FileUtils.writeStringToFile(new File(log + "-index"), "7 1\n0", StandardCharsets.UTF_8); |
| 99 | + assertStepLog("1", 0, "", false); |
| 100 | + } |
| 101 | + |
58 | 102 | @Test public void interruptionDoesNotCloseStream() throws Exception { |
59 | 103 | LogStorage ls = createStorage(); |
60 | 104 | TaskListener overall = ls.overallListener(); |
|
0 commit comments