Skip to content

Commit f7603dc

Browse files
authored
AllLinesParser: Enable draining of stdout (#8670)
1 parent 6c6023b commit f7603dc

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

utils/src/main/java/com/cloud/utils/script/OutputInterpreter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ public String interpret(BufferedReader reader) throws IOException {
137137
public String getLines() {
138138
return allLines;
139139
}
140+
141+
@Override
142+
public boolean drain() {
143+
return true;
144+
}
140145
}
141146

142147
public static class LineByLineOutputLogger extends OutputInterpreter {

utils/src/test/java/com/cloud/utils/ScriptTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ public String interpret(BufferedReader reader) throws IOException {
111111
Assert.assertNotNull(value);
112112
}
113113

114+
@Test
115+
public void executeWithOutputInterpreterAllLinesParserLargeOutput() {
116+
Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
117+
OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
118+
Script script = new Script("seq");
119+
script.add("-f");
120+
script.add("my text to test cloudstack %g");
121+
script.add("4096"); // AllLinesParser doesn't work with that amount of data
122+
String value = script.execute(parser);
123+
// it is a stack trace in this case as string
124+
Assert.assertNull(value);
125+
Assert.assertEquals(129965, parser.getLines().length());
126+
}
127+
114128
@Test
115129
public void runSimpleBashScriptNotExisting() {
116130
Assume.assumeTrue(SystemUtils.IS_OS_LINUX);

0 commit comments

Comments
 (0)