### Question:
LogCleaner implements Runnable { @Override public void run() { LOG.info("Starting log cleanup"); long startTime = System.currentTimeMillis(); long tillTime = startTime - retentionDurationMs; List<FileMetadataCleaner.DeletedEntry> deleteEntries = fileMetadataCleaner.scanAndGetFilesToDelete(tillTime, fileCleanupBatchSize); int deleteCount = 0; int failureCount = 0; for (FileMetadataCleaner.DeletedEntry deletedEntry : deleteEntries) { try { boolean status = Locations.getLocationFromAbsolutePath(locationFactory, deletedEntry.getPath()).delete(); if (!status) { failureCount++; LOG.warn("File {} delete failed", deletedEntry.getPath()); } else { deleteCount++; LOG.trace("File {} deleted by log cleanup", deletedEntry.getPath()); } } catch (IOException e) { LOG.warn("Exception while deleting file {}", deletedEntry.getPath(), e); } } long completionTime = System.currentTimeMillis(); LOG.info("File cleanup completed, Successful file deletes - {}. Failed file deletes - {}. Log Cleanup took {} ms", deleteCount, failureCount, (completionTime - startTime)); } LogCleaner(FileMetadataCleaner fileMetadataCleaner, LocationFactory locationFactory,
                    long retentionDurationMs, int fileCleanupBatchSize); @Override void run();  }### Answer:
@Test public void testLogCleanup() throws Exception { TransactionRunner transactionRunner = injector.getInstance(TransactionRunner.class); FileMetadataCleaner fileMetadataCleaner = new FileMetadataCleaner(transactionRunner); LocationFactory locationFactory = injector.getInstance(LocationFactory.class); long currentTime = System.currentTimeMillis(); LogPathIdentifier logPathIdentifier = new LogPathIdentifier("testNs", "testApp", "testEntity"); FileMetaDataWriter fileMetaDataWriter = new FileMetaDataWriter(transactionRunner); long startTime = currentTime - 5000; Location dirLocation = locationFactory.create("logs"); dirLocation.mkdirs(); for (int i = 0; i < 20; i++) { Location location = dirLocation.append("test" + i); location.createNew(); fileMetaDataWriter.writeMetaData(logPathIdentifier, startTime + i, startTime + i, location); } Assert.assertEquals(20, dirLocation.list().size()); LogCleaner logCleaner = new LogCleaner(fileMetadataCleaner, locationFactory, 100, 60); logCleaner.run(); FileMetaDataReader fileMetaDataReader = injector.getInstance(FileMetaDataReader.class); Assert.assertEquals(0, fileMetaDataReader.listFiles(logPathIdentifier, 0, System.currentTimeMillis()).size()); }