aboutsummaryrefslogtreecommitdiffstats
path: root/filedistribution
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2021-11-26 12:41:38 +0100
committerHarald Musum <musum@yahooinc.com>2021-11-26 12:41:38 +0100
commit7c3ad1972cc796e2d976429bc99c7d6b6cf1a8ec (patch)
tree9b03f5759ab6bb0889ac40942e6a968a712d63a5 /filedistribution
parentc1f3078567a9553bfb9ba98449937cc8850ccc35 (diff)
Always add client string when getting files
Diffstat (limited to 'filedistribution')
-rw-r--r--filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java4
-rw-r--r--filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownload.java4
-rw-r--r--filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java24
3 files changed, 20 insertions, 12 deletions
diff --git a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java
index 3674cba0d97..b2efd35e41e 100644
--- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java
+++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java
@@ -69,8 +69,8 @@ public class FileDownloader implements AutoCloseable {
downloadDirectory);
}
- public Optional<File> getFile(FileReference fileReference) {
- return getFile(new FileReferenceDownload(fileReference));
+ public Optional<File> getFile(FileReference fileReference, String client) {
+ return getFile(new FileReferenceDownload(fileReference, client));
}
public Optional<File> getFile(FileReferenceDownload fileReferenceDownload) {
diff --git a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownload.java b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownload.java
index 21e35bf67af..796f6ad2ebf 100644
--- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownload.java
+++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownload.java
@@ -22,6 +22,10 @@ public class FileReferenceDownload {
this(fileReference, true, "unknown");
}
+ public FileReferenceDownload(FileReference fileReference, String client) {
+ this(fileReference, true, client);
+ }
+
public FileReferenceDownload(FileReference fileReference, boolean downloadFromOtherSourceIfNotFound, String client) {
Objects.requireNonNull(fileReference, "file reference cannot be null");
this.fileReference = fileReference;
diff --git a/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java b/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java
index 97b948ef5d4..460a1ee593a 100644
--- a/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java
+++ b/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java
@@ -79,7 +79,7 @@ public class FileDownloaderTest {
fileDownloader.downloads().completedDownloading(fileReference, fileReferenceFullPath);
// Check that we get correct path and content when asking for file reference
- Optional<File> pathToFile = fileDownloader.getFile(fileReference);
+ Optional<File> pathToFile = getFile(fileReference);
assertTrue(pathToFile.isPresent());
String downloadedFile = new File(fileReferenceFullPath, filename).getAbsolutePath();
assertEquals(new File(fileReferenceFullPath, filename).getAbsolutePath(), downloadedFile);
@@ -96,7 +96,7 @@ public class FileDownloaderTest {
FileReference fileReference = new FileReference("bar");
File fileReferenceFullPath = fileReferenceFullPath(downloadDir, fileReference);
- assertFalse(fileReferenceFullPath.getAbsolutePath(), fileDownloader.getFile(fileReference).isPresent());
+ assertFalse(fileReferenceFullPath.getAbsolutePath(), getFile(fileReference).isPresent());
// Verify download status when unable to download
assertDownloadStatus(fileReference, 0.0);
@@ -107,7 +107,7 @@ public class FileDownloaderTest {
FileReference fileReference = new FileReference("baz");
File fileReferenceFullPath = fileReferenceFullPath(downloadDir, fileReference);
- assertFalse(fileReferenceFullPath.getAbsolutePath(), fileDownloader.getFile(fileReference).isPresent());
+ assertFalse(fileReferenceFullPath.getAbsolutePath(), getFile(fileReference).isPresent());
// Verify download status
assertDownloadStatus(fileReference, 0.0);
@@ -115,7 +115,7 @@ public class FileDownloaderTest {
// Receives fileReference, should return and make it available to caller
String filename = "abc.jar";
receiveFile(fileReference, filename, FileReferenceData.Type.file, "some other content");
- Optional<File> downloadedFile = fileDownloader.getFile(fileReference);
+ Optional<File> downloadedFile = getFile(fileReference);
assertTrue(downloadedFile.isPresent());
File downloadedFileFullPath = new File(fileReferenceFullPath, filename);
@@ -132,7 +132,7 @@ public class FileDownloaderTest {
FileReference fileReference = new FileReference("fileReferenceToDirWithManyFiles");
File fileReferenceFullPath = fileReferenceFullPath(downloadDir, fileReference);
- assertFalse(fileReferenceFullPath.getAbsolutePath(), fileDownloader.getFile(fileReference).isPresent());
+ assertFalse(fileReferenceFullPath.getAbsolutePath(), getFile(fileReference).isPresent());
// Verify download status
assertDownloadStatus(fileReference, 0.0);
@@ -150,7 +150,7 @@ public class FileDownloaderTest {
File tarFile = CompressedFileReference.compress(tempPath.toFile(), Arrays.asList(fooFile, barFile), new File(tempPath.toFile(), filename));
byte[] tarredContent = IOUtils.readFileBytes(tarFile);
receiveFile(fileReference, filename, FileReferenceData.Type.compressed, tarredContent);
- Optional<File> downloadedFile = fileDownloader.getFile(fileReference);
+ Optional<File> downloadedFile = getFile(fileReference);
assertTrue(downloadedFile.isPresent());
File downloadedFoo = new File(fileReferenceFullPath, tempPath.relativize(fooFile.toPath()).toString());
@@ -174,7 +174,7 @@ public class FileDownloaderTest {
FileReference fileReference = new FileReference("fileReference");
File fileReferenceFullPath = fileReferenceFullPath(downloadDir, fileReference);
- assertFalse(fileReferenceFullPath.getAbsolutePath(), fileDownloader.getFile(fileReference).isPresent());
+ assertFalse(fileReferenceFullPath.getAbsolutePath(), getFile(fileReference).isPresent());
// Getting file failed, verify download status and since there was an error is not downloading ATM
assertDownloadStatus(fileReference, 0.0);
@@ -183,7 +183,7 @@ public class FileDownloaderTest {
// Receives fileReference, should return and make it available to caller
String filename = "abc.jar";
receiveFile(fileReference, filename, FileReferenceData.Type.file, "some other content");
- Optional<File> downloadedFile = fileDownloader.getFile(fileReference);
+ Optional<File> downloadedFile = getFile(fileReference);
assertTrue(downloadedFile.isPresent());
File downloadedFileFullPath = new File(fileReferenceFullPath, filename);
assertEquals(downloadedFileFullPath.getAbsolutePath(), downloadedFile.get().getAbsolutePath());
@@ -244,13 +244,13 @@ public class FileDownloaderTest {
// Should download since we do not have the file on disk
fileDownloader.downloadIfNeeded(new FileReferenceDownload(xyzzy));
assertTrue(fileDownloader.isDownloading(xyzzy));
- assertFalse(fileDownloader.getFile(xyzzy).isPresent());
+ assertFalse(getFile(xyzzy).isPresent());
// Receive files to simulate download
receiveFile(xyzzy, "xyzzy.jar", FileReferenceData.Type.file, "content");
// Should not download, since file has already been downloaded
fileDownloader.downloadIfNeeded(new FileReferenceDownload(xyzzy));
// and file should be available
- assertTrue(fileDownloader.getFile(xyzzy).isPresent());
+ assertTrue(getFile(xyzzy).isPresent());
}
@Test
@@ -296,6 +296,10 @@ public class FileDownloaderTest {
fileDownloader.downloads().completedDownloading(fileReference, file);
}
+ private Optional<File> getFile(FileReference fileReference) {
+ return fileDownloader.getFile(fileReference, "test");
+ }
+
private static class MockConnection implements ConnectionPool, com.yahoo.vespa.config.Connection {
private ResponseHandler responseHandler;