LeveldbTimelineStore extends AbstractService implements TimelineStore { @VisibleForTesting void setFactory(JniDBFactory fact) { this.factory = fact; } LeveldbTimelineStore(); @Override TimelineEntity getEntity(String entityId, String entityType,
      EnumSet<Field> fields); @Override TimelineEvents getEntityTimelines(String entityType,
      SortedSet<String> entityIds, Long limit, Long windowStart,
      Long windowEnd, Set<String> eventType); @Override TimelineEntities getEntities(String entityType,
      Long limit, Long windowStart, Long windowEnd, String fromId, Long fromTs,
      NameValuePair primaryFilter, Collection<NameValuePair> secondaryFilters,
      EnumSet<Field> fields, CheckAcl checkAcl); @Override TimelinePutResponse put(TimelineEntities entities); @Private @VisibleForTesting TimelinePutResponse putWithNoDomainId(TimelineEntities entities); @Override void put(TimelineDomain domain); @Override TimelineDomain getDomain(String domainId); @Override TimelineDomains getDomains(String owner);  }
@Test 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); 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); } }