From 61b6018f2cd1eae40e3396388e05bb49f98394bf Mon Sep 17 00:00:00 2001 From: TungTV Date: Thu, 24 Oct 2024 19:10:49 +0700 Subject: [PATCH] JAMES-2586 - Fixup InMemoryUploadRepository.deleteByUploadDateBefore - Fix java.util.ConcurrentModificationException - Fix test InMemoryUploadRepositoryTest --- .../james/jmap/memory/upload/InMemoryUploadRepository.java | 3 ++- .../james/jmap/memory/upload/InMemoryUploadRepositoryTest.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/data/data-jmap/src/main/java/org/apache/james/jmap/memory/upload/InMemoryUploadRepository.java b/server/data/data-jmap/src/main/java/org/apache/james/jmap/memory/upload/InMemoryUploadRepository.java index c3b98a95a3d..9823214f98b 100644 --- a/server/data/data-jmap/src/main/java/org/apache/james/jmap/memory/upload/InMemoryUploadRepository.java +++ b/server/data/data-jmap/src/main/java/org/apache/james/jmap/memory/upload/InMemoryUploadRepository.java @@ -25,6 +25,7 @@ import java.time.Duration; import java.time.Instant; import java.util.HashMap; +import java.util.List; import java.util.Map; import jakarta.inject.Inject; @@ -113,7 +114,7 @@ public Publisher listUploads(Username user) { @Override public Publisher deleteByUploadDateBefore(Duration expireDuration) { Instant expirationTime = clock.instant().minus(expireDuration); - return Flux.fromIterable(uploadStore.values()) + return Flux.fromIterable(List.copyOf(uploadStore.values())) .filter(pair -> pair.right.uploadDate().isBefore(expirationTime)) .flatMap(pair -> Mono.from(blobStore.delete(bucketName, pair.right.blobId())) .then(Mono.fromRunnable(() -> uploadStore.remove(pair.right.uploadId())))) diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/upload/InMemoryUploadRepositoryTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/upload/InMemoryUploadRepositoryTest.java index 500d1ef823c..d1f37e01ce5 100644 --- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/upload/InMemoryUploadRepositoryTest.java +++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/memory/upload/InMemoryUploadRepositoryTest.java @@ -39,8 +39,8 @@ public class InMemoryUploadRepositoryTest implements UploadRepositoryContract { @BeforeEach void setUp() { BlobStore blobStore = new DeDuplicationBlobStore(new MemoryBlobStoreDAO(), BucketName.DEFAULT, new PlainBlobId.Factory()); - testee = new InMemoryUploadRepository(blobStore, Clock.systemUTC()); clock = new UpdatableTickingClock(Clock.systemUTC().instant()); + testee = new InMemoryUploadRepository(blobStore, clock); } @Override