@Test public void purgeAllOldTests() { Multimap<String, TestTime> radioTests = buildFakeTestTimes("radio", 10); Instant twoDaysAgo = Clock.systemUTC().instant().minus(2, ChronoUnit.DAYS); TestTime oldTest = new TestTime("oldTest", 0, false, null, Timestamp.from(twoDaysAgo)); radioTests.put("radio", oldTest); Map<String, Multimap<String, TestTime>> cache = Maps.newHashMap(); cache.put("fakeBuild", radioTests); FileStore fileStore = new FileStore(cache); fileStore.purgeObsoleteTests(); Set<TestTime> times = new HashSet<>(cache.get("fakeBuild").asMap().get("radio")); assertTrue(!times.contains(oldTest)); }
@Override @Scheduled(fixedDelay = 3_600_000) public synchronized void purgeObsoleteTests() { for(Map.Entry<String, Multimap<String, TestTime>> entry : fullCache.entrySet()) { Map<String, Collection<TestTime>> projectTimes = entry.getValue().asMap(); for (Map.Entry<String, Collection<TestTime>> project : projectTimes.entrySet()) { Collection<TestTime> projectTestTimes = project.getValue(); Set<TestTime> obsoleteTests = PersistenceUtil.findObsoleteTests(projectTestTimes); for (Iterator<TestTime> it = projectTestTimes.iterator(); it.hasNext(); ) { TestTime test = it.next(); if(obsoleteTests.contains(test)) { LOG.info("Removing obsolete test " + test.getTestName() + " on project " + project.getKey() + " on build " + entry.getKey()); it.remove(); } } } } }
FileStore implements TestStore { @Override @Scheduled(fixedDelay = 3_600_000) public synchronized void purgeObsoleteTests() { for(Map.Entry<String, Multimap<String, TestTime>> entry : fullCache.entrySet()) { Map<String, Collection<TestTime>> projectTimes = entry.getValue().asMap(); for (Map.Entry<String, Collection<TestTime>> project : projectTimes.entrySet()) { Collection<TestTime> projectTestTimes = project.getValue(); Set<TestTime> obsoleteTests = PersistenceUtil.findObsoleteTests(projectTestTimes); for (Iterator<TestTime> it = projectTestTimes.iterator(); it.hasNext(); ) { TestTime test = it.next(); if(obsoleteTests.contains(test)) { LOG.info("Removing obsolete test " + test.getTestName() + " on project " + project.getKey() + " on build " + entry.getKey()); it.remove(); } } } } } }
FileStore implements TestStore { @Override @Scheduled(fixedDelay = 3_600_000) public synchronized void purgeObsoleteTests() { for(Map.Entry<String, Multimap<String, TestTime>> entry : fullCache.entrySet()) { Map<String, Collection<TestTime>> projectTimes = entry.getValue().asMap(); for (Map.Entry<String, Collection<TestTime>> project : projectTimes.entrySet()) { Collection<TestTime> projectTestTimes = project.getValue(); Set<TestTime> obsoleteTests = PersistenceUtil.findObsoleteTests(projectTestTimes); for (Iterator<TestTime> it = projectTestTimes.iterator(); it.hasNext(); ) { TestTime test = it.next(); if(obsoleteTests.contains(test)) { LOG.info("Removing obsolete test " + test.getTestName() + " on project " + project.getKey() + " on build " + entry.getKey()); it.remove(); } } } } } FileStore();  FileStore(Map<String, Multimap<String, TestTime>> fullCache); }
FileStore implements TestStore { @Override @Scheduled(fixedDelay = 3_600_000) public synchronized void purgeObsoleteTests() { for(Map.Entry<String, Multimap<String, TestTime>> entry : fullCache.entrySet()) { Map<String, Collection<TestTime>> projectTimes = entry.getValue().asMap(); for (Map.Entry<String, Collection<TestTime>> project : projectTimes.entrySet()) { Collection<TestTime> projectTestTimes = project.getValue(); Set<TestTime> obsoleteTests = PersistenceUtil.findObsoleteTests(projectTestTimes); for (Iterator<TestTime> it = projectTestTimes.iterator(); it.hasNext(); ) { TestTime test = it.next(); if(obsoleteTests.contains(test)) { LOG.info("Removing obsolete test " + test.getTestName() + " on project " + project.getKey() + " on build " + entry.getKey()); it.remove(); } } } } } FileStore();  FileStore(Map<String, Multimap<String, TestTime>> fullCache); @PostConstruct void init(); @Override synchronized Map<String, Collection<TestTime>> getTestTimes(String buildName); @Override synchronized void addTestTimes(String project, List<TestSuite> testTimes, String host, String build); @Override synchronized void clearTestTimes(String build); @Override @Scheduled(fixedDelay = 3_600_000) synchronized void purgeObsoleteTests(); @Scheduled(fixedDelay = 60_000) void writeTestsToFile(); }
FileStore implements TestStore { @Override @Scheduled(fixedDelay = 3_600_000) public synchronized void purgeObsoleteTests() { for(Map.Entry<String, Multimap<String, TestTime>> entry : fullCache.entrySet()) { Map<String, Collection<TestTime>> projectTimes = entry.getValue().asMap(); for (Map.Entry<String, Collection<TestTime>> project : projectTimes.entrySet()) { Collection<TestTime> projectTestTimes = project.getValue(); Set<TestTime> obsoleteTests = PersistenceUtil.findObsoleteTests(projectTestTimes); for (Iterator<TestTime> it = projectTestTimes.iterator(); it.hasNext(); ) { TestTime test = it.next(); if(obsoleteTests.contains(test)) { LOG.info("Removing obsolete test " + test.getTestName() + " on project " + project.getKey() + " on build " + entry.getKey()); it.remove(); } } } } } FileStore();  FileStore(Map<String, Multimap<String, TestTime>> fullCache); @PostConstruct void init(); @Override synchronized Map<String, Collection<TestTime>> getTestTimes(String buildName); @Override synchronized void addTestTimes(String project, List<TestSuite> testTimes, String host, String build); @Override synchronized void clearTestTimes(String build); @Override @Scheduled(fixedDelay = 3_600_000) synchronized void purgeObsoleteTests(); @Scheduled(fixedDelay = 60_000) void writeTestsToFile();  }