Skip to content

Commit

Permalink
jenkinsci#185 Support shortlog lines that stretch into next buffer. A…
Browse files Browse the repository at this point in the history
…dd test
  • Loading branch information
tszmytka committed Jul 30, 2020
1 parent debc7ee commit 31b6b09
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private ActionContext findLastActionBefore(File logFile, Collection<String> seri
return new ActionContext(lastAction, partialLine + new String(buf, startInBuff, eolPos - startInBuff + eol.length, UTF_8));
} else {
// line extends to the next buffer
partialLine = new String(Arrays.copyOfRange(buf, startInBuff, buf.length - 1), UTF_8);
partialLine = new String(Arrays.copyOfRange(buf, startInBuff, buf.length), UTF_8);
}
}
totalRead += read;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,20 @@ public void setUp() throws Exception {

@Test
public void canCreateActionForShortlog() {
final String eol = "\n";
canCreateActionForShortlog(shortlogActionCreator, eol, "testlog.log");
canCreateActionForShortlog(shortlogActionCreator, "[Pipeline] echo\n", "testlog.log");
}

@Test
public void canCreateActionForShortlogForWindows() {
final String eol = "\r\n";
canCreateActionForShortlog(new ShortlogActionCreator(lineIdentifier, eol), eol, "testlog-crlf.log");
canCreateActionForShortlog(new ShortlogActionCreator(lineIdentifier, eol), "[Pipeline] echo" + eol, "testlog-crlf.log");
}

private void canCreateActionForShortlog(ShortlogActionCreator shortlogActionCreator, String eol, String logFile) {
private void canCreateActionForShortlog(ShortlogActionCreator shortlogActionCreator, String shortlogLine, String logFile) {
final String lineHash = "mock-line-hash";
final ColorizedAction colorizedAction = new ColorizedAction("xterm", ColorizedAction.Command.START);
final String serializedNote = "<mock-serialized-note-start>";
when(lineIdentifier.hash(eq("[Pipeline] echo" + eol), eq(1L))).thenReturn(lineHash);
when(lineIdentifier.hash(eq(shortlogLine), eq(1L))).thenReturn(lineHash);

final File file = new File(getClass().getResource(String.join("/", "", getClass().getName().replace('.', '/'), logFile)).getFile());
final HashMap<String, ColorizedAction> startActions = new HashMap<>();
Expand Down Expand Up @@ -106,4 +105,10 @@ public void wontCreateActionIfActionIsNotActiveAtShortlogLimit() {
assertNull(shortlogActionCreator.createActionForShortlog(file, startActions, 3));
verify(lineIdentifier, never()).hash(anyString(), anyLong());
}

@Test
public void canCreateActionForShortlogOnLogLineExceedingBufferSize() {
final String s = "[Pipeline] echo a very very very long line,a very very very long line,a very very very long line,a very very very long line,a very very very long line";
canCreateActionForShortlog(shortlogActionCreator, s + "\n", "testlog-long.log");
}
}
Loading

0 comments on commit 31b6b09

Please sign in to comment.