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"));
}
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));
}
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));
}
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);
}
}
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());
}
}
Aggregations