From 7c3ad1972cc796e2d976429bc99c7d6b6cf1a8ec Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Fri, 26 Nov 2021 12:41:38 +0100 Subject: Always add client string when getting files --- .../vespa/filedistribution/FileDownloader.java | 4 ++-- .../filedistribution/FileReferenceDownload.java | 4 ++++ .../vespa/filedistribution/FileDownloaderTest.java | 24 +++++++++++++--------- 3 files changed, 20 insertions(+), 12 deletions(-) (limited to 'filedistribution/src') 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 getFile(FileReference fileReference) { - return getFile(new FileReferenceDownload(fileReference)); + public Optional getFile(FileReference fileReference, String client) { + return getFile(new FileReferenceDownload(fileReference, client)); } public Optional 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 pathToFile = fileDownloader.getFile(fileReference); + Optional 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 downloadedFile = fileDownloader.getFile(fileReference); + Optional 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 downloadedFile = fileDownloader.getFile(fileReference); + Optional 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 downloadedFile = fileDownloader.getFile(fileReference); + Optional 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 getFile(FileReference fileReference) { + return fileDownloader.getFile(fileReference, "test"); + } + private static class MockConnection implements ConnectionPool, com.yahoo.vespa.config.Connection { private ResponseHandler responseHandler; -- cgit v1.2.3