Fix and improve test
@@ -265,13 +265,13 @@ public class ApplicationRepositoryTest {
Duration keepFileReferencesDuration = Duration.ofSeconds(4);
// Add file reference that is not in use and should be deleted (older than 'keepFileReferencesDuration')
- File filereferenceDirOldest = createFilereferenceOnDisk(new File(fileReferencesDir, "foo"));
+ File filereferenceDirOldest = createFileReferenceOnDisk(new File(fileReferencesDir, "bar"));
clock.advance(Duration.ofSeconds(1));
// Add file references that are not in use and could be deleted
IntStream.range(0, 3).forEach(i -> {
try {
- createFilereferenceOnDisk(new File(fileReferencesDir, "bar" + i));
+ createFileReferenceOnDisk(new File(fileReferencesDir, "baz" + i));
} catch (IOException e) {
fail(e.getMessage());
}
@@ -280,7 +280,7 @@ public class ApplicationRepositoryTest {
clock.advance(keepFileReferencesDuration);
// Add file reference that is not in use, but should not be deleted (newer than 'keepFileReferencesDuration')
- File filereferenceDirNewest = createFilereferenceOnDisk(new File(fileReferencesDir, "baz"));
+ File filereferenceDirNewest = createFileReferenceOnDisk(new File(fileReferencesDir, "foo"));
applicationRepository = new ApplicationRepository.Builder()
.withTenantRepository(tenantRepository)
@@ -293,26 +293,25 @@ public class ApplicationRepositoryTest {
PrepareParams prepareParams = new PrepareParams.Builder().applicationId(applicationId()).ignoreValidationErrors(true).build();
deployApp(new File("src/test/apps/app"), prepareParams);
- List<String> toBeDeleted = applicationRepository.deleteUnusedFileDistributionReferences(fileReferencesDir,
+ List<String> deleted = applicationRepository.deleteUnusedFileDistributionReferences(fileReferencesDir,
keepFileReferencesDuration,
2);
- Collections.sort(toBeDeleted);
- List<String> expected = new ArrayList<>(List.of("foo", "bar0", "bar1"));
+ Collections.sort(deleted);
+ List<String> expected = new ArrayList<>(List.of("bar", "baz0"));
Collections.sort(expected);
- assertEquals(expected, toBeDeleted);
- // foo, bar0 and bar1 will be deleted, 2 newest ones (bar2 and baz) will be kept no matter how old they are
+ assertEquals(expected, deleted);
+ // bar and baz0 will be deleted, 2 of the old ones (baz1 and baz2) will be kept and foo is not old enough to be considered
assertFalse(filereferenceDirOldest.exists());
- assertFalse(new File(fileReferencesDir, "bar0").exists());
- assertFalse(new File(fileReferencesDir, "bar1").exists());
+ assertFalse(new File(fileReferencesDir, "baz0").exists());
assertTrue(filereferenceDirNewest.exists());
}
- private File createFilereferenceOnDisk(File filereferenceDir) throws IOException {
- assertTrue(filereferenceDir.mkdir());
- File file = new File(filereferenceDir, "bar");
- IOUtils.writeFile(file, Utf8.toBytes("test"));
- file.setLastModified(clock.instant().toEpochMilli());
- return filereferenceDir;
+ private File createFileReferenceOnDisk(File filereference) throws IOException {
+ File fileReferenceDir = filereference.getParentFile();
+ fileReferenceDir.mkdir();
+ IOUtils.writeFile(filereference, Utf8.toBytes("test"));
+ filereference.setLastModified(clock.instant().toEpochMilli());
+ return filereference;
}
@Test
