Beispiel #1
0
 @Test
 public void testTruncateFile() throws Exception {
   Log log = getLog();
   // Appends  100 transactions.
   appendTxns(log, new Zxid(0, 0), 100);
   // Make sure latest zxid is <0, 99>.
   Assert.assertEquals(new Zxid(0, 99), log.getLatestZxid());
   int truncIdx = new Random().nextInt(100);
   log.truncate(new Zxid(0, truncIdx));
   // Make sure latest zxid is <0, truncIdx>.
   Assert.assertEquals(new Zxid(0, truncIdx), log.getLatestZxid());
 }
Beispiel #2
0
 @Test
 public void testGetLatestZxid() throws Exception {
   Log log = getLog();
   // Appends  100 transactions.
   appendTxns(log, new Zxid(0, 0), 100);
   // Make sure latest zxid is <0, 99>.
   Assert.assertEquals(new Zxid(0, 99), log.getLatestZxid());
 }
Beispiel #3
0
 @Test
 public void testTruncateAndAppend() throws Exception {
   Log log = getLog();
   // Appends  100 transactions.
   appendTxns(log, new Zxid(0, 0), 100);
   // Make sure latest zxid is <0, 99>.
   Assert.assertEquals(new Zxid(0, 99), log.getLatestZxid());
   // Truncates file after <0, 77>
   log.truncate(new Zxid(0, 77));
   // Make sure latest zxid is <0, 77>.
   Assert.assertEquals(new Zxid(0, 77), log.getLatestZxid());
   // Appends 22 more transactions.
   appendTxns(log, new Zxid(0, 78), 22);
   List<Zxid> zxids = getZxids(log, Zxid.ZXID_NOT_EXIST);
   // Make sure latest zxid is <0, 99>
   Assert.assertEquals(new Zxid(0, 99), log.getLatestZxid());
   // Check all the transactions are in log.
   Assert.assertEquals(100, zxids.size());
 }
Beispiel #4
0
 @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.");
   }
 }