Search in sources :

Example 11 with CloseableIterator

use of co.cask.cdap.api.dataset.lib.CloseableIterator in project cdap by caskdata.

the class MockLogReader method getLog.

@Override
public CloseableIterator<LogEvent> getLog(LoggingContext loggingContext, long fromTimeMs, long toTimeMs, Filter filter) {
    CollectingCallback collectingCallback = new CollectingCallback();
    // since its just for test case, we don't need to lazily read logs (which is the purpose of returning an Iterator)
    long fromOffset = getOffset(fromTimeMs / 1000);
    long toOffset = getOffset(toTimeMs / 1000);
    getLogNext(loggingContext, new ReadRange(fromTimeMs, toTimeMs, fromOffset), (int) (toOffset - fromOffset), filter, collectingCallback);
    final Iterator<LogEvent> iterator = collectingCallback.getLogEvents().iterator();
    return new CloseableIterator<LogEvent>() {

        @Override
        public boolean hasNext() {
            return iterator.hasNext();
        }

        @Override
        public LogEvent next() {
            return iterator.next();
        }

        @Override
        public void remove() {
            iterator.remove();
        }

        @Override
        public void close() {
        // no-op
        }
    };
}
Also used : CloseableIterator(co.cask.cdap.api.dataset.lib.CloseableIterator) ReadRange(co.cask.cdap.logging.read.ReadRange) LogEvent(co.cask.cdap.logging.read.LogEvent)

Aggregations

CloseableIterator (co.cask.cdap.api.dataset.lib.CloseableIterator)11 Test (org.junit.Test)6 KeyValue (co.cask.cdap.api.dataset.lib.KeyValue)3 ApplicationManager (co.cask.cdap.test.ApplicationManager)3 IOException (java.io.IOException)3 AbstractCloseableIterator (co.cask.cdap.api.dataset.lib.AbstractCloseableIterator)2 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)2 Message (co.cask.cdap.api.messaging.Message)2 MessageFetcher (co.cask.cdap.api.messaging.MessageFetcher)2 MessagingAdmin (co.cask.cdap.api.messaging.MessagingAdmin)2 TopicNotFoundException (co.cask.cdap.api.messaging.TopicNotFoundException)2 LogEvent (co.cask.cdap.logging.read.LogEvent)2 LogLocation (co.cask.cdap.logging.write.LogLocation)2 SparkManager (co.cask.cdap.test.SparkManager)2 NoSuchElementException (java.util.NoSuchElementException)2 TransactionExecutor (org.apache.tephra.TransactionExecutor)2 TxRunnable (co.cask.cdap.api.TxRunnable)1 DatasetContext (co.cask.cdap.api.data.DatasetContext)1 FileSet (co.cask.cdap.api.dataset.lib.FileSet)1 ObjectMappedTable (co.cask.cdap.api.dataset.lib.ObjectMappedTable)1