Code review comment: Well, the purpose of the fix was deleting files. As there haven't been any test for that so far I added them to show that now all files are deleted properly with HS cleaning feature enabled.

Code under review:
private void runArchiveExpirationTest(boolean cleanupExpiredJobs) throws Exception {
		int numExpiredJobs = cleanupExpiredJobs ? 1 : 0;
		int numJobs = 3;
		for (int x = 0; x < numJobs; x++) {
			runJob();
		}
		waitForArchivesCreation(numJobs);

		CountDownLatch numExpectedArchivedJobs = new CountDownLatch(numJobs);
		CountDownLatch numExpectedExpiredJobs = new CountDownLatch(numExpiredJobs);

		Configuration historyServerConfig = createTestConfiguration(cleanupExpiredJobs);

		HistoryServer hs =
			new HistoryServer(
				historyServerConfig,
				(event) -> {
					switch (event.getType()){
						case CREATED:
							numExpectedArchivedJobs.countDown();
							break;
						case DELETED:
							numExpectedExpiredJobs.countDown();
							break;
					}
				});

		try {
			hs.start();
			String baseUrl = "http:
			assertTrue(numExpectedArchivedJobs.await(10L, TimeUnit.SECONDS));

			Collection<JobDetails> jobs = getJobsOverview(baseUrl).getJobs();
			Assert.assertEquals(numJobs, jobs.size());

			String jobIdToDelete = jobs.stream()
				.findFirst()
				.map(JobDetails::getJobId)
				.map(JobID::toString)
				.orElseThrow(() -> new IllegalStateException("Expected at least one existing job"));

			assertHSFilesExistence(jobIdToDelete, true);
			
			Files.deleteIfExists(jmDirectory.toPath().resolve(jobIdToDelete));

			assertTrue(numExpectedExpiredJobs.await(10L, TimeUnit.SECONDS));

			
			Collection<JobDetails> jobsAfterDeletion = getJobsOverview(baseUrl).getJobs();
			Assert.assertEquals(numJobs - numExpiredJobs, jobsAfterDeletion.size());
			Assert.assertEquals(1 - numExpiredJobs, jobsAfterDeletion.stream()
				.map(JobDetails::getJobId)
				.map(JobID::toString)
				.filter(jobId -> jobId.equals(jobIdToDelete))
				.count());
			assertHSFilesExistence(jobIdToDelete, !cleanupExpiredJobs);
		} finally {
			hs.stop();
		}
	}

Line commented on: assertHSFilesExistence(jobIdToDelete, !cleanupExpiredJobs);

Revised code:
private void runArchiveExpirationTest(boolean cleanupExpiredJobs) throws Exception {
		int numExpiredJobs = cleanupExpiredJobs ? 1 : 0;
		int numJobs = 3;
		for (int x = 0; x < numJobs; x++) {
			runJob();
		}
		waitForArchivesCreation(numJobs);

		CountDownLatch numExpectedArchivedJobs = new CountDownLatch(numJobs);
		CountDownLatch firstArchiveExpiredLatch = new CountDownLatch(numExpiredJobs);
		CountDownLatch allArchivesExpiredLatch = new CountDownLatch(cleanupExpiredJobs ? numJobs : 0);

		Configuration historyServerConfig = createTestConfiguration(cleanupExpiredJobs);

		HistoryServer hs =
			new HistoryServer(
				historyServerConfig,
				(event) -> {
					switch (event.getType()){
						case CREATED:
							numExpectedArchivedJobs.countDown();
							break;
						case DELETED:
							firstArchiveExpiredLatch.countDown();
							allArchivesExpiredLatch.countDown();
							break;
					}
				});

		try {
			hs.start();
			String baseUrl = "http:
			assertTrue(numExpectedArchivedJobs.await(10L, TimeUnit.SECONDS));

			Collection<JobDetails> jobs = getJobsOverview(baseUrl).getJobs();
			Assert.assertEquals(numJobs, jobs.size());

			String jobIdToDelete = jobs.stream()
				.findFirst()
				.map(JobDetails::getJobId)
				.map(JobID::toString)
				.orElseThrow(() -> new IllegalStateException("Expected at least one existing job"));

			
			Files.deleteIfExists(jmDirectory.toPath().resolve(jobIdToDelete));

			assertTrue(firstArchiveExpiredLatch.await(10L, TimeUnit.SECONDS));

			
			Collection<JobDetails> jobsAfterDeletion = getJobsOverview(baseUrl).getJobs();
			Assert.assertEquals(numJobs - numExpiredJobs, jobsAfterDeletion.size());
			Assert.assertEquals(1 - numExpiredJobs, jobsAfterDeletion.stream()
				.map(JobDetails::getJobId)
				.map(JobID::toString)
				.filter(jobId -> jobId.equals(jobIdToDelete))
				.count());

			
			List<String> remainingJobIds = jobsAfterDeletion.stream()
				.map(JobDetails::getJobId)
				.map(JobID::toString)
				.collect(Collectors.toList());

			for (String remainingJobId : remainingJobIds) {
				Files.deleteIfExists(jmDirectory.toPath().resolve(remainingJobId));
			}

			assertTrue(allArchivesExpiredLatch.await(10L, TimeUnit.SECONDS));

			assertJobFilesCleanedUp(cleanupExpiredJobs);
		} finally {
			hs.stop();
		}
	}