Search in sources :

Example 16 with Path

use of com.yahoo.path.Path in project vespa by vespa-engine.

the class ApplicationFileTest method testApplicationFileListFiles.

@Test
public void testApplicationFileListFiles() throws Exception {
    ApplicationFile file = getApplicationFile(Path.createRoot());
    assertTrue(file.exists());
    assertTrue(file.isDirectory());
    List<ApplicationFile> list = file.listFiles();
    assertThat(list.size(), is(6));
    assertTrue(listContains(list, "vespa-services.xml"));
    assertTrue(listContains(list, "vespa-hosts.xml"));
    assertTrue(listContains(list, "components/"));
    assertTrue(listContains(list, "searchdefinitions/"));
    assertTrue(listContains(list, "templates/"));
    assertTrue(listContains(list, "files/"));
    list = getApplicationFile(Path.fromString("templates")).listFiles(false);
    assertTrue(listContains(list, "templates/basic/"));
    assertTrue(listContains(list, "templates/simple_html/"));
    assertTrue(listContains(list, "templates/text/"));
    list = getApplicationFile(Path.fromString("components")).listFiles(false);
    assertTrue(listContains(list, "components/defs-only.jar"));
    assertTrue(listContains(list, "components/file.txt"));
    list = getApplicationFile(Path.fromString("components")).listFiles(true);
    assertTrue(listContains(list, "components/defs-only.jar"));
    assertTrue(listContains(list, "components/file.txt"));
    list = getApplicationFile(Path.fromString("templates")).listFiles(true);
    assertThat(list.size(), is(14));
    assertTrue(listContains(list, "templates/basic/"));
    assertTrue(listContains(list, "templates/basic/error.templ"));
    assertTrue(listContains(list, "templates/basic/header.templ"));
    assertTrue(listContains(list, "templates/basic/hit.templ"));
    assertTrue(listContains(list, "templates/simple_html/"));
    assertTrue(listContains(list, "templates/simple_html/footer.templ"));
    assertTrue(listContains(list, "templates/simple_html/header.templ"));
    assertTrue(listContains(list, "templates/simple_html/hit.templ"));
    assertTrue(listContains(list, "templates/text/"));
    assertTrue(listContains(list, "templates/text/error.templ"));
    assertTrue(listContains(list, "templates/text/footer.templ"));
    assertTrue(listContains(list, "templates/text/header.templ"));
    assertTrue(listContains(list, "templates/text/hit.templ"));
    assertTrue(listContains(list, "templates/text/nohits.templ"));
    list = getApplicationFile(Path.createRoot()).listFiles(true);
    assertTrue(listContains(list, "components/"));
    assertTrue(listContains(list, "files/"));
    assertTrue(listContains(list, "searchdefinitions/"));
    assertTrue(listContains(list, "templates/"));
    assertTrue(listContains(list, "vespa-hosts.xml"));
    assertTrue(listContains(list, "vespa-services.xml"));
    assertTrue(listContains(list, "templates/text/"));
    assertTrue(listContains(list, "templates/text/error.templ"));
    assertTrue(listContains(list, "templates/text/footer.templ"));
    assertTrue(listContains(list, "templates/text/header.templ"));
    assertTrue(listContains(list, "templates/text/hit.templ"));
    assertTrue(listContains(list, "templates/text/nohits.templ"));
    list = getApplicationFile(Path.createRoot()).listFiles(new ApplicationFile.PathFilter() {

        @Override
        public boolean accept(Path path) {
            return path.getName().endsWith(".xml");
        }
    });
    assertThat(list.size(), is(2));
    assertFalse(listContains(list, "components/"));
    assertFalse(listContains(list, "files/"));
    assertFalse(listContains(list, "searchdefinitions/"));
    assertFalse(listContains(list, "templates/"));
    assertTrue(listContains(list, "vespa-hosts.xml"));
    assertTrue(listContains(list, "vespa-services.xml"));
}
Also used : Path(com.yahoo.path.Path) ApplicationFile(com.yahoo.config.application.api.ApplicationFile) Test(org.junit.Test)

Example 17 with Path

use of com.yahoo.path.Path in project vespa by vespa-engine.

the class RemoteSessionRepoTest method testSessionStateChange.

@Test
public void testSessionStateChange() throws Exception {
    long sessionId = 3L;
    createSession(sessionId, true);
    assertSessionStatus(sessionId, Session.Status.NEW);
    assertStatusChange(sessionId, Session.Status.PREPARE);
    assertStatusChange(sessionId, Session.Status.ACTIVATE);
    Path session = Tenants.getSessionsPath(tenantName).append("" + sessionId);
    curator.delete(session);
    assertSessionRemoved(sessionId);
    assertNull(remoteSessionRepo.getSession(sessionId));
}
Also used : Path(com.yahoo.path.Path) Test(org.junit.Test)

Example 18 with Path

use of com.yahoo.path.Path in project vespa by vespa-engine.

the class ApplicationFileTest method testApplicationFileEquals.

@Test
public void testApplicationFileEquals() throws Exception {
    Path p1 = Path.fromString("foo/bar/baz");
    Path p2 = Path.fromString("foo/bar");
    ApplicationFile f1 = getApplicationFile(p1);
    ApplicationFile f2 = getApplicationFile(p2);
    assertTrue(f1.equals(f1));
    assertFalse(f1.equals(f2));
    assertFalse(f2.equals(f1));
    assertTrue(f2.equals(f2));
}
Also used : Path(com.yahoo.path.Path) ApplicationFile(com.yahoo.config.application.api.ApplicationFile) Test(org.junit.Test)

Example 19 with Path

use of com.yahoo.path.Path in project vespa by vespa-engine.

the class RankingExpressionWithTensorFlowTestCase method assertLargeConstant.

/**
 * Verifies that the constant with the given name exists, and - only if an expected size is given -
 * that the content of the constant is available and has the expected size.
 */
private void assertLargeConstant(String name, RankProfileSearchFixture search, Optional<Long> expectedSize) {
    try {
        Path constantApplicationPackagePath = Path.fromString("models.generated/mnist_softmax/saved/constants").append(name + ".tbf");
        RankingConstant rankingConstant = search.search().getRankingConstants().get(name);
        assertEquals(name, rankingConstant.getName());
        assertTrue(rankingConstant.getFileName().endsWith(constantApplicationPackagePath.toString()));
        if (expectedSize.isPresent()) {
            Path constantPath = applicationDir.append(constantApplicationPackagePath);
            assertTrue("Constant file '" + constantPath + "' has been written", constantPath.toFile().exists());
            Tensor deserializedConstant = TypedBinaryFormat.decode(Optional.empty(), GrowableByteBuffer.wrap(IOUtils.readFileBytes(constantPath.toFile())));
            assertEquals(expectedSize.get().longValue(), deserializedConstant.size());
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : Path(com.yahoo.path.Path) Tensor(com.yahoo.tensor.Tensor) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) RankingConstant(com.yahoo.searchdefinition.RankingConstant)

Example 20 with Path

use of com.yahoo.path.Path in project vespa by vespa-engine.

the class RankingExpressionWithTensorFlowTestCase method testImportingFromStoredExpressions.

@Test
public void testImportingFromStoredExpressions() throws IOException {
    RankProfileSearchFixture search = fixtureWith("tensor(d0[2],d1[784])(0.0)", "tensorflow('mnist_softmax/saved')");
    search.assertFirstPhaseExpression(vespaExpression, "my_profile");
    assertLargeConstant("mnist_softmax_saved_layer_Variable_1_read", search, Optional.of(10L));
    assertLargeConstant("mnist_softmax_saved_layer_Variable_read", search, Optional.of(7840L));
    // At this point the expression is stored - copy application to another location which do not have a models dir
    Path storedApplicationDirectory = applicationDir.getParentPath().append("copy");
    try {
        storedApplicationDirectory.toFile().mkdirs();
        IOUtils.copyDirectory(applicationDir.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile(), storedApplicationDirectory.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile());
        StoringApplicationPackage storedApplication = new StoringApplicationPackage(storedApplicationDirectory);
        RankProfileSearchFixture searchFromStored = fixtureWith("tensor(d0[2],d1[784])(0.0)", "tensorflow('mnist_softmax/saved')", null, null, "Placeholder", storedApplication);
        searchFromStored.assertFirstPhaseExpression(vespaExpression, "my_profile");
        // Verify that the constants exists, but don't verify the content as we are not
        // simulating file distribution in this test
        assertLargeConstant("mnist_softmax_saved_layer_Variable_1_read", searchFromStored, Optional.empty());
        assertLargeConstant("mnist_softmax_saved_layer_Variable_read", searchFromStored, Optional.empty());
    } finally {
        IOUtils.recursiveDeleteDir(storedApplicationDirectory.toFile());
    }
}
Also used : Path(com.yahoo.path.Path) Test(org.junit.Test)

Aggregations

Path (com.yahoo.path.Path)32 Test (org.junit.Test)10 ApplicationFile (com.yahoo.config.application.api.ApplicationFile)4 ConfigCurator (com.yahoo.vespa.config.server.zookeeper.ConfigCurator)4 File (java.io.File)4 ApplicationPackage (com.yahoo.config.application.api.ApplicationPackage)3 Node (com.yahoo.vespa.curator.mock.MemoryFileSystem.Node)3 MockCurator (com.yahoo.vespa.curator.mock.MockCurator)3 KeeperException (org.apache.zookeeper.KeeperException)3 RankingConstant (com.yahoo.searchdefinition.RankingConstant)2 Curator (com.yahoo.vespa.curator.Curator)2 NullConfigModelRegistry (com.yahoo.config.model.NullConfigModelRegistry)1 FilesApplicationPackage (com.yahoo.config.model.application.provider.FilesApplicationPackage)1 ApplicationId (com.yahoo.config.provision.ApplicationId)1 TenantName (com.yahoo.config.provision.TenantName)1 NamedReader (com.yahoo.io.reader.NamedReader)1 RankProfile (com.yahoo.searchdefinition.RankProfile)1 Tensor (com.yahoo.tensor.Tensor)1 TensorType (com.yahoo.tensor.TensorType)1 NestedTransaction (com.yahoo.transaction.NestedTransaction)1