@Test
/**
 * Test that LevelDb repair is attempted at least once during
 * serviceInit for LeveldbTimelineStore in case open fails the
 * first time.
 */
public void testLevelDbRepair() throws IOException {

  LeveldbTimelineStore store = new LeveldbTimelineStore();
  JniDBFactory factory = Mockito.mock(JniDBFactory.class);
  Mockito.when(
      factory.open(Mockito.any(File.class), Mockito.any(Options.class)))
      .thenThrow(new IOException()).thenCallRealMethod();
  store.setFactory(factory);
  //Create the LevelDb in a different location
  File path = new File("target", this.getClass().getSimpleName() +
      "-tmpDir1").getAbsoluteFile();
  Configuration conf = new Configuration(this.config);
  conf.set(YarnConfiguration.TIMELINE_SERVICE_LEVELDB_PATH,
      path.getAbsolutePath());
  try {
    store.init(conf);
    Mockito.verify(factory, Mockito.times(1))
        .repair(Mockito.any(File.class), Mockito.any(Options.class));
    FileFilter fileFilter = new WildcardFileFilter(
        "*" + LeveldbTimelineStore.BACKUP_EXT +"*");
    Assert.assertTrue(path.listFiles(fileFilter).length > 0);
  } finally {
    store.close();
    fsContext.delete(new Path(path.getAbsolutePath()), true);
  }
}