JournaledEditsCache { int retrieveEdits(long requestedStartTxn, int maxTxns, List<ByteBuffer> outputBuffers) throws IOException { int txnCount = 0; try (AutoCloseableLock l = readLock.acquire()) { if (lowestTxnId == INVALID_TXN_ID || requestedStartTxn < lowestTxnId) { throw getCacheMissException(requestedStartTxn); } else if (requestedStartTxn > highestTxnId) { return 0; } outputBuffers.add(layoutHeader); Iterator<Map.Entry<Long, byte[]>> incrBuffIter = dataMap.tailMap(dataMap.floorKey(requestedStartTxn), true) .entrySet().iterator(); long prevTxn = requestedStartTxn; byte[] prevBuf = null; while ((txnCount < maxTxns) && (incrBuffIter.hasNext() || prevBuf != null)) { long currTxn; byte[] currBuf; if (incrBuffIter.hasNext()) { Map.Entry<Long, byte[]> ent = incrBuffIter.next(); currTxn = ent.getKey(); currBuf = ent.getValue(); } else { currTxn = highestTxnId + 1; currBuf = null; } if (prevBuf != null) { outputBuffers.add(ByteBuffer.wrap(prevBuf)); txnCount += currTxn - Math.max(requestedStartTxn, prevTxn); } prevTxn = currTxn; prevBuf = currBuf; } } ByteBuffer firstBuf = outputBuffers.get(1); firstBuf.position( findTransactionPosition(firstBuf.array(), requestedStartTxn)); if (txnCount > maxTxns) { ByteBuffer lastBuf = outputBuffers.get(outputBuffers.size() - 1); int limit = findTransactionPosition(lastBuf.array(), requestedStartTxn + maxTxns); lastBuf.limit(limit); txnCount = maxTxns; } return txnCount; } JournaledEditsCache(Configuration conf);   }
@Test(expected = JournaledEditsCache.CacheMissException.class) public void testReadUninitializedCache() throws Exception { cache.retrieveEdits(1, 10, new ArrayList<>()); }