RpkiRepositoryCleanupService { public long cleanupRpkiRepositories() { final InstantWithoutNanos unreferencedSince = InstantWithoutNanos.now().minus(cleanupGraceDuration); final Pair<Long, Long> deleted = Time.timed(() -> storage.writeTx(tx -> rpkiRepositories.deleteUnreferencedRepositories(tx, unreferencedSince))); log.info("Removed {} RPKI repositories that have not been referenced since {}, took {}ms", deleted.getLeft(), unreferencedSince, deleted.getRight()); return deleted.getLeft(); } RpkiRepositoryCleanupService(
            @Value("${rpki.validator.rpki.repository.cleanup.grace.duration:P7D}") Duration cleanupGraceDuration,
            Storage storage
    ); long cleanupRpkiRepositories();  }
@Test public void should_delete_repositories_not_referenced_during_validation() throws Exception { TrustAnchor trustAnchor = TestObjects.newTrustAnchor(); wtx0(tx -> this.getTrustAnchors().add(tx, trustAnchor)); final Ref<TrustAnchor> trustAnchorRef = rtx(tx -> this.getTrustAnchors().makeRef(tx, trustAnchor.key())); RpkiRepository repository = wtx(tx -> this.getRpkiRepositories().register(tx, trustAnchorRef, "rsync: assertThat(rtx(tx -> rpkiRepositories.findRsyncRepositories(tx).collect(Collectors.toList())), hasSize(1)); assertThat(subject.cleanupRpkiRepositories(), is(0L)); repository.getTrustAnchors().put(trustAnchorRef, InstantWithoutNanos.from(ZonedDateTime.now().minusDays(20).toInstant())); wtx0(tx -> rpkiRepositories.update(tx, repository)); assertThat(subject.cleanupRpkiRepositories(), is(1L)); assertThat(rtx(tx -> rpkiRepositories.findRsyncRepositories(tx).collect(Collectors.toList())), is(empty())); }