|
38 | 38 | import java.io.UncheckedIOException;
|
39 | 39 |
|
40 | 40 | import static org.hamcrest.Matchers.containsString;
|
| 41 | +import static org.hamcrest.Matchers.equalTo; |
41 | 42 | import static org.hamcrest.Matchers.hasToString;
|
42 | 43 | import static org.hamcrest.Matchers.instanceOf;
|
43 | 44 | import static org.hamcrest.Matchers.not;
|
@@ -127,6 +128,22 @@ public void testReformatSetting() {
|
127 | 128 | assertTrue(log.isReformat());
|
128 | 129 | }
|
129 | 130 |
|
| 131 | + public void testReformatIsFalseAndSourceIsTrim() { |
| 132 | + String json = "\n\n{ \"fieldName\": 123 } \n "; |
| 133 | + BytesReference source = new BytesArray(json); |
| 134 | + ParsedDocument pd = new ParsedDocument(new NumericDocValuesField("version", 1), |
| 135 | + SeqNoFieldMapper.SequenceIDFields.emptySeqID(), "id", |
| 136 | + "test", null, null, source, XContentType.JSON, null); |
| 137 | + Index index = new Index("foo", "123"); |
| 138 | + // Turning off reformatting so the document is in logs as provided |
| 139 | + SlowLogParsedDocumentPrinter p = new SlowLogParsedDocumentPrinter(index, pd, 10, false, 1000); |
| 140 | + String logLine = p.toString(); |
| 141 | + |
| 142 | + //expect the new lines and white characters to be trimmed |
| 143 | + assertThat(logLine, containsString("source[{")); |
| 144 | + assertThat(logLine.split("\n").length, equalTo(1)); |
| 145 | + } |
| 146 | + |
130 | 147 | public void testLevelSetting() {
|
131 | 148 | SlowLogLevel level = randomFrom(SlowLogLevel.values());
|
132 | 149 | IndexMetaData metaData = newIndexMeta("index", Settings.builder()
|
|
0 commit comments