use of com.yahoo.config.FileReference in project vespa by vespa-engine.
the class FileReceiver method receiveFileEof.
@SuppressWarnings({ "UnusedDeclaration" })
public final void receiveFileEof(Request req) {
log.log(LogLevel.DEBUG, () -> "Received method call '" + req.methodName() + "' with parameters : " + req.parameters());
FileReference reference = new FileReference(req.parameters().get(0).asString());
int sessionId = req.parameters().get(1).asInt32();
long xxhash = req.parameters().get(2).asInt64();
Session session = getSession(sessionId);
int retval = verifySession(session, sessionId, reference);
File file = session.close(xxhash);
downloader.completedDownloading(reference, file);
synchronized (sessions) {
sessions.remove(sessionId);
}
req.returnValues().add(new Int32Value(retval));
}
use of com.yahoo.config.FileReference in project vespa by vespa-engine.
the class FileDownloaderTest method receiveFile.
@Test
public void receiveFile() throws IOException {
FileReference foo = new FileReference("foo");
String filename = "foo.jar";
receiveFile(foo, filename, FileReferenceData.Type.file, "content");
File downloadedFile = new File(fileReferenceFullPath(downloadDir, foo), filename);
assertEquals("content", IOUtils.readFile(downloadedFile));
}
use of com.yahoo.config.FileReference in project vespa by vespa-engine.
the class FileDownloaderTest method getFileWhenConnectionError.
@Test
public void getFileWhenConnectionError() throws IOException {
fileDownloader = new FileDownloader(connection, downloadDir, tempDir, Duration.ofSeconds(3), Duration.ofMillis(100));
File downloadDir = fileDownloader.downloadDirectory();
int timesToFail = 2;
MockConnection.ConnectionErrorResponseHandler responseHandler = new MockConnection.ConnectionErrorResponseHandler(timesToFail);
connection.setResponseHandler(responseHandler);
FileReference fileReference = new FileReference("fileReference");
File fileReferenceFullPath = fileReferenceFullPath(downloadDir, fileReference);
assertFalse(fileReferenceFullPath.getAbsolutePath(), fileDownloader.getFile(fileReference).isPresent());
// Getting file failed, verify download status and since there was an error is not downloading ATM
assertDownloadStatus(fileDownloader, fileReference, 0.0);
assertFalse(fileDownloader.fileReferenceDownloader().isDownloading(fileReference));
// 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);
assertTrue(downloadedFile.isPresent());
File downloadedFileFullPath = new File(fileReferenceFullPath, filename);
assertEquals(downloadedFileFullPath.getAbsolutePath(), downloadedFile.get().getAbsolutePath());
assertEquals("some other content", IOUtils.readFile(downloadedFile.get()));
// Verify download status when downloaded
assertDownloadStatus(fileDownloader, fileReference, 1.0);
assertEquals(timesToFail, responseHandler.failedTimes);
}
use of com.yahoo.config.FileReference in project vespa by vespa-engine.
the class FileDownloaderTest method setFilesToDownload.
@Test
public void setFilesToDownload() throws IOException {
Duration timeout = Duration.ofMillis(200);
Duration sleepBetweenRetries = Duration.ofMillis(200);
File downloadDir = Files.createTempDirectory("filedistribution").toFile();
MockConnection connectionPool = new MockConnection();
connectionPool.setResponseHandler(new MockConnection.WaitResponseHandler(timeout.plus(Duration.ofMillis(1000))));
FileDownloader fileDownloader = new FileDownloader(connectionPool, downloadDir, tempDir, timeout, sleepBetweenRetries);
FileReference foo = new FileReference("foo");
FileReference bar = new FileReference("bar");
fileDownloader.queueForAsyncDownload(new FileReferenceDownload(foo));
fileDownloader.queueForAsyncDownload(new FileReferenceDownload(bar));
// Verify download status
assertDownloadStatus(fileDownloader, foo, 0.0);
assertDownloadStatus(fileDownloader, bar, 0.0);
}
use of com.yahoo.config.FileReference in project vespa by vespa-engine.
the class FileReferenceDataTest method testDataBlob.
@Test
public void testDataBlob() {
String content = "blob";
FileReferenceData fileReferenceData = new FileReferenceDataBlob(new FileReference("ref"), "foo", FileReferenceData.Type.compressed, Utf8.toBytes(content));
ByteBuffer byteBuffer = ByteBuffer.allocate(100);
assertEquals(4, fileReferenceData.nextContent(byteBuffer));
assertEquals(content, Utf8.toString(Arrays.copyOfRange(byteBuffer.array(), 0, 4)));
// nextContent() will always return everything for FileReferenceDataBlob, so nothing more should be read
assertEquals(-1, fileReferenceData.nextContent(byteBuffer));
}
Aggregations