use of co.cask.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);
}
use of co.cask.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);
}
Aggregations