Search in sources :

Example 1 with DistributedLogReader

use of io.cdap.cdap.logging.read.DistributedLogReader in project cdap by caskdata.

the class TestDistributedLogReader method testDistributedLogNext.

public void testDistributedLogNext(ReadRange readRange, LoggingContext loggingContext, int numCalls, int step, String assertMessage, int assertCount, int startIndex) throws Exception {
    DistributedLogReader distributedLogReader = injector.getInstance(DistributedLogReader.class);
    int count = 0;
    for (int i = 0; i < numCalls; ++i) {
        LoggingTester.LogCallback callback = new LoggingTester.LogCallback();
        distributedLogReader.getLogNext(loggingContext, readRange, step, Filter.EMPTY_FILTER, callback);
        List<LogEvent> events = callback.getEvents();
        Assert.assertFalse(events.isEmpty());
        readRange = ReadRange.createFromRange(events.get(events.size() - 1).getOffset());
        for (LogEvent event : events) {
            Assert.assertEquals(assertMessage + (startIndex + count++), event.getLoggingEvent().getFormattedMessage());
            // All logs generated by this test have value "system" in MDC property ".origin"
            Assert.assertEquals("system", event.getLoggingEvent().getMDCPropertyMap().get(".origin"));
        }
    }
    Assert.assertEquals(assertCount, count);
}
Also used : DistributedLogReader(io.cdap.cdap.logging.read.DistributedLogReader) LogEvent(io.cdap.cdap.logging.read.LogEvent) Checkpoint(io.cdap.cdap.logging.meta.Checkpoint)

Example 2 with DistributedLogReader

use of io.cdap.cdap.logging.read.DistributedLogReader in project cdap by caskdata.

the class TestDistributedLogReader method testDistributedLogPrev.

private void testDistributedLogPrev(ReadRange readRange, LoggingContext loggingContext, int numCalls, int step, String assertMessage, int assertCount) throws Exception {
    DistributedLogReader distributedLogReader = injector.getInstance(DistributedLogReader.class);
    for (int i = 0; i < numCalls; ++i) {
        LoggingTester.LogCallback callback = new LoggingTester.LogCallback();
        distributedLogReader.getLogPrev(loggingContext, readRange, step, Filter.EMPTY_FILTER, callback);
        List<LogEvent> events = callback.getEvents();
        Assert.assertFalse(events.isEmpty());
        readRange = ReadRange.createToRange(events.get(0).getOffset());
        Collections.reverse(events);
        for (LogEvent event : events) {
            Assert.assertEquals(assertMessage + --assertCount, event.getLoggingEvent().getFormattedMessage());
            // All logs generated by this test have value "system" in MDC property ".origin"
            Assert.assertEquals("system", event.getLoggingEvent().getMDCPropertyMap().get(".origin"));
        }
    }
    Assert.assertEquals(0, assertCount);
}
Also used : DistributedLogReader(io.cdap.cdap.logging.read.DistributedLogReader) LogEvent(io.cdap.cdap.logging.read.LogEvent) Checkpoint(io.cdap.cdap.logging.meta.Checkpoint)

Aggregations

Checkpoint (io.cdap.cdap.logging.meta.Checkpoint)2 DistributedLogReader (io.cdap.cdap.logging.read.DistributedLogReader)2 LogEvent (io.cdap.cdap.logging.read.LogEvent)2