use of com.codahale.metrics.MetricRegistry in project graylog2-server by Graylog2.
the class KafkaJournalTest method segmentRotation.
@Test
public void segmentRotation() throws Exception {
final Size segmentSize = Size.kilobytes(1L);
final KafkaJournal journal = new KafkaJournal(journalDirectory, scheduler, segmentSize, Duration.standardHours(1), Size.kilobytes(10L), Duration.standardDays(1), 1_000_000, Duration.standardMinutes(1), 100, new MetricRegistry(), serverStatus);
createBulkChunks(journal, segmentSize, 3);
final File[] files = journalDirectory.listFiles();
assertNotNull(files);
assertTrue("there should be files in the journal directory", files.length > 0);
final File[] messageJournalDir = journalDirectory.listFiles((FileFilter) and(directoryFileFilter(), nameFileFilter("messagejournal-0")));
assertTrue(messageJournalDir.length == 1);
final File[] logFiles = messageJournalDir[0].listFiles((FileFilter) and(fileFileFilter(), suffixFileFilter(".log")));
assertEquals("should have two journal segments", 3, logFiles.length);
}
use of com.codahale.metrics.MetricRegistry in project graylog2-server by Graylog2.
the class KafkaJournalTest method readAtLeastOne.
@Test
public void readAtLeastOne() throws Exception {
final Journal journal = new KafkaJournal(journalDirectory, scheduler, Size.megabytes(100L), Duration.standardHours(1), Size.megabytes(5L), Duration.standardHours(1), 1_000_000, Duration.standardMinutes(1), 100, new MetricRegistry(), serverStatus);
final byte[] idBytes = "id".getBytes(UTF_8);
final byte[] messageBytes = "message1".getBytes(UTF_8);
final long position = journal.write(idBytes, messageBytes);
// Trying to read 0 should always read at least 1 entry.
final List<Journal.JournalReadEntry> messages = journal.read(0);
final Journal.JournalReadEntry firstMessage = Iterators.getOnlyElement(messages.iterator());
assertEquals("message1", new String(firstMessage.getPayload(), UTF_8));
}
use of com.codahale.metrics.MetricRegistry in project graylog2-server by Graylog2.
the class KafkaJournalTest method serverStatusThrottledIfJournalUtilizationIsHigherThanThreshold.
@Test
public void serverStatusThrottledIfJournalUtilizationIsHigherThanThreshold() throws Exception {
serverStatus.running();
final Size segmentSize = Size.kilobytes(1L);
final KafkaJournal journal = new KafkaJournal(journalDirectory, scheduler, segmentSize, Duration.standardSeconds(1L), Size.kilobytes(4L), Duration.standardHours(1L), 1_000_000, Duration.standardSeconds(1L), 90, new MetricRegistry(), serverStatus);
createBulkChunks(journal, segmentSize, 4);
journal.flushDirtyLogs();
journal.cleanupLogs();
assertThat(serverStatus.getLifecycle()).isEqualTo(Lifecycle.THROTTLED);
}
use of com.codahale.metrics.MetricRegistry in project graylog2-server by Graylog2.
the class KafkaJournalTest method writeAndRead.
@Test
public void writeAndRead() throws IOException {
final Journal journal = new KafkaJournal(journalDirectory, scheduler, Size.megabytes(100L), Duration.standardHours(1), Size.megabytes(5L), Duration.standardHours(1), 1_000_000, Duration.standardMinutes(1), 100, new MetricRegistry(), serverStatus);
final byte[] idBytes = "id".getBytes(UTF_8);
final byte[] messageBytes = "message".getBytes(UTF_8);
final long position = journal.write(idBytes, messageBytes);
final List<Journal.JournalReadEntry> messages = journal.read(1);
final Journal.JournalReadEntry firstMessage = Iterators.getOnlyElement(messages.iterator());
assertEquals("message", new String(firstMessage.getPayload(), UTF_8));
}
use of com.codahale.metrics.MetricRegistry in project graylog2-server by Graylog2.
the class KafkaJournalTest method maxSegmentSize.
@Test
public void maxSegmentSize() throws Exception {
final Size segmentSize = Size.kilobytes(1L);
final KafkaJournal journal = new KafkaJournal(journalDirectory, scheduler, segmentSize, Duration.standardHours(1), Size.kilobytes(10L), Duration.standardDays(1), 1_000_000, Duration.standardMinutes(1), 100, new MetricRegistry(), serverStatus);
long size = 0L;
long maxSize = segmentSize.toBytes();
final List<Journal.Entry> list = Lists.newArrayList();
while (size <= maxSize) {
final byte[] idBytes = ("the1-id").getBytes(UTF_8);
final byte[] messageBytes = ("the1-message").getBytes(UTF_8);
size += idBytes.length + messageBytes.length;
list.add(journal.createEntry(idBytes, messageBytes));
}
// Make sure all messages have been written
assertThat(journal.write(list)).isEqualTo(list.size() - 1);
}
Aggregations