diff options
author | Harald Musum <musum@yahooinc.com> | 2022-10-26 14:32:08 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2022-10-26 14:32:08 +0200 |
commit | 16b382e21ad5658e93314fc7b424492fd5a5d220 (patch) | |
tree | d64a5bdbf589d010c27f5225c6d7ff05e3f610ed /configserver | |
parent | eddd0562097024157ce3bd381cdbbc45996eecb9 (diff) |
Fix and improve test
Diffstat (limited to 'configserver')
-rw-r--r-- | configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java index e93b80076e8..e8d969119f9 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java @@ -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 |