From 934e3b3b4add008796f8b2848c8f97b8bfac7f59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20Lauk=C3=B6tter?= Date: Mon, 17 Feb 2025 14:12:56 +0100 Subject: [PATCH 1/7] Rename DeleteAllXNormsPort to DeleteAllXDokumentePort RISDEV-6774 --- .../adapter/output/s3/BucketService.java | 8 +++---- .../output/DeleteAllPrivateDokumentePort.java | 15 ++++++++++++ .../output/DeleteAllPrivateNormsPort.java | 15 ------------ .../output/DeleteAllPublicDokumentePort.java | 14 +++++++++++ .../port/output/DeleteAllPublicNormsPort.java | 14 ----------- .../application/service/PublishService.java | 16 ++++++------- .../service/PublishServiceTest.java | 24 +++++++++++-------- .../s3/BucketServiceIntegrationTest.java | 4 ++-- 8 files changed, 57 insertions(+), 53 deletions(-) create mode 100644 backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPrivateDokumentePort.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPrivateNormsPort.java create mode 100644 backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPublicDokumentePort.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPublicNormsPort.java diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java index b03aaa7cc..899e03b6a 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java @@ -51,8 +51,8 @@ public class BucketService PublishPrivateNormPort, DeletePublicNormPort, DeletePrivateNormPort, - DeleteAllPublicNormsPort, - DeleteAllPrivateNormsPort, + DeleteAllPublicDokumentePort, + DeleteAllPrivateDokumentePort, PublishChangelogsPort { @Value("${otc.obs.private.bucket-name}") @@ -103,12 +103,12 @@ public void deletePublicNorm(DeletePublicNormPort.Command command) throws Bucket } @Override - public void deleteAllPublicNorms() { + public void deleteAllPublicDokumente() { deleteAllExceptChangelog(publicS3Client, publicBucketName); } @Override - public void deleteAllPrivateNorms() { + public void deleteAllPrivateDokumente() { deleteAllExceptChangelog(privateS3Client, privateBucketName); } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPrivateDokumentePort.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPrivateDokumentePort.java new file mode 100644 index 000000000..a3a1ce36c --- /dev/null +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPrivateDokumentePort.java @@ -0,0 +1,15 @@ +package de.bund.digitalservice.ris.norms.application.port.output; + +import de.bund.digitalservice.ris.norms.domain.entity.Dokument; + +/** + * Interface representing the output port for deleting multiple {@link Dokument} entities from a storage location designated + * for private data. + */ +public interface DeleteAllPrivateDokumentePort { + /** + * Deletes the specified {@link Dokument} entities from a designated private storage location. + * + */ + void deleteAllPrivateDokumente(); +} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPrivateNormsPort.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPrivateNormsPort.java deleted file mode 100644 index 8c154d416..000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPrivateNormsPort.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.bund.digitalservice.ris.norms.application.port.output; - -import de.bund.digitalservice.ris.norms.domain.entity.Norm; - -/** - * Interface representing the output port for deleting multiple {@link Norm} entities from a storage location designated - * for private data. - */ -public interface DeleteAllPrivateNormsPort { - /** - * Deletes the specified {@link Norm} entities from a designated private storage location. - * - */ - void deleteAllPrivateNorms(); -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPublicDokumentePort.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPublicDokumentePort.java new file mode 100644 index 000000000..1ecd18383 --- /dev/null +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPublicDokumentePort.java @@ -0,0 +1,14 @@ +package de.bund.digitalservice.ris.norms.application.port.output; + +import de.bund.digitalservice.ris.norms.domain.entity.Dokument; + +/** + * Interface representing the output port for deleting all {@link Dokument} entities from a storage location designated + * for public data. + */ +public interface DeleteAllPublicDokumentePort { + /** + * Deletes all {@link Dokument} entities from a designated public storage location. + */ + void deleteAllPublicDokumente(); +} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPublicNormsPort.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPublicNormsPort.java deleted file mode 100644 index dd150e450..000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPublicNormsPort.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.bund.digitalservice.ris.norms.application.port.output; - -import de.bund.digitalservice.ris.norms.domain.entity.Norm; - -/** - * Interface representing the output port for deleting all {@link Norm} entities from a storage location designated - * for public data. - */ -public interface DeleteAllPublicNormsPort { - /** - * Deletes all {@link Norm} entities from a designated public storage location. - */ - void deleteAllPublicNorms(); -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java index c3a43eaca..88575a89e 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java @@ -33,8 +33,8 @@ public class PublishService implements PublishNormUseCase { private final DeletePublicNormPort deletePublicNormPort; private final DeletePrivateNormPort deletePrivateNormPort; private final LoadLastMigrationLogPort loadLastMigrationLogPort; - private final DeleteAllPublicNormsPort deleteAllPublicNormsPort; - private final DeleteAllPrivateNormsPort deleteAllPrivateNormsPort; + private final DeleteAllPublicDokumentePort deleteAllPublicDokumentePort; + private final DeleteAllPrivateDokumentePort deleteAllPrivateDokumentePort; private final PublishChangelogsPort publishChangelogsPort; public PublishService( @@ -46,8 +46,8 @@ public PublishService( DeletePublicNormPort deletePublicNormPort, DeletePrivateNormPort deletePrivateNormPort, LoadLastMigrationLogPort loadLastMigrationLogPort, - DeleteAllPublicNormsPort deleteAllPublicNormsPort, - DeleteAllPrivateNormsPort deleteAllPrivateNormsPort, + DeleteAllPublicDokumentePort deleteAllPublicDokumentePort, + DeleteAllPrivateDokumentePort deleteAllPrivateDokumentePort, PublishChangelogsPort publishChangelogsPort ) { this.loadNormManifestationElisByPublishStatePort = loadNormManifestationElisByPublishStatePort; @@ -58,8 +58,8 @@ public PublishService( this.deletePublicNormPort = deletePublicNormPort; this.deletePrivateNormPort = deletePrivateNormPort; this.loadLastMigrationLogPort = loadLastMigrationLogPort; - this.deleteAllPublicNormsPort = deleteAllPublicNormsPort; - this.deleteAllPrivateNormsPort = deleteAllPrivateNormsPort; + this.deleteAllPublicDokumentePort = deleteAllPublicDokumentePort; + this.deleteAllPrivateDokumentePort = deleteAllPrivateDokumentePort; this.publishChangelogsPort = publishChangelogsPort; } @@ -85,8 +85,8 @@ public void processQueuedFilesForPublish() { if (migrationLog.getSize() <= 0) { throw new MigrationJobException(); } - deleteAllPublicNormsPort.deleteAllPublicNorms(); - deleteAllPrivateNormsPort.deleteAllPrivateNorms(); + deleteAllPublicDokumentePort.deleteAllPublicDokumente(); + deleteAllPrivateDokumentePort.deleteAllPrivateDokumente(); log.info("Deleted all norms in both buckets"); } }); diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/PublishServiceTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/PublishServiceTest.java index 13c6ff216..047feaa12 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/PublishServiceTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/PublishServiceTest.java @@ -32,9 +32,13 @@ class PublishServiceTest { final DeletePrivateNormPort deletePrivateNormPort = mock(DeletePrivateNormPort.class); - final DeleteAllPublicNormsPort deleteAllPublicNormsPort = mock(DeleteAllPublicNormsPort.class); + final DeleteAllPublicDokumentePort deleteAllPublicDokumentePort = mock( + DeleteAllPublicDokumentePort.class + ); - final DeleteAllPrivateNormsPort deleteAllPrivateNormsPort = mock(DeleteAllPrivateNormsPort.class); + final DeleteAllPrivateDokumentePort deleteAllPrivateDokumentePort = mock( + DeleteAllPrivateDokumentePort.class + ); final LoadNormPort loadNormPort = mock(LoadNormPort.class); final LoadLastMigrationLogPort loadLastMigrationLogPort = mock(LoadLastMigrationLogPort.class); @@ -50,8 +54,8 @@ class PublishServiceTest { deletePublicNormPort, deletePrivateNormPort, loadLastMigrationLogPort, - deleteAllPublicNormsPort, - deleteAllPrivateNormsPort, + deleteAllPublicDokumentePort, + deleteAllPrivateDokumentePort, publishChangelogsPort ); @@ -185,8 +189,8 @@ void deleteAllNormsIfMigrationLogExists() { ); // Check that deletion was called - verify(deleteAllPublicNormsPort, times(1)).deleteAllPublicNorms(); - verify(deleteAllPrivateNormsPort, times(1)).deleteAllPrivateNorms(); + verify(deleteAllPublicDokumentePort, times(1)).deleteAllPublicDokumente(); + verify(deleteAllPrivateDokumentePort, times(1)).deleteAllPrivateDokumente(); // Verify norm publishing actions verify(publishPublicNormPort, times(1)) @@ -227,8 +231,8 @@ void doNotdeleteAllNormsIfMigrationLogExistsButSizeIsZero() { ); // Check that deletion was called - verify(deleteAllPublicNormsPort, times(0)).deleteAllPublicNorms(); - verify(deleteAllPrivateNormsPort, times(0)).deleteAllPrivateNorms(); + verify(deleteAllPublicDokumentePort, times(0)).deleteAllPublicDokumente(); + verify(deleteAllPrivateDokumentePort, times(0)).deleteAllPrivateDokumente(); // Verify norm publishing actions verify(publishPublicNormPort, times(0)) @@ -262,8 +266,8 @@ void doNotDeleteNormsIfNoMigrationLogExists() { ); // Verify that deletion was NOT called - verify(deleteAllPublicNormsPort, never()).deleteAllPublicNorms(); - verify(deleteAllPrivateNormsPort, never()).deleteAllPrivateNorms(); + verify(deleteAllPublicDokumentePort, never()).deleteAllPublicDokumente(); + verify(deleteAllPrivateDokumentePort, never()).deleteAllPrivateDokumente(); // Verify norm publishing actions verify(publishPublicNormPort, times(1)) diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java index ec00bc223..1f161d519 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java @@ -190,7 +190,7 @@ void itDeletesAllNormsFromPublicBucket() { bucketService.publishPublicNorm(commandPublish2); // When - bucketService.deleteAllPublicNorms(); + bucketService.deleteAllPublicDokumente(); final PublishChangelogsPort.Command commandPublishChangelogs = new PublishChangelogsPort.Command(false); bucketService.publishChangelogs(commandPublishChangelogs); @@ -219,7 +219,7 @@ void itDeletesAllNormsFromPrivateBucket() { bucketService.publishPrivateNorm(commandPublish2); // When - bucketService.deleteAllPrivateNorms(); + bucketService.deleteAllPrivateDokumente(); final PublishChangelogsPort.Command commandPublishChangelogs = new PublishChangelogsPort.Command(false); bucketService.publishChangelogs(commandPublishChangelogs); From 1315a5bf90c94dc163e1fa5d0ed9c352d8e14888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20Lauk=C3=B6tter?= Date: Mon, 17 Feb 2025 14:56:49 +0100 Subject: [PATCH 2/7] Keep files modified since a date in bucket RISDEV-6774 --- .../adapter/output/s3/BucketService.java | 37 ++++++++++++++----- .../norms/adapter/output/s3/S3MockClient.java | 7 +++- .../output/DeleteAllPrivateDokumentePort.java | 14 ++++++- .../output/DeleteAllPublicDokumentePort.java | 15 +++++++- .../application/service/PublishService.java | 13 +++++-- .../service/PublishServiceTest.java | 12 +++--- .../s3/BucketServiceIntegrationTest.java | 24 +++++++----- 7 files changed, 89 insertions(+), 33 deletions(-) diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java index 899e03b6a..cb51d2f05 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java @@ -8,6 +8,7 @@ import de.bund.digitalservice.ris.norms.utils.XmlMapper; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.ArrayList; import java.util.List; import lombok.extern.slf4j.Slf4j; @@ -103,13 +104,21 @@ public void deletePublicNorm(DeletePublicNormPort.Command command) throws Bucket } @Override - public void deleteAllPublicDokumente() { - deleteAllExceptChangelog(publicS3Client, publicBucketName); + public void deleteAllPublicDokumente(DeleteAllPublicDokumentePort.Command command) { + deleteAllDokumenteLastModifiedBefore( + publicS3Client, + publicBucketName, + command.lastChangeBefore() + ); } @Override - public void deleteAllPrivateDokumente() { - deleteAllExceptChangelog(privateS3Client, privateBucketName); + public void deleteAllPrivateDokumente(DeleteAllPrivateDokumentePort.Command command) { + deleteAllDokumenteLastModifiedBefore( + privateS3Client, + privateBucketName, + command.lastChangeBefore() + ); } @Override @@ -235,7 +244,8 @@ private void deleteFromBucket( } /** - * Deletes all objects in the specified S3 bucket, except for the changelog files, which are contained within the "changelogs" folder + * Deletes all Dokumente in the specified S3 bucket, (not the changelog files) which have not been changed since the + * given date. * The deletion process handles pagination automatically if there are more than 1,000 objects in the bucket. *

* AWS S3 allows a maximum of 1,000 keys to be processed per delete request. This method retrieves and deletes objects @@ -244,10 +254,19 @@ private void deleteFromBucket( * * @param s3Client the S3 client used to interact with the S3 service * @param bucketName the name of the S3 bucket where the objects are located + * @param lastChangeBefore Dokumente that have been changed since this date are ignored */ - private void deleteAllExceptChangelog(final S3Client s3Client, final String bucketName) { + private void deleteAllDokumenteLastModifiedBefore( + final S3Client s3Client, + final String bucketName, + Instant lastChangeBefore + ) { try { - ListObjectsV2Request listRequest = ListObjectsV2Request.builder().bucket(bucketName).build(); + ListObjectsV2Request listRequest = ListObjectsV2Request + .builder() + .bucket(bucketName) + .prefix("eli") + .build(); ListObjectsV2Response listResponse; int objectsDeleted = 0; do { @@ -256,7 +275,7 @@ private void deleteAllExceptChangelog(final S3Client s3Client, final String buck for (S3Object s3Object : listResponse.contents()) { final String key = s3Object.key(); - if (!key.startsWith(Changelog.FOLDER + "/")) { + if (s3Object.lastModified().isBefore(lastChangeBefore)) { objectsToDelete.add(ObjectIdentifier.builder().key(key).build()); } } @@ -278,7 +297,7 @@ private void deleteAllExceptChangelog(final S3Client s3Client, final String buck throw new BucketException( BucketException.Operation.DELETE, bucketName, - "All norms could not be deleted", + "All dokumente could not be deleted", e ); } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/S3MockClient.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/S3MockClient.java index 9af7ceb26..959cb485e 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/S3MockClient.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/S3MockClient.java @@ -3,6 +3,7 @@ import jakarta.annotation.PostConstruct; import java.io.*; import java.nio.file.*; +import java.time.Instant; import java.util.List; import java.util.Objects; import java.util.stream.Stream; @@ -73,7 +74,11 @@ public ListObjectsV2Response listObjectsV2(ListObjectsV2Request listObjectsV2Req // If the file is not under 'eli', return only the file name key = path.getFileName().toString(); } - return S3Object.builder().key(key).build(); + return S3Object + .builder() + .key(key) + .lastModified(Instant.ofEpochMilli(path.toFile().lastModified())) + .build(); }) .toList(); diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPrivateDokumentePort.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPrivateDokumentePort.java index a3a1ce36c..52d55a50a 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPrivateDokumentePort.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPrivateDokumentePort.java @@ -1,6 +1,7 @@ package de.bund.digitalservice.ris.norms.application.port.output; import de.bund.digitalservice.ris.norms.domain.entity.Dokument; +import java.time.Instant; /** * Interface representing the output port for deleting multiple {@link Dokument} entities from a storage location designated @@ -8,8 +9,17 @@ */ public interface DeleteAllPrivateDokumentePort { /** - * Deletes the specified {@link Dokument} entities from a designated private storage location. + * Deletes all {@link Dokument} entities that have not been edited since the given date from a designated private + * storage location. * + * @param command command for deleting Dokumente */ - void deleteAllPrivateDokumente(); + void deleteAllPrivateDokumente(DeleteAllPrivateDokumentePort.Command command); + + /** + * Command for deleting dokumente + * + * @param lastChangeBefore Dokumente last edited after the given date are not deleted. + */ + record Command(Instant lastChangeBefore) {} } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPublicDokumentePort.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPublicDokumentePort.java index 1ecd18383..6b347f724 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPublicDokumentePort.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/DeleteAllPublicDokumentePort.java @@ -1,6 +1,7 @@ package de.bund.digitalservice.ris.norms.application.port.output; import de.bund.digitalservice.ris.norms.domain.entity.Dokument; +import java.time.Instant; /** * Interface representing the output port for deleting all {@link Dokument} entities from a storage location designated @@ -8,7 +9,17 @@ */ public interface DeleteAllPublicDokumentePort { /** - * Deletes all {@link Dokument} entities from a designated public storage location. + * Deletes all {@link Dokument} entities that have not been edited since the given date from a designated public + * storage location. + * + * @param command command for deleting Dokumente */ - void deleteAllPublicDokumente(); + void deleteAllPublicDokumente(DeleteAllPublicDokumentePort.Command command); + + /** + * Command for deleting dokumente + * + * @param lastChangeBefore Dokumente last edited after the given date are not deleted. + */ + record Command(Instant lastChangeBefore) {} } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java index 88575a89e..42d65ad72 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java @@ -7,6 +7,7 @@ import de.bund.digitalservice.ris.norms.domain.entity.eli.NormManifestationEli; import de.bund.digitalservice.ris.norms.utils.NodeParser; import de.bund.digitalservice.ris.norms.utils.exceptions.StorageException; +import java.time.Instant; import java.time.LocalDate; import java.time.ZoneId; import java.time.ZoneOffset; @@ -65,6 +66,9 @@ public PublishService( @Override public void processQueuedFilesForPublish() { + final Instant startOfProcessing = Instant.now(); + final LocalDate today = startOfProcessing.atZone(ZoneId.systemDefault()).toLocalDate(); + loadLastMigrationLogPort .loadLastMigrationLog() .ifPresent(migrationLog -> { @@ -72,7 +76,6 @@ public void processQueuedFilesForPublish() { .getCreatedAt() .atZone(ZoneId.systemDefault()) .toLocalDate(); - final LocalDate today = LocalDate.now(); final LocalDate yesterday = today.minusDays(1); if (createdAtDate.equals(today) || createdAtDate.equals(yesterday)) { log.info( @@ -85,8 +88,12 @@ public void processQueuedFilesForPublish() { if (migrationLog.getSize() <= 0) { throw new MigrationJobException(); } - deleteAllPublicDokumentePort.deleteAllPublicDokumente(); - deleteAllPrivateDokumentePort.deleteAllPrivateDokumente(); + deleteAllPublicDokumentePort.deleteAllPublicDokumente( + new DeleteAllPublicDokumentePort.Command(startOfProcessing) + ); + deleteAllPrivateDokumentePort.deleteAllPrivateDokumente( + new DeleteAllPrivateDokumentePort.Command(startOfProcessing) + ); log.info("Deleted all norms in both buckets"); } }); diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/PublishServiceTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/PublishServiceTest.java index 047feaa12..b0f3a22d1 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/PublishServiceTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/PublishServiceTest.java @@ -189,8 +189,8 @@ void deleteAllNormsIfMigrationLogExists() { ); // Check that deletion was called - verify(deleteAllPublicDokumentePort, times(1)).deleteAllPublicDokumente(); - verify(deleteAllPrivateDokumentePort, times(1)).deleteAllPrivateDokumente(); + verify(deleteAllPublicDokumentePort, times(1)).deleteAllPublicDokumente(any()); + verify(deleteAllPrivateDokumentePort, times(1)).deleteAllPrivateDokumente(any()); // Verify norm publishing actions verify(publishPublicNormPort, times(1)) @@ -231,8 +231,8 @@ void doNotdeleteAllNormsIfMigrationLogExistsButSizeIsZero() { ); // Check that deletion was called - verify(deleteAllPublicDokumentePort, times(0)).deleteAllPublicDokumente(); - verify(deleteAllPrivateDokumentePort, times(0)).deleteAllPrivateDokumente(); + verify(deleteAllPublicDokumentePort, times(0)).deleteAllPublicDokumente(any()); + verify(deleteAllPrivateDokumentePort, times(0)).deleteAllPrivateDokumente(any()); // Verify norm publishing actions verify(publishPublicNormPort, times(0)) @@ -266,8 +266,8 @@ void doNotDeleteNormsIfNoMigrationLogExists() { ); // Verify that deletion was NOT called - verify(deleteAllPublicDokumentePort, never()).deleteAllPublicDokumente(); - verify(deleteAllPrivateDokumentePort, never()).deleteAllPrivateDokumente(); + verify(deleteAllPublicDokumentePort, never()).deleteAllPublicDokumente(any()); + verify(deleteAllPrivateDokumentePort, never()).deleteAllPrivateDokumente(any()); // Verify norm publishing actions verify(publishPublicNormPort, times(1)) diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java index 1f161d519..a433c7024 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java @@ -17,6 +17,7 @@ import de.bund.digitalservice.ris.norms.integration.BaseS3MockIntegrationTest; import java.nio.file.Files; import java.nio.file.Path; +import java.time.Instant; import java.time.LocalDate; import java.util.Map; import java.util.Objects; @@ -190,7 +191,7 @@ void itDeletesAllNormsFromPublicBucket() { bucketService.publishPublicNorm(commandPublish2); // When - bucketService.deleteAllPublicDokumente(); + bucketService.deleteAllPublicDokumente(new DeleteAllPublicDokumentePort.Command(Instant.now())); final PublishChangelogsPort.Command commandPublishChangelogs = new PublishChangelogsPort.Command(false); bucketService.publishChangelogs(commandPublishChangelogs); @@ -209,17 +210,17 @@ void itDeletesAllNormsFromPrivateBucket() { // Given final Norm norm1 = Fixtures.loadNormFromDisk("SimpleNorm.xml"); final Norm norm2 = Fixtures.loadNormFromDisk("NormToBeReleased.xml"); - final PublishPrivateNormPort.Command commandPublish1 = new PublishPrivateNormPort.Command( - norm1 - ); - final PublishPrivateNormPort.Command commandPublish2 = new PublishPrivateNormPort.Command( - norm2 - ); - bucketService.publishPrivateNorm(commandPublish1); - bucketService.publishPrivateNorm(commandPublish2); + final Norm norm3 = Fixtures.loadNormFromDisk("NormWithMods.xml"); + + bucketService.publishPrivateNorm(new PublishPrivateNormPort.Command(norm1)); + bucketService.publishPrivateNorm(new PublishPrivateNormPort.Command(norm2)); + Instant afterTwoPublishes = Instant.now(); + bucketService.publishPrivateNorm(new PublishPrivateNormPort.Command(norm3)); // When - bucketService.deleteAllPrivateDokumente(); + bucketService.deleteAllPrivateDokumente( + new DeleteAllPrivateDokumentePort.Command(afterTwoPublishes) + ); final PublishChangelogsPort.Command commandPublishChangelogs = new PublishChangelogsPort.Command(false); bucketService.publishChangelogs(commandPublishChangelogs); @@ -227,10 +228,13 @@ void itDeletesAllNormsFromPrivateBucket() { // Then final Path filePath1 = getPrivatePath(norm1.getRegelungstext1()); final Path filePath2 = getPrivatePath(norm2.getRegelungstext1()); + final Path filePath3 = getPrivatePath(norm3.getRegelungstext1()); assertThat(Files.exists(filePath1)).isFalse(); assertThat(Files.exists(filePath2)).isFalse(); + assertThat(Files.exists(filePath3)).isTrue(); assertChangelogContains(false, PRIVATE_BUCKET, DELETED, norm1); assertChangelogContains(false, PRIVATE_BUCKET, DELETED, norm2); + assertChangelogContains(true, PRIVATE_BUCKET, CHANGED, norm3); } @Test From bd74dc4c9f06af83490804bbdd32590deb6bdcd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20Lauk=C3=B6tter?= Date: Mon, 17 Feb 2025 15:05:19 +0100 Subject: [PATCH 3/7] Delete the old files only after uploading the new once RISDEV-6774 --- .../application/service/PublishService.java | 39 ++++++++++--------- .../service/PublishServiceTest.java | 17 +------- 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java index 42d65ad72..4e2cee999 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java @@ -69,6 +69,22 @@ public void processQueuedFilesForPublish() { final Instant startOfProcessing = Instant.now(); final LocalDate today = startOfProcessing.atZone(ZoneId.systemDefault()).toLocalDate(); + List manifestationElis = + loadNormManifestationElisByPublishStatePort.loadNormManifestationElisByPublishState( + new LoadNormManifestationElisByPublishStatePort.Command(NormPublishState.QUEUED_FOR_PUBLISH) + ); + + log.info("Found {} norms that are queued for publishing", manifestationElis.size()); + + manifestationElis.forEach(manifestationEli -> { + log.info("Processing norm with manifestation eli {}", manifestationEli); + Optional norm = loadNormPort.loadNorm(new LoadNormPort.Command(manifestationEli)); + norm.ifPresent(this::processNorm); + if (norm.isEmpty()) { + log.error("Norm with manifestation eli {} not found", manifestationEli); + } + }); + loadLastMigrationLogPort .loadLastMigrationLog() .ifPresent(migrationLog -> { @@ -79,40 +95,27 @@ public void processQueuedFilesForPublish() { final LocalDate yesterday = today.minusDays(1); if (createdAtDate.equals(today) || createdAtDate.equals(yesterday)) { log.info( - "Migration log found with timestamp {} (UTC). Deleting all norms in both buckets", + "Migration log found with timestamp {} (UTC) and {} dokumente.", migrationLog .getCreatedAt() .atOffset(ZoneOffset.UTC) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), + migrationLog.getSize() ); if (migrationLog.getSize() <= 0) { throw new MigrationJobException(); } + log.info("Deleting all old dokumente in both buckets"); deleteAllPublicDokumentePort.deleteAllPublicDokumente( new DeleteAllPublicDokumentePort.Command(startOfProcessing) ); deleteAllPrivateDokumentePort.deleteAllPrivateDokumente( new DeleteAllPrivateDokumentePort.Command(startOfProcessing) ); - log.info("Deleted all norms in both buckets"); + log.info("Deleted all dokumente in both buckets"); } }); - List manifestationElis = - loadNormManifestationElisByPublishStatePort.loadNormManifestationElisByPublishState( - new LoadNormManifestationElisByPublishStatePort.Command(NormPublishState.QUEUED_FOR_PUBLISH) - ); - - log.info("Found {} norms that are queued for publishing", manifestationElis.size()); - - manifestationElis.forEach(manifestationEli -> { - log.info("Processing norm with manifestation eli {}", manifestationEli); - Optional norm = loadNormPort.loadNorm(new LoadNormPort.Command(manifestationEli)); - norm.ifPresent(this::processNorm); - if (norm.isEmpty()) { - log.error("Norm with manifestation eli {} not found", manifestationEli); - } - }); publishChangelogsPort.publishChangelogs(new PublishChangelogsPort.Command(true)); log.info("Publish job successfully completed."); } diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/PublishServiceTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/PublishServiceTest.java index b0f3a22d1..b315bb000 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/PublishServiceTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/PublishServiceTest.java @@ -220,27 +220,12 @@ void doNotdeleteAllNormsIfMigrationLogExistsButSizeIsZero() { when(loadLastMigrationLogPort.loadLastMigrationLog()).thenReturn(Optional.of(migrationLog)); // Migration log found // Then When - assertThatThrownBy(publishService::processQueuedFilesForPublish) .isInstanceOf(MigrationJobException.class); - // Then - verify(loadNormManifestationElisByPublishStatePort, times(0)) - .loadNormManifestationElisByPublishState( - argThat(command -> command.publishState() == NormPublishState.QUEUED_FOR_PUBLISH) - ); - - // Check that deletion was called + // Check that deletion was not called verify(deleteAllPublicDokumentePort, times(0)).deleteAllPublicDokumente(any()); verify(deleteAllPrivateDokumentePort, times(0)).deleteAllPrivateDokumente(any()); - - // Verify norm publishing actions - verify(publishPublicNormPort, times(0)) - .publishPublicNorm(new PublishPublicNormPort.Command(norm)); - verify(publishPrivateNormPort, times(0)) - .publishPrivateNorm(new PublishPrivateNormPort.Command(norm)); - verify(updateOrSaveNormPort, times(0)).updateOrSave(new UpdateOrSaveNormPort.Command(norm)); - verify(publishChangelogsPort, times(0)).publishChangelogs(any()); } @Test From fa437e3ecf5955a0c641f7fab594f70f7e82f35d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20Lauk=C3=B6tter?= Date: Mon, 17 Feb 2025 15:30:29 +0100 Subject: [PATCH 4/7] Adjust changelog filename RISDEV-0000 --- .../norms/adapter/output/s3/Changelog.java | 7 +-- .../adapter/output/s3/ChangelogTest.java | 3 +- .../s3/BucketServiceIntegrationTest.java | 49 +++++-------------- 3 files changed, 18 insertions(+), 41 deletions(-) diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/Changelog.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/Changelog.java index 594d17b28..fa8a6bc86 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/Changelog.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/Changelog.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.nio.file.Paths; -import java.time.LocalDate; +import java.time.Instant; import java.util.*; import lombok.Getter; @@ -15,7 +15,7 @@ public class Changelog { public static final String FOLDER = "changelogs"; - public static final String FILE_NAME_FORMAT = "changelog-%s.json"; + public static final String FILE_NAME_FORMAT = "%s-norms.json"; public static final String CHANGED = "changed"; public static final String DELETED = "deleted"; @@ -27,7 +27,8 @@ public class Changelog { private final String fileName; public Changelog() { - this.fileName = Paths.get(FOLDER, FILE_NAME_FORMAT.formatted(LocalDate.now())).toString(); + this.fileName = + Paths.get(FOLDER, FILE_NAME_FORMAT.formatted(Instant.now().toString())).toString(); } /** diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/s3/ChangelogTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/s3/ChangelogTest.java index be246657a..4b34cee82 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/s3/ChangelogTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/output/s3/ChangelogTest.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import java.io.IOException; -import java.time.LocalDate; import org.junit.jupiter.api.Test; class ChangelogTest { @@ -14,7 +13,7 @@ void createsChangelogWithGivenDate() { final Changelog changelog = new Changelog(); assertThat(changelog.getFileName()).isNotEmpty(); assertThat(changelog.getFileName()) - .isEqualTo("changelogs/changelog-%s.json".formatted(LocalDate.now().toString())); + .matches("changelogs/\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d+Z-norms\\.json"); } @Test diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java index a433c7024..a4868e49b 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java @@ -18,10 +18,10 @@ import java.nio.file.Files; import java.nio.file.Path; import java.time.Instant; -import java.time.LocalDate; import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -237,49 +237,26 @@ void itDeletesAllNormsFromPrivateBucket() { assertChangelogContains(true, PRIVATE_BUCKET, CHANGED, norm3); } - @Test - void itAddsToExistingChangelog() { - // Given - final Norm norm = Fixtures.loadNormFromDisk("SimpleNorm.xml"); - final PublishPublicNormPort.Command command = new PublishPublicNormPort.Command(norm); - final Norm anotherNorm = Fixtures.loadNormFromDisk("NormToBeReleased.xml"); - final PublishPublicNormPort.Command commandAnotherNorm = new PublishPublicNormPort.Command( - anotherNorm - ); - final PublishChangelogsPort.Command commandPublishChangelogs = - new PublishChangelogsPort.Command(false); - // When - bucketService.publishPublicNorm(command); - bucketService.publishChangelogs(commandPublishChangelogs); - bucketService.publishPublicNorm(commandAnotherNorm); - bucketService.publishChangelogs(commandPublishChangelogs); - - // Then - assertChangelogContains(true, PUBLIC_BUCKET, CHANGED, norm); - assertChangelogContains(true, PUBLIC_BUCKET, CHANGED, anotherNorm); - } - private void assertChangelogContains( final boolean contains, final String location, final String operation, final Norm norm ) { - Path changeLogPath; - if (Objects.equals(location, PUBLIC_BUCKET)) { - changeLogPath = - getPublicPath() - .resolve(Changelog.FOLDER) - .resolve("changelog-%s.json".formatted(LocalDate.now().toString())); - } else { - changeLogPath = - getPrivatePath() - .resolve(Changelog.FOLDER) - .resolve("changelog-%s.json".formatted(LocalDate.now().toString())); - } - final Map> changelogEntries; + try { + Path changeLogPath; + if (Objects.equals(location, PUBLIC_BUCKET)) { + try (Stream files = Files.list(getPublicPath().resolve(Changelog.FOLDER))) { + changeLogPath = files.findFirst().orElseThrow(); + } + } else { + try (Stream files = Files.list(getPrivatePath().resolve(Changelog.FOLDER))) { + changeLogPath = files.findFirst().orElseThrow(); + } + } + final String json = Files.readString(changeLogPath); changelogEntries = OBJECT_MAPPER.readValue(json, new TypeReference<>() {}); } catch (Exception e) { From accb47c5b16b387dba7102a333590b131a10081b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20Lauk=C3=B6tter?= Date: Mon, 17 Feb 2025 16:27:01 +0100 Subject: [PATCH 5/7] Update changelog during delete all RISDEV-0000 --- .../ris/norms/adapter/output/s3/BucketService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java index cb51d2f05..b269c02a4 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java @@ -108,6 +108,7 @@ public void deleteAllPublicDokumente(DeleteAllPublicDokumentePort.Command comman deleteAllDokumenteLastModifiedBefore( publicS3Client, publicBucketName, + publicChangelog, command.lastChangeBefore() ); } @@ -117,6 +118,7 @@ public void deleteAllPrivateDokumente(DeleteAllPrivateDokumentePort.Command comm deleteAllDokumenteLastModifiedBefore( privateS3Client, privateBucketName, + privateChangelog, command.lastChangeBefore() ); } @@ -259,6 +261,7 @@ private void deleteFromBucket( private void deleteAllDokumenteLastModifiedBefore( final S3Client s3Client, final String bucketName, + Changelog changelog, Instant lastChangeBefore ) { try { @@ -287,6 +290,9 @@ private void deleteAllDokumenteLastModifiedBefore( .build(); s3Client.deleteObjects(deleteRequest); objectsDeleted += objectsToDelete.size(); + objectsToDelete.forEach(objectIdentifier -> + changelog.addContent(Changelog.DELETED, objectIdentifier.key()) + ); } listRequest = From ce516bd8f83ce728a0502906abc656601d9ae051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20Lauk=C3=B6tter?= Date: Mon, 17 Feb 2025 16:31:11 +0100 Subject: [PATCH 6/7] Always publish full changelog RISDEV-0000 --- .../ris/norms/adapter/output/s3/BucketService.java | 5 ++++- .../ris/norms/application/service/PublishService.java | 4 ++-- .../output/s3/BucketServiceIntegrationTest.java | 10 +++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java index b269c02a4..251bd3ae6 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/s3/BucketService.java @@ -278,7 +278,10 @@ private void deleteAllDokumenteLastModifiedBefore( for (S3Object s3Object : listResponse.contents()) { final String key = s3Object.key(); - if (s3Object.lastModified().isBefore(lastChangeBefore)) { + if ( + !key.startsWith(Changelog.FOLDER + "/") && + s3Object.lastModified().isBefore(lastChangeBefore) + ) { objectsToDelete.add(ObjectIdentifier.builder().key(key).build()); } } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java index 4e2cee999..79d5d181b 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/PublishService.java @@ -116,7 +116,7 @@ public void processQueuedFilesForPublish() { } }); - publishChangelogsPort.publishChangelogs(new PublishChangelogsPort.Command(true)); + publishChangelogsPort.publishChangelogs(new PublishChangelogsPort.Command(false)); log.info("Publish job successfully completed."); } @@ -177,7 +177,7 @@ private void rollbackPrivatePublish(Norm norm) { try { deletePrivateNormPort.deletePrivateNorm(new DeletePrivateNormPort.Command(norm)); log.info( - "Deleted privated norm on rollback strategy: {}", + "Deleted private norm on rollback strategy: {}", norm.getManifestationEli().toString() ); } catch (StorageException e) { diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java index a4868e49b..896b59afd 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java @@ -18,6 +18,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.time.Instant; +import java.util.Comparator; import java.util.Map; import java.util.Objects; import java.util.Set; @@ -214,6 +215,7 @@ void itDeletesAllNormsFromPrivateBucket() { bucketService.publishPrivateNorm(new PublishPrivateNormPort.Command(norm1)); bucketService.publishPrivateNorm(new PublishPrivateNormPort.Command(norm2)); + bucketService.publishChangelogs(new PublishChangelogsPort.Command(false)); Instant afterTwoPublishes = Instant.now(); bucketService.publishPrivateNorm(new PublishPrivateNormPort.Command(norm3)); @@ -221,9 +223,7 @@ void itDeletesAllNormsFromPrivateBucket() { bucketService.deleteAllPrivateDokumente( new DeleteAllPrivateDokumentePort.Command(afterTwoPublishes) ); - final PublishChangelogsPort.Command commandPublishChangelogs = - new PublishChangelogsPort.Command(false); - bucketService.publishChangelogs(commandPublishChangelogs); + bucketService.publishChangelogs(new PublishChangelogsPort.Command(false)); // Then final Path filePath1 = getPrivatePath(norm1.getRegelungstext1()); @@ -249,11 +249,11 @@ private void assertChangelogContains( Path changeLogPath; if (Objects.equals(location, PUBLIC_BUCKET)) { try (Stream files = Files.list(getPublicPath().resolve(Changelog.FOLDER))) { - changeLogPath = files.findFirst().orElseThrow(); + changeLogPath = files.max(Comparator.naturalOrder()).orElseThrow(); } } else { try (Stream files = Files.list(getPrivatePath().resolve(Changelog.FOLDER))) { - changeLogPath = files.findFirst().orElseThrow(); + changeLogPath = files.max(Comparator.naturalOrder()).orElseThrow(); } } From 791f2e9728111db395e4fc67d914be28f58f0c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20Lauk=C3=B6tter?= Date: Tue, 18 Feb 2025 08:36:50 +0100 Subject: [PATCH 7/7] Reduce flakiness of integration test The test failed once as the Instant.now() created for the afterTwoPublishes was the same as the one used for the lastModifiedAt date of norm3 as this just happened within the same instant (probably due to some precision of the Instant). By doing the first publishing of the changelog in between enough time should have passed that this is no longer a happening. RISDEV-0000 --- .../adapter/output/s3/BucketServiceIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java index 896b59afd..2db244a89 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/output/s3/BucketServiceIntegrationTest.java @@ -215,8 +215,8 @@ void itDeletesAllNormsFromPrivateBucket() { bucketService.publishPrivateNorm(new PublishPrivateNormPort.Command(norm1)); bucketService.publishPrivateNorm(new PublishPrivateNormPort.Command(norm2)); - bucketService.publishChangelogs(new PublishChangelogsPort.Command(false)); Instant afterTwoPublishes = Instant.now(); + bucketService.publishChangelogs(new PublishChangelogsPort.Command(false)); bucketService.publishPrivateNorm(new PublishPrivateNormPort.Command(norm3)); // When