mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
Correctly sets the default codec to java_line. Fixes buffer handling for events whose encodings do not fit into the buffer.
Fixes #10673
This commit is contained in:
parent
d1e41f3908
commit
25158bdddd
2 changed files with 23 additions and 2 deletions
|
@ -20,7 +20,7 @@ import java.util.concurrent.CountDownLatch;
|
|||
public class Stdout implements Output {
|
||||
|
||||
public static final PluginConfigSpec<Codec> CODEC_CONFIG =
|
||||
PluginConfigSpec.codecSetting("codec", "java-line");
|
||||
PluginConfigSpec.codecSetting("codec", "java_line");
|
||||
|
||||
private Codec codec;
|
||||
private OutputStream outputStream;
|
||||
|
@ -57,7 +57,7 @@ public class Stdout implements Output {
|
|||
do {
|
||||
encodeCompleted = codec.encode(e, encodeBuffer);
|
||||
outputStream.write(encodeBuffer.array(), encodeBuffer.position(), encodeBuffer.limit());
|
||||
encodeBuffer.flip();
|
||||
encodeBuffer.clear();
|
||||
}
|
||||
while (!encodeCompleted);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.logstash.plugins.outputs;
|
|||
|
||||
import co.elastic.logstash.api.Event;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.logstash.plugins.ConfigurationImpl;
|
||||
import org.logstash.plugins.TestContext;
|
||||
|
@ -69,4 +70,24 @@ public class StdoutTest {
|
|||
e3.setField("myField", "event3");
|
||||
return Arrays.asList(e1, e2, e3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEventLargerThanBuffer() {
|
||||
StringBuilder message = new StringBuilder();
|
||||
String repeatedMessage = "foo";
|
||||
for (int k = 0; k < (16 * 1024 / repeatedMessage.length()); k++) {
|
||||
message.append("foo");
|
||||
}
|
||||
|
||||
org.logstash.Event e = new org.logstash.Event();
|
||||
e.setField("message", message.toString());
|
||||
|
||||
OutputStream dummyOutputStream = new ByteArrayOutputStream(17 * 1024);
|
||||
Stdout stdout = new Stdout(ID, new ConfigurationImpl(Collections.emptyMap(), new TestPluginFactory()),
|
||||
new TestContext(), dummyOutputStream);
|
||||
stdout.output(Collections.singletonList(e));
|
||||
stdout.stop();
|
||||
|
||||
Assert.assertTrue(dummyOutputStream.toString().contains(message.toString()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue