-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-30777] also allow slaves to decorate logger
- Loading branch information
Showing
3 changed files
with
84 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
test/src/test/java/hudson/console/ConsoleLogFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package hudson.console; | ||
|
||
import hudson.model.Computer; | ||
import hudson.model.Run; | ||
import hudson.slaves.SlaveComputer; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.TestExtension; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
/** | ||
* @author Kohsuke Kawaguchi | ||
*/ | ||
public class ConsoleLogFilterTest extends Assert { | ||
@Rule | ||
public JenkinsRule r = new JenkinsRule(); | ||
|
||
/** | ||
* Checks | ||
*/ | ||
@Issue("JENKINS-30777") | ||
@Test public void decorateSlaveLog() throws Exception { | ||
SlaveComputer c = r.createSlave().getComputer(); | ||
c.connect(false).get(); | ||
assertTrue(c.getLog().contains("[["+c.getName()+"]] ")); | ||
} | ||
|
||
@TestExtension | ||
public static class Impl extends ConsoleLogFilter { | ||
@Override | ||
public OutputStream decorateLogger(Run build, OutputStream logger) throws IOException, InterruptedException { | ||
return logger; | ||
} | ||
|
||
@Override | ||
public OutputStream decorateLogger(final Computer c, final OutputStream out) throws IOException, InterruptedException { | ||
return new LineTransformationOutputStream() { | ||
@Override | ||
protected void eol(byte[] b, int len) throws IOException { | ||
out.write(("[["+c.getName()+"]] ").getBytes()); | ||
out.write(b, 0, len); | ||
} | ||
}; | ||
} | ||
} | ||
} |