From 5d363496bd93309b3f125f9a25eb20aaba38fd3e Mon Sep 17 00:00:00 2001 From: akwizgran Date: Wed, 8 Jun 2022 12:03:11 +0100 Subject: [PATCH] Download files in the order the mailbox returns them. --- .../mailbox/ContactMailboxDownloadWorker.java | 12 ++---------- .../mailbox/ContactMailboxDownloadWorkerTest.java | 7 +++---- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/bramble-core/src/main/java/org/briarproject/bramble/mailbox/ContactMailboxDownloadWorker.java b/bramble-core/src/main/java/org/briarproject/bramble/mailbox/ContactMailboxDownloadWorker.java index 818403215..971d6e7cd 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/mailbox/ContactMailboxDownloadWorker.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/mailbox/ContactMailboxDownloadWorker.java @@ -11,7 +11,6 @@ import org.briarproject.bramble.mailbox.TorReachabilityMonitor.TorReachabilityOb import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue; @@ -21,7 +20,6 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.GuardedBy; import javax.annotation.concurrent.ThreadSafe; -import static java.util.Collections.sort; import static java.util.logging.Level.INFO; import static java.util.logging.Logger.getLogger; import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull; @@ -147,14 +145,8 @@ class ContactMailboxDownloadWorker implements MailboxWorker, LOG.info("Listing inbox"); List files = mailboxApi.getFiles(mailboxProperties, requireNonNull(mailboxProperties.getInboxId())); - if (files.isEmpty()) { - onDownloadCycleFinished(); - } else { - files = new ArrayList<>(files); - //noinspection UseCompareMethod,Java8ListSort - sort(files, (a, b) -> Long.valueOf(a.time).compareTo(b.time)); - downloadNextFile(new LinkedList<>(files)); - } + if (files.isEmpty()) onDownloadCycleFinished(); + else downloadNextFile(new LinkedList<>(files)); } private void onDownloadCycleFinished() { diff --git a/bramble-core/src/test/java/org/briarproject/bramble/mailbox/ContactMailboxDownloadWorkerTest.java b/bramble-core/src/test/java/org/briarproject/bramble/mailbox/ContactMailboxDownloadWorkerTest.java index d2d08ed77..cd6b4f210 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/mailbox/ContactMailboxDownloadWorkerTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/mailbox/ContactMailboxDownloadWorkerTest.java @@ -44,7 +44,7 @@ public class ContactMailboxDownloadWorkerTest extends BrambleMockTestCase { new MailboxFile(new MailboxFileId(getRandomId()), now - 1); private final MailboxFile file2 = new MailboxFile(new MailboxFileId(getRandomId()), now); - private final List filesInWrongOrder = asList(file2, file1); + private final List files = asList(file1, file2); private File testDir, tempFile; private ContactMailboxDownloadWorker worker; @@ -104,13 +104,12 @@ public class ContactMailboxDownloadWorkerTest extends BrambleMockTestCase { worker.onConnectivityCheckSucceeded(); // When the list-inbox tasks runs and finds some files to download, - // it should sort them in timestamp order and start a download task - // for the first file + // it should start a download task for the first file AtomicReference downloadTask = new AtomicReference<>(null); context.checking(new Expectations() {{ oneOf(mailboxApi).getFiles(mailboxProperties, requireNonNull(mailboxProperties.getInboxId())); - will(returnValue(filesInWrongOrder)); + will(returnValue(files)); oneOf(mailboxApiCaller).retryWithBackoff(with(any(ApiCall.class))); will(new CaptureArgumentAction<>(downloadTask, ApiCall.class, 0)); }});