Search in sources :

Example 16 with FileReference

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));
}
Also used : Int32Value(com.yahoo.jrt.Int32Value) FileReference(com.yahoo.config.FileReference) File(java.io.File)

Example 17 with FileReference

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));
}
Also used : FileReference(com.yahoo.config.FileReference) File(java.io.File) Test(org.junit.Test)

Example 18 with FileReference

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);
}
Also used : FileReference(com.yahoo.config.FileReference) File(java.io.File) Test(org.junit.Test)

Example 19 with FileReference

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);
}
Also used : Duration(java.time.Duration) FileReference(com.yahoo.config.FileReference) File(java.io.File) Test(org.junit.Test)

Example 20 with FileReference

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));
}
Also used : FileReference(com.yahoo.config.FileReference) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

FileReference (com.yahoo.config.FileReference)37 Test (org.junit.Test)10 File (java.io.File)9 Int32Value (com.yahoo.jrt.Int32Value)4 IOException (java.io.IOException)3 Bundle (org.osgi.framework.Bundle)3 StringValue (com.yahoo.jrt.StringValue)2 CompressedFileReference (com.yahoo.vespa.filedistribution.CompressedFileReference)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ByteBuffer (java.nio.ByteBuffer)2 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 Optional (java.util.Optional)2 ComponentSpecification (com.yahoo.component.ComponentSpecification)1 ConfigBuilder (com.yahoo.config.ConfigBuilder)1 ComponentInfo (com.yahoo.config.application.api.ComponentInfo)1 MockFileRegistry (com.yahoo.config.model.application.provider.MockFileRegistry)1 UserConfigRepo (com.yahoo.config.model.producer.UserConfigRepo)1 MockHosts (com.yahoo.config.model.test.MockHosts)1 BundleInstantiationSpecification (com.yahoo.container.bundle.BundleInstantiationSpecification)1 CloudSubscriberFactory (com.yahoo.container.di.CloudSubscriberFactory)1