use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class GelfChunkAggregatorTest method tooManyChunks.
@Test
public void tooManyChunks() {
final ChannelBuffer[] chunks = createChunkedMessage(129 * 1024, 1024);
int i = 1;
for (final ChannelBuffer chunk : chunks) {
final CodecAggregator.Result result = aggregator.addChunk(chunk);
if (i == 129) {
assertFalse("Message invalidated (chunk #" + i + ")", result.isValid());
assertNull("Message discarded (chunk #" + i + ")", result.getMessage());
} else {
assertTrue("Incomplete message valid (chunk #" + i + ")", result.isValid());
assertNull("Message not complete (chunk #" + i + ")", result.getMessage());
}
i++;
}
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class GelfChunkAggregatorTest method manyChunks.
@Test
public void manyChunks() {
// creates 5 chunks
final ChannelBuffer[] chunks = createChunkedMessage(4096 + 512, 1024);
int i = 0;
for (final ChannelBuffer chunk : chunks) {
i++;
final CodecAggregator.Result result = aggregator.addChunk(chunk);
assertTrue(result.isValid());
if (i == 5) {
assertNotNull("message should've been assembled from chunks", result.getMessage());
assertEquals(1, counterValueNamed(metricRegistry, COMPLETE_MESSAGES));
assertEquals(5, counterValueNamed(metricRegistry, CHUNK_COUNTER));
assertEquals(0, counterValueNamed(metricRegistry, WAITING_MESSAGES));
assertEquals(0, counterValueNamed(metricRegistry, EXPIRED_CHUNKS));
assertEquals(0, counterValueNamed(metricRegistry, EXPIRED_MESSAGES));
assertEquals(0, counterValueNamed(metricRegistry, DUPLICATE_CHUNKS));
} else {
assertNull("chunks not complete", result.getMessage());
assertEquals("message not complete yet", 0, counterValueNamed(metricRegistry, COMPLETE_MESSAGES));
assertEquals(i, counterValueNamed(metricRegistry, CHUNK_COUNTER));
assertEquals("one message waiting", 1, counterValueNamed(metricRegistry, WAITING_MESSAGES));
assertEquals(0, counterValueNamed(metricRegistry, EXPIRED_CHUNKS));
assertEquals(0, counterValueNamed(metricRegistry, EXPIRED_MESSAGES));
assertEquals(0, counterValueNamed(metricRegistry, DUPLICATE_CHUNKS));
}
}
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class GelfCodecTest method decodeBuildsValidMessageObject.
@Test
public void decodeBuildsValidMessageObject() throws Exception {
final String json = "{" + "\"version\": \"1.1\"," + "\"host\": \"example.org\"," + "\"short_message\": \"A short message that helps you identify what is going on\"," + "\"full_message\": \"Backtrace here\\n\\nMore stuff\"," + "\"timestamp\": 1385053862.3072," + "\"level\": 1," + "\"_user_id\": 9001," + "\"_some_info\": \"foo\"," + "\"_some_env_var\": \"bar\"" + "}";
final RawMessage rawMessage = new RawMessage(json.getBytes(StandardCharsets.UTF_8));
final Message message = codec.decode(rawMessage);
assertThat(message).isNotNull();
assertThat(message.getField("source")).isEqualTo("example.org");
assertThat(message.getField("message")).isEqualTo("A short message that helps you identify what is going on");
assertThat(message.getField("user_id")).isEqualTo(9001L);
assertThat(message.getFieldNames()).containsOnly("_id", "source", "message", "full_message", "timestamp", "level", "user_id", "some_info", "some_env_var");
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class GelfCodecTest method decodeFiltersOutVersionField.
@Test
public void decodeFiltersOutVersionField() throws Exception {
final String json = "{" + "\"version\": \"1.1\"," + "\"host\": \"example.org\"," + "\"short_message\": \"A short message that helps you identify what is going on\"" + "}";
final RawMessage rawMessage = new RawMessage(json.getBytes(StandardCharsets.UTF_8));
final Message message = codec.decode(rawMessage);
assertThat(message).isNotNull();
assertThat(message.getField("version")).isNull();
assertThat(message.getField("source")).isEqualTo("example.org");
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class SyslogCodecTest method testDecodeUnstructuredWithFullMessage.
@Test
public void testDecodeUnstructuredWithFullMessage() throws Exception {
when(configuration.getBoolean(SyslogCodec.CK_STORE_FULL_MESSAGE)).thenReturn(true);
final Message message = codec.decode(buildRawMessage(UNSTRUCTURED));
assertNotNull(message);
assertEquals(message.getMessage(), "c4dc57ba1ebb syslog-ng[7208]: syslog-ng starting up; version='3.5.3'");
assertEquals(message.getField("timestamp"), new DateTime(YEAR + "-10-21T12:09:37"));
assertEquals(message.getField("source"), "c4dc57ba1ebb");
assertEquals(message.getField("level"), 5);
assertEquals(message.getField("facility"), "syslogd");
assertEquals(message.getField("full_message"), UNSTRUCTURED);
}
Aggregations