/** Tests whether the getIterator method works as our expectation. */ @Test public void testIterator() throws Exception { Log log = getLog(); // Appends 100 transactions. appendTxns(log, new Zxid(0, 0), 100); Random rand = new Random(); Zxid begZxid = new Zxid(0, rand.nextInt(100)); Log.LogIterator iter = log.getIterator(begZxid); // Make sure it starts from the correct zxid. Assert.assertEquals(begZxid, iter.next().getZxid()); // Starts from negative zxid. iter = log.getIterator(new Zxid(0, -1)); Assert.assertEquals(new Zxid(0, 0), iter.next().getZxid()); }
/** Gets transaction id of all the transactions after zxid in log. */ List<Zxid> getZxids(Log log, Zxid startZxid) throws IOException { List<Zxid> zxids = new ArrayList<Zxid>(); try (Log.LogIterator iter = log.getIterator(startZxid)) { while (iter.hasNext()) { Zxid zxid = iter.next().getZxid(); zxids.add(zxid); } } return zxids; }
@Test(expected = RuntimeException.class) public void testCorruptTxn() throws Exception { if (logClass == (Class<?>) SimpleLog.class) { Log log = getLog(); appendTxns(log, new Zxid(0, 0), 1); // Corrupts Transaction. corruptFile(20); // Iterating the log will trigger the checksum error. log.getIterator(log.getLatestZxid()); log.close(); } else { throw new RuntimeException("Simulated exception for RollingLog."); } }