diff options
author | Harald Musum <musum@yahooinc.com> | 2022-07-06 10:33:57 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2022-07-06 10:33:57 +0200 |
commit | f7d93a0f3bade34a4a02cdbd8d3942422ed65b2f (patch) | |
tree | a82b30d72ca49a93bf81facd7943dab9ebe3ed8e /filedistribution/src/test | |
parent | 8dae227258dde84db5116922fbc616dc1d70d3a7 (diff) |
Wire in use of compression types and flags for file distribution
VESPA_FILE_DISTRIBUTION_ACCEPTED_COMPRESSION_TYPES is not set anywhere
yet, will be set through host-admin
Diffstat (limited to 'filedistribution/src/test')
-rw-r--r-- | filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java | 29 |
1 files changed, 24 insertions, 5 deletions
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 f5cd1760e89..629ea5915df 100644 --- a/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java +++ b/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java @@ -17,7 +17,6 @@ import net.jpountz.xxhash.XXHashFactory; import org.junit.After; import org.junit.Before; import org.junit.Test; - import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; @@ -26,6 +25,7 @@ import java.nio.file.Path; import java.time.Duration; import java.util.Arrays; import java.util.Optional; +import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -41,6 +41,7 @@ import static org.junit.Assert.fail; public class FileDownloaderTest { private static final Duration sleepBetweenRetries = Duration.ofMillis(10); + private static final Set<FileReferenceData.CompressionType> acceptedCompressionTypes = Set.of(gzip); private MockConnection connection; private FileDownloader fileDownloader; @@ -53,7 +54,7 @@ public class FileDownloaderTest { downloadDir = Files.createTempDirectory("filedistribution").toFile(); connection = new MockConnection(); supervisor = new Supervisor(new Transport()).setDropEmptyBuffers(true); - fileDownloader = new FileDownloader(connection, supervisor, downloadDir, Duration.ofSeconds(1), sleepBetweenRetries); + fileDownloader = createDownloader(connection, Duration.ofSeconds(1)); } catch (IOException e) { e.printStackTrace(); fail(e.getMessage()); @@ -167,7 +168,7 @@ public class FileDownloaderTest { @Test public void getFileWhenConnectionError() throws IOException { - fileDownloader = new FileDownloader(connection, supervisor, downloadDir, Duration.ofSeconds(2), sleepBetweenRetries); + fileDownloader = createDownloader(connection, Duration.ofSeconds(2)); File downloadDir = fileDownloader.downloadDirectory(); int timesToFail = 2; @@ -201,7 +202,7 @@ public class FileDownloaderTest { public void getFileWhenDownloadInProgress() throws IOException, ExecutionException, InterruptedException { ExecutorService executor = Executors.newFixedThreadPool(2); String filename = "abc.jar"; - fileDownloader = new FileDownloader(connection, supervisor, downloadDir, Duration.ofSeconds(3), sleepBetweenRetries); + fileDownloader = createDownloader(connection, Duration.ofSeconds(3)); File downloadDir = fileDownloader.downloadDirectory(); // Delay response so that we can make a second request while downloading the file from the first request @@ -241,7 +242,7 @@ public class FileDownloaderTest { Duration timeout = Duration.ofMillis(200); MockConnection connectionPool = new MockConnection(); connectionPool.setResponseHandler(new MockConnection.WaitResponseHandler(timeout.plus(Duration.ofMillis(1000)))); - FileDownloader fileDownloader = new FileDownloader(connectionPool, supervisor, downloadDir, timeout, sleepBetweenRetries); + FileDownloader fileDownloader = createDownloader(connectionPool, timeout); FileReference xyzzy = new FileReference("xyzzy"); // Should download since we do not have the file on disk fileDownloader.downloadIfNeeded(new FileReferenceDownload(xyzzy, "test")); @@ -264,6 +265,16 @@ public class FileDownloaderTest { assertEquals("content", IOUtils.readFile(downloadedFile)); } + @Test + public void testCompressionTypes() { + try { + createDownloader(connection, Duration.ofSeconds(1), Set.of()); + fail("expected to fail when set is empty"); + } catch (IllegalArgumentException e) { + // ignore + } + } + private void writeFileReference(File dir, String fileReferenceString, String fileName) throws IOException { File fileReferenceDir = new File(dir, fileReferenceString); fileReferenceDir.mkdir(); @@ -302,6 +313,14 @@ public class FileDownloaderTest { return fileDownloader.getFile(new FileReferenceDownload(fileReference, "test")); } + private FileDownloader createDownloader(MockConnection connection, Duration timeout) { + return createDownloader(connection, timeout, acceptedCompressionTypes); + } + + private FileDownloader createDownloader(MockConnection connection, Duration timeout, Set<FileReferenceData.CompressionType> acceptedCompressionTypes) { + return new FileDownloader(connection, supervisor, downloadDir, timeout, sleepBetweenRetries, acceptedCompressionTypes); + } + private static class MockConnection implements ConnectionPool, com.yahoo.vespa.config.Connection { private ResponseHandler responseHandler; |