Skip to content

Commit

Permalink
JAMES-2586 - Fixup InMemoryUploadRepository.deleteByUploadDateBefore
Browse files Browse the repository at this point in the history
- Fix java.util.ConcurrentModificationException
- Fix test InMemoryUploadRepositoryTest
  • Loading branch information
vttranlina authored and Arsnael committed Oct 28, 2024
1 parent fec4a91 commit 61b6018
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -113,7 +114,7 @@ public Publisher<UploadMetaData> listUploads(Username user) {
@Override
public Publisher<Void> 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()))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 61b6018

Please sign in to comment.